-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLA4.cpp
More file actions
82 lines (64 loc) · 1.6 KB
/
LA4.cpp
File metadata and controls
82 lines (64 loc) · 1.6 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
#include <iostream>
using namespace std;
class Person {
public:
string name;
int age;
void setPersonInfo(string n, int a) {
name = n;
age = a;
}
void displayPersonInfo() {
cout << "Name: " << name << ", Age: " << age << endl;
}
};
class Marks {
protected:
int subject1, subject2, subject3;
public:
void setMarks(int m1, int m2, int m3) {
subject1 = m1;
subject2 = m2;
subject3 = m3;
}
void displayMarks() {
cout << "Marks: Subject1 = " << subject1
<< ", Subject2 = " << subject2
<< ", Subject3 = " << subject3 << endl;
}
};
class Sports : public Person {
protected:
int sportsMarks;
public:
void setSportsMarks(int sm) {
sportsMarks = sm;
}
void displaySportsMarks() {
cout << "Sports Marks: " << sportsMarks << endl;
}
};
// Hybrid Inheritance
class Result : public Marks, public Sports {
public:
void displayResult() {
int totalMarks = subject1 + subject2 + subject3 + sportsMarks;
double percentage = totalMarks / 4.0;
displayPersonInfo();
displayMarks();
displaySportsMarks();
cout << "Total Marks: " << totalMarks << endl;
cout << "Percentage: " << percentage << "%" << endl;
}
};
int main() {
Result student;
// Set student information and marks
student.setPersonInfo("Vighnesh", 18);
student.setMarks(95, 94, 96);
student.setSportsMarks(80);
// Display the result analysis
cout << "Student Result Analysis:" << endl;
student.displayResult();
return 0;
}