-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path18_inheritance-student.cpp
executable file
·103 lines (81 loc) · 1.37 KB
/
18_inheritance-student.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
#include <iostream>
#define TOTAL 300
using namespace std;
// person name age gender
class Person{
char name[20], gender;
int age;
protected:
void print_details();
void read_details();
};
// student m1 m2 m3 total grade
class Student: public Person{
int m1, m2, m3, total;
char get_grade(int);
void get_marks();
public:
void get();
void print();
};
int main(){
Student s1, s2;
s1.get();
s2.get();
s1.print();
s2.print();
cout<<endl;
return 0;
}
// Person
void Person::print_details(){
cout<<"\n\nName : "<<name;
cout<<"\nAge : "<<age;
cout<<"\nGender : "<<gender;
}
void Person::read_details(){
cout<<"Name : ";
cin>>name;
cout<<"Age : ";
cin>>age;
cout<<"Gender : ";
cin>>gender;
}
// Student
void Student::get_marks(){
cout<<"Enter marks :\nM1 :";
cin>>m1;
cout<<"M2 :";
cin>>m2;
cout<<"M3 :";
cin>>m3;
total = m1 + m2 + m3;
}
char Student::get_grade(int mark){
int per = ((float)mark/TOTAL)*100;
if(per > 90)
return 'O';
if(per > 80)
return 'A';
if(per > 70)
return 'B';
if(per > 60)
return 'C';
if(per > 50)
return 'D';
if(per > 40)
return 'E';
return 'F';
}
void Student::get(){
read_details();
get_marks();
}
void Student::print(){
print_details();
cout<<"\nMark 1 : "<<m1;
cout<<"\nMark 2 : "<<m2;
cout<<"\nMark 3 : "<<m3;
cout<<"\nTotal : "<<total;
cout<<"\nGrade : "<<get_grade(total);
}