Skip to content

Commit 2564b0b

Browse files
author
hash-bash
committed
Reformat code and some fixes
0 parents  commit 2564b0b

23 files changed

+1970
-0
lines changed

BinaryAdd.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<iostream>
2+
#include<stack>
3+
4+
using namespace std;
5+
6+
stack<int> read();
7+
8+
void display(stack<int> &s);
9+
10+
stack<int> add(stack<int> &s1, stack<int> &s2);
11+
12+
int main() {
13+
stack<int> s1, s2, s3;
14+
s1 = read();
15+
s2 = read();
16+
s3 = add(s1, s2);
17+
display(s3);
18+
return 0;
19+
}
20+
21+
stack<int> read() {
22+
char a[40];
23+
stack<int> s;
24+
cout << "\nEnter any one binary number: ";
25+
cin >> a;
26+
for (int i = 0; a[i] != '\0'; i++) {
27+
if (a[i] == '1')
28+
s.push(1);
29+
else if (a[i] == '0')
30+
s.push(0);
31+
}
32+
return s;
33+
}
34+
35+
stack<int> add(stack<int> &s1, stack<int> &s2) {
36+
stack<int> s;
37+
int sum, carry = 0, bit1, bit2;
38+
while (!s1.empty() || !s2.empty()) {
39+
bit1 = bit2 = 0;
40+
if (!s1.empty()) {
41+
bit1 = s1.top();
42+
s1.pop();
43+
}
44+
if (!s2.empty()) {
45+
bit2 = s2.top();
46+
s2.pop();
47+
}
48+
sum = (bit1 + bit2 + carry) % 2;
49+
carry = (bit1 + bit2 + carry) / 2;
50+
s.push(sum);
51+
}
52+
if (carry == 1)
53+
s.push(1);
54+
return s;
55+
}
56+
57+
void display(stack<int> &s) {
58+
cout << "\nSum: ";
59+
while (!s.empty()) {
60+
cout << s.top();
61+
s.pop();
62+
}
63+
}

BioData.cpp

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include<iostream>
2+
#include<ios>
3+
#include<limits>
4+
5+
using namespace std;
6+
7+
class BioData {
8+
private:
9+
string name, address, gender;
10+
long phone;
11+
public:
12+
BioData() {
13+
name = "";
14+
address = "";
15+
gender = "";
16+
phone = -1;
17+
}
18+
19+
void getData() {
20+
cout << "\nEnter your name: ";
21+
cin >> name;
22+
cout << "\nEnter gender: ";
23+
cin >> gender;
24+
cin.ignore(numeric_limits<streamsize>::max(), '\n');
25+
cout << "\nEnter address: ";
26+
getline(cin, address);
27+
cout << "\nEnter phone number: ";
28+
cin >> phone;
29+
}
30+
31+
void putData() {
32+
cout << "\nPERSONAL DETAILS:- \n";
33+
cout << "\nNAME: " << name;
34+
cout << "\nGENDER: " << gender;
35+
cout << "\nADDRESS: " << address;
36+
cout << "\nCONTACT: " << phone;
37+
}
38+
};
39+
40+
class ProfClass {
41+
private:
42+
string os, pl;
43+
string classname;
44+
public:
45+
ProfClass() {
46+
os = "";
47+
pl = "";
48+
classname = "";
49+
}
50+
51+
void getData() {
52+
cout << "\nEnter name of the course: ";
53+
cin >> classname;
54+
cin.ignore(numeric_limits<streamsize>::max(), '\n');
55+
cout << "\nEnter which operating system do you know?: ";
56+
getline(cin, os);
57+
cout << "\nEnter which programming language do you know?: ";
58+
getline(cin, pl);
59+
}
60+
61+
void putData() {
62+
cout << "\nPROFESSIONAL DETAILS:- \n ";
63+
cout << "\nCOURSE: " << classname;
64+
cout << "\nOS KNOWN: " << os;
65+
cout << "\nPROGRAMMING LANGUAGES: " << pl;
66+
}
67+
};
68+
69+
class AcadClass {
70+
private:
71+
float ten, twe, fe;
72+
public:
73+
AcadClass() {
74+
ten = -1;
75+
twe = -1;
76+
fe = -1;
77+
}
78+
79+
void getData() {
80+
cout << "\nEnter 10th class percentage: ";
81+
cin >> ten;
82+
cout << "\nEnter 12th class percentage: ";
83+
cin >> twe;
84+
cout << "\nEnter first year percentage: ";
85+
cin >> fe;
86+
}
87+
88+
void putData() {
89+
cout << "\nACADEMIC DETAILS:- \n";
90+
cout << "\n10th MARKS: " << ten;
91+
cout << "\n12th MARKS: " << twe;
92+
cout << "\nFE MARKS: " << fe;
93+
}
94+
};
95+
96+
class Resume : public BioData, public ProfClass, public AcadClass {
97+
private:
98+
string title;
99+
public:
100+
Resume() : BioData(), ProfClass(), AcadClass() {
101+
title = "";
102+
}
103+
104+
void getData() {
105+
BioData::getData();
106+
ProfClass::getData();
107+
AcadClass::getData();
108+
cout << "\nEnter the title for your Resume: ";
109+
cin >> title;
110+
}
111+
112+
void putData() {
113+
cout << "\n=============================" << title << "=============================\n";
114+
BioData::putData();
115+
ProfClass::putData();
116+
AcadClass::putData();
117+
}
118+
};
119+
120+
int main() {
121+
Resume r1;
122+
r1.getData();
123+
r1.putData();
124+
return 0;
125+
}

