Browse Source

added ptr exercises

master
Sudipto Ghosh 5 months ago
parent
commit
f0d0fb46de
Signed by: Sudipto Ghosh <sudipto@ghosh.pro> GPG Key ID: FDE756FE89D3B4FF
49 changed files with 794 additions and 38 deletions
  1. 14
    11
      README.md
  2. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/.vscode/c_cpp_properties.json
  3. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/.vscode/launch.json
  4. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/.vscode/tasks.json
  5. 26
    0
      Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/main.cpp
  6. BIN
      Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/main.exe
  7. 3
    0
      Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/output.txt
  8. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/deleteElement/.vscode/c_cpp_properties.json
  9. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/deleteElement/.vscode/launch.json
  10. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/deleteElement/.vscode/tasks.json
  11. 42
    0
      Year I/Semester I/C++/Other/02-09-2018/deleteElement/main.cpp
  12. BIN
      Year I/Semester I/C++/Other/02-09-2018/deleteElement/main.exe
  13. 3
    0
      Year I/Semester I/C++/Other/02-09-2018/deleteElement/output.txt
  14. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/replaceVowels/.vscode/c_cpp_properties.json
  15. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/replaceVowels/.vscode/launch.json
  16. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/replaceVowels/.vscode/tasks.json
  17. 32
    0
      Year I/Semester I/C++/Other/02-09-2018/replaceVowels/main.cpp
  18. BIN
      Year I/Semester I/C++/Other/02-09-2018/replaceVowels/main.exe
  19. 2
    0
      Year I/Semester I/C++/Other/02-09-2018/replaceVowels/output.txt
  20. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/.vscode/c_cpp_properties.json
  21. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/.vscode/launch.json
  22. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/.vscode/tasks.json
  23. 32
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/main.cpp
  24. BIN
      Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/main.exe
  25. 2
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/output.txt
  26. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/.vscode/c_cpp_properties.json
  27. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/.vscode/launch.json
  28. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/.vscode/tasks.json
  29. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/main.cpp
  30. BIN
      Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/main.exe
  31. 2
    0
      Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/output.txt
  32. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/.vscode/c_cpp_properties.json
  33. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/.vscode/launch.json
  34. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/.vscode/tasks.json
  35. 37
    0
      Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/main.cpp
  36. BIN
      Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/main.exe
  37. 4
    0
      Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/output.txt
  38. 20
    0
      Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/.vscode/c_cpp_properties.json
  39. 29
    0
      Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/.vscode/launch.json
  40. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/.vscode/tasks.json
  41. 24
    0
      Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/main.cpp
  42. BIN
      Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/main.exe
  43. 2
    0
      Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/output.txt
  44. 19
    13
      Year I/Semester I/C++/Practicals/menuDrivenStringOps/.vscode/c_cpp_properties.json
  45. 4
    4
      Year I/Semester I/C++/Practicals/menuDrivenStringOps/.vscode/launch.json
  46. 12
    7
      Year I/Semester I/C++/Practicals/menuDrivenStringOps/.vscode/tasks.json
  47. BIN
      Year I/Semester I/C++/Practicals/menuDrivenStringOps/main
  48. 3
    3
      Year I/Semester I/C++/Practicals/menuDrivenStringOps/main.cpp
  49. BIN
      Year I/Semester I/C++/Practicals/menuDrivenStringOps/main.exe

+ 14
- 11
README.md View File

