-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance_3.cpp
210 lines (203 loc) · 3.42 KB
/
inheritance_3.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
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
#include<iostream>
using namespace std;
class studentmarks
{
protected:
int reg_no;
int m1,m2,m3;
public:
studentmarks()
{
cout<<"\n default constructor for studentmarks class"<<endl;
reg_no=1;
m1=100;
m2=100;
m3=100;
}
studentmarks(int rg,int a,int b,int c)
{
cout<<"\n parameterized constructor for studentmarks class"<<endl;
reg_no=rg;
m1=a;
m2=b;
m3=c;
}
void get()
{
cout<<"enter reg no and marks for 3 sub"<<endl;
cin>>reg_no>>m1>>m2>>m3;
}
float avg()
{
float av;
cout<<"average is";
av=(m1+m2+m3)/3.0;
cout<<av<<endl;
return av;
}
};
class Result:public studentmarks
{
public:
Result()
{
cout<<"\n default constructor for Result class";
}
Result(int rg,int a,int b,int c):studentmarks(rg,a,b,c)
{
cout<<"\n parameterized constructor for Result class";
}
void result(int min)
{
if(m1>=min&&m2>=min&&m3>=min)
{
cout<<"\npass"<<endl;
}
else
{
cout<<"\nfail"<<endl;
}
}
void result(int min,int merit)
{
float a;
a = avg();
if(m1>=min&&m2>=min&&m3>=min)
{
if(a >= merit)
{
cout<<"\ngot scholorship"<<endl;
}
}
else
{
cout<<"\nnot eligible"<<endl;
}
}
};
class sports
{
protected :
float ms;
public:
float marks_s();
sports()
{
ms=100;
cout<<"\nSports class default constructor called";
}
sports(float x)
{
ms=x;
cout<<"\nsports class parameterized constructor called.";
}
void input_s()
{
cout<<"\nMarks in sports :";
cin>>ms;
}
};
float sports :: marks_s()
{
return ms;
}
class cultural
{
protected :
float mc;
public:
float marks_c();
cultural()
{
mc=100;
cout<<"\ncultural class default constructor called";
}
cultural(float y)
{
mc=y;
cout<<"\ncultural class parameterized constructor called.";
}
input_c()
{
cout<<"\nMarks in cultural :";
cin>>mc;
}
};
float cultural :: marks_c()
{
return mc;
}
class FinalResult : public Result , public sports , public cultural
{
public :
FinalResult()
{
cout<<"\ndefault constructor called for final result.";
}
FinalResult(int rg,int a,int b,int c,float s,float cl):Result(rg,a,b,c), sports(s), cultural(cl)
{
cout<<"\nparameterized constructor called for final result ";
}
float total_marks();
void cal_grade();
void cal_per();
};
float FinalResult :: total_marks()
{
float t,t1,t2;
input_s();
input_c();
t1=marks_s();
t2=marks_c();
t= m1+m2+m3+t1+t2;
return t;
}
void FinalResult :: cal_grade()
{
float g,t1,t2;
t1=marks_s();
t2=marks_c();
g=t1+t2;
if(g>=150)
cout<<"\nGRADE IS : A";
else if (g>=100&&g<=150)
cout<<"\nGRADE IS : B";
else if(g>=50 &&g<=100)
cout<<"\nGRADE IS : C";
else
cout<<"\nGRADE IS : D";
}
void FinalResult :: cal_per()
{
float p,percentage;
p=m1+m2+m3;
percentage=(p/300.0)*100.0;
cout<<"\npercentage is :"<<percentage;
if( percentage>=90)
cout<<"\nDIVISION IS : A";
else if (percentage>=75)
cout<<"\nDIVISION IS : B";
else if(percentage>=60)
cout<<"\nDIVISION IS : C";
else
cout<<"\nDIVISION IS : D";
}
int main()
{
int rg,a,b,c,min,merit;
float x,y;
cout<<"enter reg no and marks:";
cin>>rg>>a>>b>>c;
studentmarks obp(rg,a,b,c);
obp.avg();
cout<<"enter min and merit:";
cin>>min>>merit;
Result obpr(rg,a,b,c);
obpr.result(min);
obpr.result(min,merit);
FinalResult f1(rg,a,b,c,x,y);
cout<<"\nTotal marks in test, sports and culture = "<<f1.total_marks();
f1.cal_grade();
f1.cal_per();
return 0;
}