-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHybrid Inheritance.cpp
More file actions
213 lines (192 loc) · 4.96 KB
/
Hybrid Inheritance.cpp
File metadata and controls
213 lines (192 loc) · 4.96 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
#include<iostream>
using namespace std;
class student
{
public:
int rno;
char nam[100];
void getrno()
{
cout<<"Enter roll no: ";
cin>>rno;
}
void getnam()
{
cout<<"Enter student name: ";
cin>>nam;
}
void outputrno()
{
cout<<"Roll no: "<<rno;
}
void outputnam()
{
cout<<endl<<"Name: "<<nam<<endl;
}
};
class test : public student
{
protected:
float sub1,sub2,sub3; // private members can only be accessible in the same class
// protected members can be accessible in the same class in the class where the inherit from
public:
int i;
void inputmarks()
{
cout<<"Enter marks for sub1: ";
cin>>sub1;
for(i=1;i>=1;i++)
{
if(sub1>30){
cout<<"Wrong value inserted!!"<<endl<<"Enter values between 0 - 30"<<endl;
sub1=0;
break;
}
else {
cout<<endl<<"_______Values Accepted For Subject1________"<<endl;
break;
}
}
cout<<"Enter marks for sub2: ";
cin>>sub2;
for(i=1;i>=1;i++)
{
if(sub2>30)
{
cout<<"Wrong value inserted!!"<<endl<<"Enter values between 0 - 30"<<endl;
sub2=0;
break;
}
else {
cout<<endl<<"_______Values Accepted For Subject2________"<<endl;
break;
}
}
cout<<"Enter marks for sub3: ";
cin>>sub3;
for(i=1;i>=1;i++)
{
if(sub3>30)
{
cout<<"Wrong value inserted!!"<<endl<<"Enter values between 0 - 30"<<endl;
sub3=0;
break;
}
else {
cout<<endl<<"_______Values Accepted For Subject3________"<<endl;
break;
}
}
}
void outputmarks()
{
cout<<endl<<"Marks of subject 1: "<<sub1<<endl;
cout<<endl<<"Marks of subject 2: "<<sub2<<endl;
cout<<endl<<"Marks of subject 3: "<<sub3<<endl;
}
};
class sports
{
protected:
float score;
public:
int i=1;
void getsports()
{
cout<<endl<<"Enter sports score: ";
cin>>score;
for(i=1;i>=1;i++)
{
if(score>30){
cout<<"Wrong value inserted!!"<<endl<<"Enter values between 0 - 30"<<endl;
score=0;
break;
}
else {
cout<<endl<<"_______Values Accepted For Sports________"<<endl;
break;
}
}
}
void outputsprtsscore()
{
cout<<"Sports Score: "<<score<<endl;
}
};
class result: public test, public sports
{
float Total,percentage;
public:
void resultoutput()
{
Total= sub1 + sub2 + sub3 + score;
percentage=((sub1+sub2+sub3+score)/120)*100;
cout<<endl<<"----------------RESULTS------------------"<<endl;
if(sub1<=0)
{
cout<<"[Incorect input] or [U scored : 0] in - Subject1"<<endl;
}
else{
cout<<endl<<"Marks of subject 1: "<<sub1<<endl;
}
if(sub2<=0)
{
cout<<"[Incorect input] or [U scored : 0] in - Subject2"<<endl;
}
else{
cout<<endl<<"Marks of subject 2: "<<sub2<<endl;
}
if(sub3<=0)
{
cout<<"[Incorect input] or [U scored : 0] in - Subject3"<<endl;
}
else{
cout<<endl<<"Marks of subject 3: "<<sub3<<endl;
}
if(score<=0)
{
cout<<"[Incorect input] or [U scored : 0] in - Sports"<<endl;
}
else{
cout<<endl<<"Marks of sports : "<<score<<endl;
}
cout<<"Total score: "<<Total;
if(Total<=35)
{
cout<<endl<<" U Failed ";
cout<<"With Percentage score: "<<percentage<<"%"<<endl;
}
else if(Total<=55)
{
cout<<endl<<" Pass!!----->Average result ";
cout<<"With Percentage score: "<<percentage<<"%"<<endl;
}
else if(Total<=75)
{
cout<<endl<<" Pass!!----->Above average result ";
cout<<"With Percentage score: "<<percentage<<"%"<<endl;
}
else if(Total<=100)
{
cout<<endl<<" Pass!!----->Good Result ";
cout<<"With Percentage score: "<<percentage<<"%"<<endl;
}
else{
cout<<endl<<" Pass!!----->Awesome result ";
cout<<"With Percentage score: "<<percentage<<"%"<<endl;
}
}
};
int main()
{
result r;
r.getrno();
r.getnam();
r.outputrno();
r.outputnam();
r.inputmarks();
r.outputmarks();
r.getsports();
r.outputsprtsscore();
r.resultoutput();
}