-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.cpp
162 lines (160 loc) · 2.49 KB
/
index.cpp
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
#include<iostream>
#include<stdlib.h>
#include<string>
#include<fstream>
using namespace std;
class A // function overloding
{
protected :
int a[3];
public:
void sum()
{
int t=0;
cout<<"Enter there numbers for sum :"<<endl;
for(int i=0;i<3;i++)
{
cin>>a[i];
}
cout<<"Sum : ";
for(int i=0;i<3;i++)
{
t+=a[i];
}
cout<<t<<endl;
}
void sum(int x,int y,int z)
{
int t=0;
a[0]=x;
a[1]=y;
a[2]=z;
cout<<"Sum : ";
for(int i=0;i<3;i++)
{
t+=a[i];
}
cout<<t<<endl;
}
int sum1()
{
int t=0;
cout<<"Enter there numbers for sum :"<<endl;
for(int i=0;i<3;i++)
{
cin>>a[i];
}
cout<<"Sum : ";
for(int i=0;i<3;i++)
{
t+=a[i];
}
return t;
}
int sum1(int x,int y,int z)
{
int t=0;
a[0]=x;
a[1]=y;
a[2]=z;
for(int i=0;i<3;i++)
{
t+=a[i];
}
cout<<"Sum : ";
return t;
}
friend void f(A);
};
class B : public A //single level in
{
public:
int sub(int x,int b,int c,int d)
{
a[0]=b;
a[1]=c;
a[2]=d;
cout<<"Sub : ";
for(int i=0;i<3;i++)
{
x-=a[i];
}
return x;
}
};
class c: public B //multilevel in
{ public:
void mul(int x,int y, int z)
{
int t=1;
a[0]=x;
a[1]=y;
a[2]=z;
cout<<"Mul : ";
for(int i=0;i<3;i++)
{
t*=a[i];
}
cout<<t;
}
};
class E
{
public:
void fun()
{
cout<<"I Am a demo class";
}
};
class D: public A,public E
{
public:
D()
{
cout<<"I am constructor "<<endl;
}
~D()
{
cout<<"I am distuctur "<<endl;
}
};
class expansion
{
int a,b;
void divide()
{
cout<<"enter the value of a and b";
cin>>a>>b;
try
{
if(b!=0)
cout<<"division:"<<a/b;
else throw(b);
}
catch(int x)
{
cout<<"can't division by zero";
}
}
};
void f(A o)
{
cout<<"i am friend of class A";
}
int main()
{
A obj;
// obj.sum();
// obj.sum(1,2,3);
// int a=obj.sum1();
// cout<<a;
// cout<<obj.sum1(4,5,89);
// B o;
//cout<<o.sub(40,5,12,3);
// c poth;
//poth.mul(2,3,4);
// D con;
E ajay;
f(obj);
return 0;
}