Skip to content

Commit 4074347

Browse files
commit
0 parents  commit 4074347

23 files changed

+1263
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.exe

.vscode/c_cpp_properties.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [
9+
"_DEBUG",
10+
"UNICODE",
11+
"_UNICODE"
12+
],
13+
"windowsSdkVersion": "10.0.19041.0",
14+
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
15+
"cStandard": "c17",
16+
"cppStandard": "c++17",
17+
"intelliSenseMode": "windows-msvc-x64"
18+
}
19+
],
20+
"version": 4
21+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}

.vscode/tasks.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "cppbuild",
5+
"label": "C/C++: g++.exe build active file",
6+
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
7+
"args": [
8+
"-fdiagnostics-color=always",
9+
"-g",
10+
"${file}",
11+
"-o",
12+
"${fileDirname}\\${fileBasenameNoExtension}.exe"
13+
],
14+
"options": {
15+
"cwd": "${fileDirname}"
16+
},
17+
"problemMatcher": [
18+
"$gcc"
19+
],
20+
"group": {
21+
"kind": "build",
22+
"isDefault": true
23+
},
24+
"detail": "Task generated by Debugger."
25+
}
26+
],
27+
"version": "2.0.0"
28+
}

Bubble Sort.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//{ Driver Code Starts
2+
// Initial Template for C++
3+
4+
// C program for implementation of Bubble sort
5+
#include <stdio.h>
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
// swapping the elements
10+
void swap(int *xp, int *yp)
11+
{
12+
int temp = *xp;
13+
*xp = *yp;
14+
*yp = temp;
15+
}
16+
17+
// } Driver Code Ends
18+
// User function Template for C++
19+
20+
class Solution
21+
{
22+
public:
23+
// Function to sort the array using bubble sort algorithm.
24+
void bubbleSort(int arr[], int n)
25+
{
26+
for (int i = 0; i < n - 1; i++)
27+
{
28+
for (int j = 0; j < n - i - 1; j++)
29+
{
30+
if (arr[j] > arr[j + 1])
31+
{
32+
swap(arr[j], arr[j + 1]);
33+
}
34+
}
35+
}
36+
}
37+
};
38+
39+
//{ Driver Code Starts.
40+
41+
/* Function to print an array */
42+
void printArray(int arr[], int size)
43+
{
44+
int i;
45+
for (i = 0; i < size; i++)
46+
printf("%d ", arr[i]);
47+
printf("\n");
48+
}
49+
50+
// Driver program to test above functions
51+
int main()
52+
{
53+
int arr[1000], n, T, i;
54+
55+
scanf("%d", &T);
56+
57+
while (T--)
58+
{
59+
60+
scanf("%d", &n);
61+
62+
for (i = 0; i < n; i++)
63+
scanf("%d", &arr[i]);
64+
65+
Solution ob;
66+
67+
ob.bubbleSort(arr, n);
68+
printArray(arr, n);
69+
}
70+
return 0;
71+
;
72+
}
73+
// } Driver Code Ends