BusReservation.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include <iostream>
2+
#include <set>
3+
#include<iomanip>
4+
5+
using namespace std;
6+
7+
class Bus1 {
8+
public:
9+
string name;
10+
int seat, dist, bill;
11+
12+
Bus1(string n, int b, int p, int g) : name(n), dist(b), seat(p), bill(g) {};
13+
14+
bool operator<(const Bus1 &b) const {
15+
return name < b.name;
16+
}
17+
};
18+
19+
int main() {
20+
int ch;
21+
char cho;
22+
string na, y;
23+
int b, p, g, flag = 0, x;
24+
set<Bus1> data;
25+
do {
26+
cout << "\n=====================PUNE-MUMBAI BUS=====================";
27+
cout << "\n 1. Entry & sort passengers";
28+
cout << "\n 2. Display bill of all passengers";
29+
cout << "\n 3. Display all passengers";
30+
cout << "\n 4. Search by seat number";
31+
cout << "\n 5. Search by passenger name";
32+
cout << "\n\tEnter your choice: ";
33+
cin >> ch;
34+
switch (ch) {
35+
case 1:
36+
cout << "\nEnter passenger details:";
37+
cout << "\nName: ";
38+
cin >> na;
39+
cout << "\nDistance traveling (Kms): ";
40+
cin >> b;
41+
cout << "\nSeat number: ";
42+
cin >> p;
43+
if (b <= 99)
44+
g = b * 2;
45+
if (b > 100 && b < 199)
46+
g = b * 3;
47+
if (b >= 200 && b <= 299)
48+
g = b * 4;
49+
if (b >= 300 && b < 399)
50+
g = b * 5;
51+
data.insert(Bus1(na, b, p, g));
52+
break;
53+
case 2:
54+
cout << "\nYou will be charged according to the table given to you, per kilometer.\n";
55+
cout << "\t" << left << setw(15) << "Name" << left << setw(15) << "Seat Number" << left << setw(15)
56+
<< "Net Pay" << endl;
57+
for (set<Bus1>::const_iterator it = data.begin(); it != data.end(); it++)
58+
cout << "\t" << left << setw(15) << it->name << left << setw(15) << it->seat << left << setw(15)
59+
<< it->bill << endl;
60+
break;
61+
case 3:
62+
cout << "\t" << left << setw(15) << "Name" << left << setw(15) << "Distance" << left << setw(10)
63+
<< "Seat Number" << endl;
64+
for (set<Bus1>::const_iterator it = data.begin(); it != data.end(); it++)
65+
cout << "\t" << left << setw(15) << it->name << left << setw(15) << it->dist << left << setw(10)
66+
<< it->seat << endl;
67+
break;
68+
case 4:
69+
cout << "\nEnter seat number for searching: ";
70+
cin >> x;
71+
for (set<Bus1>::const_iterator it = data.begin(); it != data.end(); it++)
72+
if (it->seat == x) {
73+
flag = 1;
74+
cout << "\t" << left << setw(15) << it->name << left << setw(15) << it->dist << left << setw(10)
75+
<< it->seat << endl;
76+
}
77+
if (flag == 0)
78+
cout << "\nRecord not found.";
79+
break;
80+
case 5:
81+
cout << "\nEnter same for searching: ";
82+
cin >> y;
83+
for (set<Bus1>::const_iterator it = data.begin(); it != data.end(); it++)
84+
if (it->name == y) {
85+
flag = 1;
86+
cout << "\t" << left << setw(15) << it->name << left << setw(15) << it->dist << left << setw(10)
87+
<< it->seat << endl;
88+
}
89+
if (flag == 0)
90+
cout << "\nRecord not found.";
91+
break;
92+
93+
default:
94+
cout << "\nWrong choice.";
95+
break;
96+
}
97+
cout << "\nDo you want to continue? (y/n): ";
98+
cin >> cho;
99+
} while (cho == 'y' || cho == 'Y');
100+
return 0;
101+
}

Calculator.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# include <iostream>
2+
3+
using namespace std;
4+
5+
class calc {
6+
public:
7+
void init() {
8+
char op;
9+
float num1, num2;
10+
cout << "========================CALCULATOR========================";
11+
cout << "\nPlease enter first number then operator followed by second number: ";
12+
cin >> num1;
13+
cin >> op;
14+
cin >> num2;
15+
switch (op) {
16+
case '+':
17+
cout << num1 + num2;
18+
break;
19+
case '-':
20+
cout << num1 - num2;
21+
break;
22+
case '*':
23+
cout << num1 * num2;
24+
break;
25+
case '/':
26+
cout << num1 / num2;
27+
break;
28+
default:
29+
cout << "\nWrong operation.";
30+
break;
31+
}
32+
}
33+
34+
void cont() {
35+
char ch;
36+
cout << "\nDo you want to continue? (y/n): ";
37+
cin >> ch;
38+
if (ch == 'Y' || ch == 'y') {
39+
calc c1;
40+
c1.init();
41+
}
42+
}
43+
};
44+
45+
int main() {
46+
calc c1;
47+
c1.init();
48+
c1.cont();
49+
return 0;
50+
}

0 commit comments

Comments
 (0)