-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled5.cpp
More file actions
144 lines (97 loc) · 1.94 KB
/
Untitled5.cpp
File metadata and controls
144 lines (97 loc) · 1.94 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
/*
Write clean code
- Do proper indentation
// This one is bad
void main()
{
int a=0;
for(int x=0;x<3;x++)
count<<x;
}
// This is good
void main()
{
int a = 0;
for(int x = 0; x < 3; x++)
count << x;
}
- give prover spacing
// bad
int a=b+c/3;
// good
int a = b + c / 3;
"Any fool can write a code that
a machine can understand, a programmer
writes a code that a humans can understand."
- Mertin Fowller
Do read this article
https://blog.alexdevero.com/6-simple-tips-writing-clean-code/
*/
#include <iostream>
using namespace std;
class classa{
public:
virtual void display(){
cout << "class a"<<endl;
}
virtual void objects() = 0;
};
class classb: public classa{
public:
void display(){
cout<<"class b \n";
}
void objects(){
cout<< "you choose a bat" << endl;
}
int sum(int a, int b){
int c;
c = a + b;
return c;
}
int sum(int a, int b, int c){
int d;
d = a + b + c;
return d;
}
};
class classc: public classa{
public:
void objects(){
cout<< "you choose a cat" << endl;
}
};
int main() {
// overloading objects function
cout << "hey! lets play a game \n\n";
cout << "It is a game of luck! what do you want bat or cat??? \n\n";
cout << "1-b \n\n2-c \n\n";
int choice;
cout << "enter 1 or 2 = ";
cin >> choice;
classa * a;
classb b;
classc c;
if (choice==1){
a=&b;
a->objects();
}
else{
a=&c;
a->objects();
}
cout<<"\n\n\n\n\nsome examples of polymorphism\n\n";
classa *aa;
// function overriding
aa->display();
b.display();
//runtime polymorphism virtual func
classa * p = new classb;
p->display();
//function overloading
int sum;
sum = b.sum(2,4,8);
cout << "3 parameter sum = "<<sum<<endl;
sum = b.sum(2,4);
cout << "2 parameter sum = "<<sum<<endl;
}