@@ -9,20 +9,23 @@ Textbooks are available at [url.ghosh.pro/ducsbooks](https://url.ghosh.pro/ducsb
The code is organized mainly under the following heads:

- Year I
- Semester I
- Tutorials
- Practicals
- Projects
- Others
- Semester II
- Subject
- Semester I
- Tutorials
- Practicals
- Projects
- Others
- Semester II
- Year II
- Semester I
- Semester II
- Subject
- Semester I
- Semester II
- Year III
- Semester I
- Semester II
- Subject
- Semester I
- Semester II

**NOTE**: The code written in most of the files was compiled on the compiler available on the latest release of the GNU Compiler Collection to Linux executable binaries. The code has to be adapted for Borland/Turbo C++ compilers by the user of the code in case they use the aforementioned compilers.
**NOTE**: The code written in most of the files was compiled on the compiler available on the latest release of the GNU Compiler Collection to Linux or Windows executable binaries. The code has to be adapted for Borland/Turbo C++ compilers by the user of the code in case they use the aforementioned compilers.

## License


+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 26
- 0
Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/main.cpp View File

@@ -0,0 +1,26 @@
#include <iostream>

using namespace std;

int main()
{
int a, b, c;
int *pa = &a; // points to a
int *pb = &b; // points to b
int *pc = &c; // points to c
int **psum = &pc; // points to pc

cout << "Enter A: ";
cin >> a;
cout << "Enter B: ";
cin >> b;

*pc = (*pa) + (*pb); // changing value of c

/**
* accessing value of c by deferencing twice
* as psum->pc->c
*/
cout << "Sum of A and B: " << (**psum);
return 0;
}

BIN
Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/main.exe View File


+ 3
- 0
Year I/Semester I/C++/Other/02-09-2018/addNumsPtrs/output.txt View File

@@ -0,0 +1,3 @@
Enter A: 1
Enter B: 2
Sum of A and B: 3

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/deleteElement/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/deleteElement/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/deleteElement/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 42
- 0
Year I/Semester I/C++/Other/02-09-2018/deleteElement/main.cpp View File

@@ -0,0 +1,42 @@
#include <iostream>
#define MAX_ELEMS 100

using namespace std;

void deleteElement(int[], int, int);

int main()
{
int n, d, arr[MAX_ELEMS];

cout << "Enter size of the array: ";
cin >> n;

cout << "Enter elements: ";
for (int i = 0; i < n; i++)
cin >> arr[i];

cout << "Enter index of element to delete: ";
cin >> d;

deleteElement(arr, n, d);

cout << endl;

return 0;
}

void deleteElement(int a[], int s, int e)
{
for (int i = 0; i < s; i++)
if (i == e)
for (int j = e; j < s; j++)
a[j] = a[j + 1];
s--;

cout << "Compacted array: ";
for (int i = 0; i < s; i++)
cout << a[i] << " ";

return;
}

BIN
Year I/Semester I/C++/Other/02-09-2018/deleteElement/main.exe View File


+ 3
- 0
Year I/Semester I/C++/Other/02-09-2018/deleteElement/output.txt View File

@@ -0,0 +1,3 @@
Enter elements: 1 2 3 4 5 6 7 8 9 0
Enter index of element to delete: 4
Compacted array: 1 2 3 4 6 7 8 9 0

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/replaceVowels/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/replaceVowels/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/replaceVowels/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 32
- 0
Year I/Semester I/C++/Other/02-09-2018/replaceVowels/main.cpp View File

@@ -0,0 +1,32 @@
#include <iostream>
#include <cctype>

using namespace std;

void replaceVowels(char[]);

int main()
{
char input[255];
cout << "Enter a string: ";
cin >> input;

replaceVowels(input);

cout << "Replaced string: ";
cout << input;

return 0;
}

void replaceVowels(char s[])
{
for (int i = 0; s[i] != '\0'; i++)
if ((char)tolower(s[i]) == 'a' ||
(char)tolower(s[i]) == 'e' ||
(char)tolower(s[i]) == 'i' ||
(char)tolower(s[i]) == 'o' ||
(char)tolower(s[i]) == 'u')
s[i] = '*';
return;
}

BIN
Year I/Semester I/C++/Other/02-09-2018/replaceVowels/main.exe View File


+ 2
- 0
Year I/Semester I/C++/Other/02-09-2018/replaceVowels/output.txt View File

@@ -0,0 +1,2 @@
Enter a string: Sudipto
Replaced string: S*d*pt*

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 32
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/main.cpp View File

@@ -0,0 +1,32 @@
#include <iostream>

using namespace std;

int *smallest(int[], int);

int main()
{
int a[10], *s;

cout << "Enter 10 integers: ";
for (int i = 0; i < 10; i++)
cin >> a[i];

s = smallest(a, 10);

cout << "Smallest integer: " << *s
<< endl;

return 0;
}

int *smallest(int a[], int n)
{
int *psmall, *pwalk, *plast;
for (psmall = a, pwalk = a + 1, plast = a + (n - 1);
pwalk <= plast; pwalk++)
if (*pwalk <= *psmall)
psmall = pwalk;

return psmall;
}

BIN
Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/main.exe View File


+ 2
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestArrayPtrs/output.txt View File

@@ -0,0 +1,2 @@
Enter 10 integers: 5 1 2 4 56 5 0 -87 4 5
Smallest integer: -87

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/main.cpp View File

@@ -0,0 +1,20 @@
#include <iostream>

using namespace std;

int *smallest(int *, int *);

int main()
{
int a, b, *s;
cout << "Enter 2 integers: ";
cin >> a >> b;
s = smallest(&a, &b);
cout << "Smallest integer: " << *s;
return 0;
}

int *smallest(int *p, int *q)
{
return (*p > *q ? q : p);
}

BIN
Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/main.exe View File


+ 2
- 0
Year I/Semester I/C++/Other/02-09-2018/smallestInputPtrs/output.txt View File

@@ -0,0 +1,2 @@
Enter 2 integers: 23123 2312
Smallest integer: 2312

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 37
- 0
Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/main.cpp View File

@@ -0,0 +1,37 @@
#include <iostream>
#define MAX_ELEMS 100

using namespace std;

int main()
{
int n, i, j, k;
int arr[MAX_ELEMS], even[MAX_ELEMS],
odd[MAX_ELEMS];
cout << "Enter size of the array: ";
cin >> n;

cout << "Enter elements: ";
for (i = 0, j = 0; i < n; i++)
cin >> arr[i];

for (i = 0, k = 0, j = 0; i < n; i++)
if (arr[i] % 2)
odd[k++] = arr[i];
else
even[j++] = arr[i];

cout << "Even elements: ";
for (i = 0; i < j; i++)
cout << even[i] << " ";

cout << endl;

cout << "Odd elements: ";
for (i = 0; i < k; i++)
cout << odd[i] << " ";

cout << endl;

return 0;
}

BIN
Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/main.exe View File


+ 4
- 0
Year I/Semester I/C++/Other/02-09-2018/splitArrEvenOdd/output.txt View File

@@ -0,0 +1,4 @@
Enter size of the array: 5
Enter elements: 1 2 3 4 5
Even elements: 2 4
Odd elements: 1 3 5

+ 20
- 0
Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/.vscode/c_cpp_properties.json View File

@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 29
- 0
Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/.vscode/launch.json View File

@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/.vscode/tasks.json View File

@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

+ 24
- 0
Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/main.cpp View File

@@ -0,0 +1,24 @@
#include <iostream>

using namespace std;

void swap(int *, int *);

int main()
{
int a, b, *pa = &a, *pb = &b;
cout << "Enter 2 Integers: ";
cin >> *pa >> *pb;
swap(pa, pb);
cout << "After Swapping: ";
cout << *pa << " " << *pb << endl;
return 0;
}

void swap(int *p, int *q)
{
int temp = *p;
*p = *q;
*q = temp;
return;
}

BIN
Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/main.exe View File


+ 2
- 0
Year I/Semester I/C++/Other/02-09-2018/swapNumsPtrs/output.txt View File

@@ -0,0 +1,2 @@
Enter 2 Integers: 1 9
After Swapping: 9 1

+ 19
- 13
Year I/Semester I/C++/Practicals/menuDrivenStringOps/.vscode/c_cpp_properties.json View File

@@ -1,14 +1,20 @@
{
"configurations": [
{
"name": "Linux",
"includePath": ["${workspaceFolder}/**"],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

+ 4
- 4
Year I/Semester I/C++/Practicals/menuDrivenStringOps/.vscode/launch.json View File

@@ -5,16 +5,17 @@
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
@@ -22,8 +23,7 @@
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
"preLaunchTask": "g++.exe build active file"
}
]
}

+ 12
- 7
Year I/Semester I/C++/Practicals/menuDrivenStringOps/.vscode/tasks.json View File

@@ -1,19 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "/usr/bin"
}
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
],
"version": "2.0.0"
]
}

BIN
Year I/Semester I/C++/Practicals/menuDrivenStringOps/main View File


+ 3
- 3
Year I/Semester I/C++/Practicals/menuDrivenStringOps/main.cpp View File

@@ -203,11 +203,11 @@ void compareStrings(char a[], char b[])
cout << "length(String 1) < length(String 2)" << endl;

int flag = 0;
for (int i = 0, j = 0; i < stringLength(a) && j < stringLength(b); i++, j++)
for (int i = 0, j = 0; i < stringLength(a); i++, j++)
if (a[i] == b[j])
flag = 1;
flag++;

if (flag)
if (flag == stringLength(a))
cout << "String 1 is the same as String 2!" << endl;

return;

BIN
Year I/Semester I/C++/Practicals/menuDrivenStringOps/main.exe View File


Loading…
Cancel
Save