-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP.cpp
More file actions
227 lines (208 loc) · 4.67 KB
/
Copy pathOOP.cpp
File metadata and controls
227 lines (208 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
#include<iostream>
using namespace std;
class Employee
{
private:
int a, b, c;
public:
int d, e;
void setData(int a1, int b1, int c1);
void getData(){
cout << "The value of a is : " <<a<<endl;
cout << "The value of b is : " <<b<<endl;
cout << "The value of c is : " <<c<<endl;
cout << "The value of d is : " <<d<<endl;
cout << "The value of e is : " <<e<<endl;
}
};
void Employee :: setData(int a1, int b1, int c1){
a = a1;
b = b1;
c = c1;
}
int main(){
Employee Sumit;
Sumit.e = 123;
Sumit.d = 34;
Sumit.e = 89;
Sumit.setData(1, 2, 5);
Sumit.getData();
return 0;
}
*/
// Nesting of member function
// #include <iostream>
// #include <string>
// using namespace std;
// class binary
// {
// string s;
// public:
// void read(void);
// void chk_bin(void);
// void ones_complement(void);
// void display(void);
// };
// void binary :: read(void){
// cout << "Enter a binary number : ";
// cin >>s;
// }
// void binary :: chk_bin(void){
// for (int i = 0; i <s.length(); i++)
// {
// if(s.at(i) != '0' && s.at(i) != '1'){
// cout << "Incorrect binary format" << endl;
// exit(0);
// }
// }
// cout << "Correct binary format" << endl;
// }
// void binary :: ones_complement(void){
// for (int i = 0; i < s.length(); i++){
// if (s.at(i) == '0'){
// s.at(i) = '1';
// }
// else{
// s.at(i) = '0';
// }
// }
// }
// void binary :: display(void)
// {
// for (int i = 0; i < s.length(); i++){
// cout << s.at(i);
// }
// }
// int main(){
// binary b;
// b.read();
// b.chk_bin();
// b.ones_complement();
// cout << "Displaying your binary number" << endl;
// b.display();
// cout << endl;
// return 0;
// }
// Lecture no 23
// object memory allocation & using array in classes
// #include<iostream>
// using namespace std;
// class shop{
// int itemId[20];
// int itemPrice[30];
// int counter;
// public:
// void initCounter(void) { counter = 0; }
// void setPrice(void);
// void displayPrice(void);
// };
// void shop :: setPrice(void){
// cout << "Enter Id of your item no "<< counter+1 << endl;
// cin >> itemId[counter];
// cout << "Enter Price of your item " << endl;
// cin >> itemPrice[counter];
// counter++;
// };
// void shop :: displayPrice (void){
// for (int i = 0; i < counter; i++)
// {
// cout << "The Price of item with Id " << itemId[i] << " is " << itemPrice[i] << endl;
// }
// }
// int main(){
// shop dukaan;
// dukaan.initCounter();
// dukaan.setPrice();
// dukaan.setPrice();
// dukaan.setPrice();
// dukaan.displayPrice();
// return 0;
// }
// Lecture no 24
// #include<iostream>
// using namespace std;
// class employee{
// int id;
// static int count;
// public:
// void setData (void){
// cout << "Enter the Id ";
// cin >> id;
// count++;
// }
// void getData (void){
// cout << "The Id of employee " << id << " and this is employee number "<<count<<endl;
// }
// };
// int employee::count; // default value is 0
// int main(){
// employee sumit, kashish;
// sumit.setData();
// sumit.getData();
// kashish.setData();
// kashish.getData();
// return 0;
// }
// Lecture no 25
// array of objects
// #include<iostream>
// using namespace std;
// class Employee{
// int id;
// int salary;
// public:
// void setId(void){
// salary = 212;
// cout<<"Enter the Id of employee: ";
// cin >> id;
// }
// void getId(void){
// cout<<"The Id of employee is: "<<id<<endl;
// }
// };
// int main() {
// 1st way to create an array of objects
// Employee sumit, kashish, shubh, kajal;
// sumit.setId();
// sumit.getId();
// 2nd way to create an array of objects suppose we have 1000 employees so we don't want to create 1000 objects manually
// Employee S7[5];
// for (int i = 0; i < 5; i++){
// S7[i].setId();
// S7[i].getId();
// }
// return 0;
// };
#include <iostream>
using namespace std;
class complex
{
int a, b;
public:
void setData(int x, int y)
{
a = x;
b = y;
}
void setDataBySum(complex o1, complex o2)
{
a = o1.a + o2.a;
b = o1.b + o2.b;
}
void printNumber()
{
cout<<"The complex number is: " << a << " + " << b << "i" << endl;
}
};
int main()
{
complex c1, c2, c3;
c1.setData(1, 2);
c1.printNumber();
c2.setData(3, 4);
c2.printNumber();
c3.setDataBySum(c1, c2);
c3.printNumber();
return 0;
}