commit c1111e50193d871b67571c867aa300959d0faa96
parent 2a2aa50bf879fd5cdd41b143f92fd5b6a8594d76
Author: Amit Dutta <mail@amit.is-a.dev>
Date: Fri, 10 Jul 2026 22:04:39 +0530
Refactor: remade the tasks.json for Linux, added for pgrm files.
Diffstat:
5 files changed, 256 insertions(+), 0 deletions(-)
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
@@ -0,0 +1,62 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "Silent Auto-Pull",
+ "type": "shell",
+ "command": "git pull",
+ "runOptions": {
+ "runOn": "folderOpen"
+ },
+ "presentation": {
+ "reveal": "never",
+ "panel": "shared",
+ "showReuseMessage": false,
+ "clear": true
+ }
+ },
+ {
+ "label": "C/C++: build active file",
+ "type": "shell",
+ "command": "if [ \"${fileExtname}\" = \".cpp\" ]; then c=\"g++\"; else c=\"gcc\"; fi; exe=\"${fileDirname}/${fileBasenameNoExtension}\"; B=\"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\"; fnH() { if [ \"${2:-true}\" = \"true\" ]; then echo \"\"; fi; echo -e \"\\e[90m$B\\e[0m\"; echo -e \" \\e[36m$1\\e[0m\"; echo -e \"\\e[90m$B\\e[0m\"; echo \"\"; }; fnR() { printf \"%-15s\" \"$1\"; echo -e \"\\e[${3:-0}m$2\\e[0m\"; }; fnT() { if [ $1 -ge 1000 ]; then echo \"$((1 / 1000)) sec ($1 ms)\"; else echo \"$1 ms\"; fi; }; fnH \"BUILD\" false; echo \"Compiling ${fileBasename}...\"; echo \"\"; start_t=$(date +%s%3N); out=$($c -fdiagnostics-color=always -g \"${file}\" -o \"$exe\" 2>&1); bexit=$?; end_t=$(date +%s%3N); bms=$((end_t - start_t)); if [ -n \"$out\" ]; then echo -e \"$out\"; fi; w=$(echo \"$out\" | grep -ic \"warning:\"); e=$(echo \"$out\" | grep -ic \"error:\"); if [ $bexit -eq 0 ]; then bs=\"✓ Success\"; bc=\"32\"; else bs=\"✗ Failed\"; bc=\"31\"; fi; echo -e \"\\e[${bc}m${bs} in $(fnT $bms)\\e[0m\"; fnH \"BUILD REPORT\"; fnR \"File\" \"${fileBasename}\"; fnR \"Compiler\" \"$c\"; fnR \"Target\" \"x64\"; fnR \"Build\" \"$bs\" \"$bc\"; if [ $w -gt 0 ]; then wc=\"33\"; else wc=\"0\"; fi; fnR \"Warnings\" \"$w\" \"$wc\"; if [ $e -gt 0 ]; then ec=\"31\"; else ec=\"0\"; fi; fnR \"Errors\" \"$e\" \"$ec\"; if [ -f \"$exe\" ]; then sz=$(du -h \"$exe\" | cut -f1); fnR \"Size\" \"$sz\"; fi; fnR \"Build Time\" \"$(fnT $bms)\"; if [ $bexit -ne 0 ]; then exit 1; fi; exit 0",
+ "args": [],
+ "options": {
+ "cwd": "${fileDirname}",
+ "shell": {
+ "executable": "/bin/bash",
+ "args": ["-c"]
+ }
+ },
+ "problemMatcher": ["$gcc"],
+ "group": "build",
+ "detail": "Auto-selects gcc for .c and g++ for .cpp"
+ },
+ {
+ "label": "C/C++: build and run active file",
+ "type": "shell",
+ "command": "if [ \"${fileExtname}\" = \".cpp\" ]; then c=\"g++\"; else c=\"gcc\"; fi; exe=\"${fileDirname}/${fileBasenameNoExtension}\"; logDir=\"/home/notamitgamer/Documents/bsc/buildLog\"; mkdir -p \"$logDir\"; ts=$(date +\"%Y-%m-%d_%H-%m-%M_%S\"); logFile=\"$logDir/buildLog_$ts.txt\"; B=\"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\"; fnH() { title=\"$1\"; show_c=\"${2:-true}\"; show_l=\"${3:-true}\"; nl=\"${4:-true}\"; if [ \"$show_c\" = \"true\" ]; then if [ \"$nl\" = \"true\" ]; then echo \"\"; fi; echo -e \"\\e[90m$B\\e[0m\"; echo -e \" \\e[36m$title\\e[0m\"; echo -e \"\\e[90m$B\\e[0m\"; echo \"\"; fi; if [ \"$show_l\" = \"true\" ]; then if [ \"$nl\" = \"true\" ]; then echo \"\" >> \"$logFile\"; fi; echo \"$B\" >> \"$logFile\"; echo \" $title\" >> \"$logFile\"; echo \"$B\" >> \"$logFile\"; echo \"\" >> \"$logFile\"; fi; }; fnR() { pad=$(printf \"%-16s\" \"$1\"); echo -e \"${pad}\\e[${3:-0}m$2\\e[0m\"; echo \"${pad}$2\" >> \"$logFile\"; }; fnL() { echo -e \"\\e[${2:-0}m$1\\e[0m\"; clean=$(echo \"$1\" | sed -r \"s/\\x1B\\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g\"); echo \"$clean\" >> \"$logFile\"; }; fnT() { if [ $1 -ge 1000 ]; then echo \"$(($1 / 1000)) sec ($1 ms)\"; else echo \"$1 ms\"; fi; }; ver=$($c --version | head -n 1); fnH \"BUILD\" true true false; fnL \"Compiling ${fileBasename}...\" \"0\"; fnL \"$ver\" \"90\"; fnL \"\" \"0\"; start_t=$(date +%s%3N); out=$($c -fdiagnostics-color=always -g \"${file}\" -o \"$exe\" 2>&1); bexit=$?; end_t=$(date +%s%3N); bms=$((end_t - start_t)); if [ -n \"$out\" ]; then echo -e \"$out\"; cleanOut=$(echo \"$out\" | sed -r \"s/\\x1B\\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g\"); echo \"$cleanOut\" >> \"$logFile\"; fi; w=$(echo \"$out\" | grep -ic \"warning:\"); e=$(echo \"$out\" | grep -ic \"error:\"); if [ $bexit -eq 0 ]; then bs=\"✓ Success\"; bc=\"32\"; else bs=\"✗ Failed\"; bc=\"31\"; fi; fnL \"$bs in $(fnT $bms)\" \"$bc\"; fnH \"BUILD REPORT\"; fnR \"Source\" \"${file}\"; loc=$(wc -l < \"${file}\"); fnR \"Lines of Code\" \"$loc\"; fnR \"Timestamp\" \"$(date +'%Y-%m-%d %H:%M:%S')\"; fnR \"Compiler\" \"$c\"; fnR \"Target\" \"x64\"; fnR \"Build\" \"$bs\" \"$bc\"; if [ $w -gt 0 ]; then wc=\"33\"; else wc=\"0\"; fi; fnR \"Warnings\" \"$w\" \"$wc\"; if [ $e -gt 0 ]; then ec=\"31\"; else ec=\"0\"; fi; fnR \"Errors\" \"$e\" \"$ec\"; if [ -f \"$exe\" ]; then sz=$(du -h \"$exe\" | cut -f1); fnR \"Size\" \"$sz\"; fi; fnR \"Build Time\" \"$(fnT $bms)\"; fnR \"Log File\" \"$logFile\" \"90\"; if [ $bexit -ne 0 ]; then exit 1; fi; fnH \"RUN\" true false; rstart_t=$(date +%s%3N); \"$exe\"; rexit=$?; rend_t=$(date +%s%3N); rms=$((rend_t - rstart_t)); fnH \"EXECUTION REPORT\"; if [ $rexit -eq 0 ]; then rc=\"32\"; else rc=\"31\"; fi; fnR \"Exit Code\" \"$rexit\" \"$rc\"; fnR \"Runtime\" \"$(fnT $rms)\"; rm -f \"$exe\"; fnR \"Executable\" \"Removed\"; fnH \"SOURCE CODE\" false true; cat \"${file}\" >> \"$logFile\"; exit 0",
+ "args": [],
+ "options": {
+ "cwd": "${fileDirname}",
+ "shell": {
+ "executable": "/bin/bash",
+ "args": ["-c"]
+ }
+ },
+ "problemMatcher": ["$gcc"],
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
+ "presentation": {
+ "echo": false,
+ "reveal": "always",
+ "focus": true,
+ "panel": "shared",
+ "showReuseMessage": true,
+ "clear": true
+ },
+ "detail": "Builds, runs, dynamic time, full logging, one-click close, flush top"
+ }
+ ]
+}+
\ No newline at end of file
diff --git a/semester_2/eduincs/pgrm_009.cpp b/semester_2/eduincs/pgrm_009.cpp
@@ -0,0 +1,39 @@
+/*
+ * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 10 Jul 2026
+ * Repo: https://github.com/notamitgamer/bsc
+ * License: MIT
+ */
+
+/* WAP in cpp to overload the following functions
+ int max(int a, int b);
+ int max(int a, int b, int c);
+ float max(float a, float b);
+*/
+
+#include<iostream>
+using namespace std;
+class Maximum {
+public:
+ int max(int a, int b) {
+ return (a > b) ? a : b;
+ }
+
+ int max(int a, int b, int c) {
+ int m = a;
+ if(m < b) m = b;
+ if(m < c) m = c;
+ return m;
+ }
+
+ float max(float a, float b) {
+ return (a > b) ? a : b;
+ }
+};
+
+int main() {
+ Maximum obj;
+ cout << "Between 10, 20: " << obj.max(10, 20) << endl;
+ cout << "Between 10, 20, 30: " << obj.max(10, 20, 30) << endl;
+ cout << "Between 11.5, 10.5: " << obj.max(11.5f, 10.5f) << endl;
+ return 0;
+}+
\ No newline at end of file
diff --git a/semester_2/eduincs/pgrm_010.cpp b/semester_2/eduincs/pgrm_010.cpp
@@ -0,0 +1,24 @@
+/*
+ * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 10 Jul 2026
+ * Repo: https://github.com/notamitgamer/bsc
+ * License: MIT
+ */
+
+/* Default argument */
+
+#include<iostream>
+using namespace std;
+class Interest {
+public:
+ float simpleInterest(float p, float t = 5.0, float r = 1.0) {
+ return (p * t * r) / 100;
+ }
+};
+
+int main() {
+ Interest obj;
+ cout << "Principle only = " << obj.simpleInterest(10000) << endl;
+ cout << "Principle and Time = " << obj.simpleInterest(10000, 8.0f) << endl;
+ cout << "Principle, Time and Rate of Interest = " << obj.simpleInterest(10000, 8.0f, 5.0f) << endl;
+ return 0;
+}+
\ No newline at end of file
diff --git a/semester_2/eduincs/pgrm_011.cpp b/semester_2/eduincs/pgrm_011.cpp
@@ -0,0 +1,75 @@
+/*
+ * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 10 Jul 2026
+ * Repo: https://github.com/notamitgamer/bsc
+ * License: MIT
+ */
+
+/* call by value, call by address, call by reference */
+
+#include<iostream>
+using namespace std;
+class Swap {
+private:
+ int a, b;
+public:
+ void getData() {
+ cout << "Enter two numbers: ";
+ cin >> a >> b;
+ }
+
+ // call by value
+ void swapValue(int x, int y) {
+ int temp = x;
+ x = y;
+ y = temp;
+ cout << "Inside swapValue(): " << x << " " << y << endl;
+ }
+
+ // call by address
+ void swapAddress(int *x, int *y) {
+ int temp = *x;
+ *x = *y;
+ *y = temp;
+ cout << "Inside swapAddress(): " << *x << " " << *y << endl;
+ }
+
+ // call by reference
+ void swapReference(int &x, int &y) {
+ int temp = x;
+ x = y;
+ y = temp;
+ cout << "Inside swapValue(): " << x << " " << y << endl;
+ }
+
+ void display() {
+ cout << "Current values: " << a << " " << b << endl;
+ }
+
+ void test() {
+ cout << "\nOriginal values: " << endl;
+ display();
+
+ cout << "\n== Call by Value ==" << endl;
+ swapValue(a, b);
+ cout << "After swapValue(): " << endl;
+ display();
+
+ cout << "\n== Call by Address ==" << endl;
+ swapAddress(&a, &b);
+ cout << "After swapAddress(): " << endl;
+ display();
+
+ cout << "\n== Call by Reference ==" << endl;
+ swapReference(a, b);
+ cout << "After swapReference(): " << endl;
+ display();
+ }
+ ~Swap() {}
+};
+
+int main() {
+ Swap obj;
+ obj.getData();
+ obj.test();
+ return 0;
+}+
\ No newline at end of file
diff --git a/semester_2/eduincs/pgrm_012.cpp b/semester_2/eduincs/pgrm_012.cpp
@@ -0,0 +1,51 @@
+/*
+ * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 10 Jul 2026
+ * Repo: https://github.com/notamitgamer/bsc
+ * License: MIT
+ */
+
+/* Linear search in cpp */
+
+#include<iostream>
+using namespace std;
+class LinearSearch {
+private:
+ int arr[10];
+ int n;
+public:
+ LinearSearch() {n = 0;}
+
+ void getData() {
+ cout << "Enter number of elements: ";
+ cin >> n;
+ cout << "Enter " << n << " elements: ";
+ for(int i = 0; i < n; i++) {
+ cin >> arr[i];
+ }
+ }
+
+ void Lsearch(int &key, int &position) {
+ position = -1;
+ for(int i = 0; i < n; i++) {
+ if(arr[i] == key) {
+ position = i + 1;
+ }
+ }
+ }
+};
+
+int main() {
+ LinearSearch obj;
+ int key, pos;
+ obj.getData();
+ cout << "Enter the element to search: ";
+ cin >> key;
+ obj.Lsearch(key, pos);
+ if(pos != -1) {
+ cout << "Element found at position " << pos << endl;
+ }
+ else {
+ cout << "Element not found." << endl;
+ }
+ return 0;
+}+
\ No newline at end of file