C++ Classes Introduction.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//{ Driver Code Starts
2+
// Initial Template for C++
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
// } Driver Code Ends
7+
// User function Template for C++
8+
9+
// CollegeCourse Class
10+
class CollegeCourse
11+
{
12+
public:
13+
string courseId;
14+
char grade;
15+
int credits;
16+
17+
void set_CourseId(string CID)
18+
{
19+
courseId = CID;
20+
}
21+
22+
void set_Grade(char g)
23+
{
24+
grade = g;
25+
}
26+
void set_Credit(int cr)
27+
{
28+
credits = cr;
29+
}
30+
31+
int calculateGradePoints(char g)
32+
{
33+
if (g == 'A' || g == 'a')
34+
{
35+
grade = 10;
36+
}
37+
else if (g == 'B' || g == 'b')
38+
{
39+
grade = 9;
40+
}
41+
else if (g == 'C' || g == 'c')
42+
{
43+
grade = 8;
44+
}
45+
else if (g == 'D' || g == 'd')
46+
{
47+
grade = 7;
48+
}
49+
else if (g == 'E' || g == 'e')
50+
{
51+
grade = 6;
52+
}
53+
else
54+
{
55+
grade = 5;
56+
}
57+
return grade;
58+
}
59+
60+
float calculateHonorPoints(int gp, int cr)
61+
{
62+
return grade * credits;
63+
}
64+
65+
void display()
66+
{
67+
cout << int(grade)<<" ";
68+
cout << grade * credits << endl;
69+
}
70+
};
71+
72+
//{ Driver Code Starts.
73+
74+
int main()
75+
{
76+
int t;
77+
cin >> t;
78+
while (t--)
79+
{
80+
CollegeCourse cc;
81+
string courseId;
82+
int gp;
83+
char grade;
84+
int credits;
85+
cin >> courseId >> grade >> credits;
86+
cc.set_CourseId(courseId);
87+
cc.set_Grade(grade);
88+
cc.set_Credit(credits);
89+
gp = cc.calculateGradePoints(grade);
90+
cc.calculateHonorPoints(gp, credits);
91+
cc.display();
92+
}
93+
return 0;
94+
}
95+
96+
// } Driver Code Ends

C++ Function overloading.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//{ Driver Code Starts
2+
//Initial Template for C++
3+
4+
#include <iostream>
5+
using namespace std;
6+
7+
8+
9+
// } Driver Code Ends
10+
//User function Template for C++
11+
12+
void volume(int s)
13+
{
14+
cout<<s*s*s<<endl;
15+
}
16+
17+
void volume(int r, int h)
18+
{
19+
cout<<3.14159*r*r*h<<endl;
20+
}
21+
22+
void volume(int l, int b, int h)
23+
{
24+
cout<<l*b*h<<endl;
25+
}
26+
27+
28+
29+
//{ Driver Code Starts.
30+
int main()
31+
{
32+
int t;
33+
cin>>t;
34+
while(t--)
35+
{
36+
int q;
37+
cin>>q;
38+
39+
switch (q)
40+
{
41+
case 1:
42+
int edge;
43+
cin>>edge;
44+
volume(edge);
45+
break;
46+
47+
case 2:
48+
int radius, heigh;
49+
cin>>radius>>heigh;
50+
volume(radius, heigh);
51+
break;
52+
53+
case 3:
54+
int length, width, height;
55+
cin>>length>>width>>height;
56+
volume(length, width, height);
57+
break;
58+
59+
}
60+
61+
62+
63+
}
64+
65+
return 0;
66+
}
67+
// } Driver Code Ends

C++ Inheritance introduction.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//{ Driver Code Starts
2+
// Initial Template for C++
3+
4+
#include <iostream>
5+
using namespace std;
6+
7+
// } Driver Code Ends
8+
// User function Template for C++
9+
10+
class Cuboid
11+
{
12+
public:
13+
int length, width, height;
14+
void display()
15+
{
16+
cout << length << " " << width << " " << height << endl;
17+
}
18+
};
19+
20+
class CuboidVol : public Cuboid
21+
{
22+
public:
23+
void read_input(int l, int w, int h)
24+
{
25+
length = l;
26+
width = w;
27+
height = h;
28+
}
29+
void display()
30+
{
31+
cout << length * width * height << endl;
32+
}
33+
};
34+
35+
//{ Driver Code Starts.
36+
37+
int main()
38+
{
39+
int t;
40+
cin >> t;
41+
42+
while (t--)
43+
{
44+
int l, w, h;
45+
cin >> l >> w >> h;
46+
47+
// Declare a CuboidVol object
48+
49+
CuboidVol c_vol;
50+
51+
// Read length width and height
52+
53+
c_vol.read_input(l, w, h);
54+
55+
// Print length, width and height
56+
57+
c_vol.Cuboid::display();
58+
59+
// Print the Volume
60+
61+
c_vol.display();
62+
}
63+
64+
return 0;
65+
}
66+
// } Driver Code Ends

0 commit comments

Comments
 (0)