-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog11.cpp
More file actions
60 lines (49 loc) · 1.07 KB
/
prog11.cpp
File metadata and controls
60 lines (49 loc) · 1.07 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
/*
Write a C++ Program to read and print student information using single
inheritance concept
*/
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
class BasicInfo {
private:
string name, usn;
int age;
char gender;
public:
void setInfo() {
cout << "Enter name, usn, age and gender" << endl;
cin >> name >> usn >> age >> gender;
}
void getInfo() {
cout << "Student Info" << endl;
cout << "\tName: " << name << endl;
cout << "\tUSN: " << usn << endl;
cout << "\tAge: " << age << endl;
cout << "\tGender: " << gender << endl;
}
};
class ResultInfo : public BasicInfo {
private:
int totalMarks;
float percentage;
public:
void setMarks() {
cout << "Enter marks: ";
cin >> totalMarks;
percentage = totalMarks / 3.00;
}
void getMarksAndResult() {
cout << "\tMarks: " << totalMarks << endl;
cout << "\tPercentage: " << setprecision(4) << percentage << "%" << endl;
}
};
int main() {
ResultInfo s1;
s1.setInfo();
s1.getInfo();
s1.setMarks();
s1.getMarksAndResult();
return 0;
}