-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLA3.cpp
More file actions
86 lines (70 loc) · 1.94 KB
/
Copy pathLA3.cpp
File metadata and controls
86 lines (70 loc) · 1.94 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
#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 AcademicRecord {
public:
int marks1, marks2, marks3;
void setMarks(int m1, int m2, int m3) {
marks1 = m1;
marks2 = m2;
marks3 = m3;
}
int getTotalMarks() {
return marks1 + marks2 + marks3;
}
void displayMarks() {
cout << "Marks - Subject 1: " << marks1 << ", Subject 2: " << marks2 << ", Subject 3: " << marks3 << endl;
}
};
// Derived Class for Multiple Inheritance:
class Result : public Person, public AcademicRecord {
public:
void displayResult() {
int total = getTotalMarks();
double percentage = total / 3.0;
displayPersonInfo();
displayMarks();
cout << "Total Marks: " << total << ", Percentage: " << percentage << "%" << endl;
}
};
// Derived Class for Hierarchical Inheritance:
class SportsResult : public AcademicRecord {
private:
int sportsMarks;
public:
void setSportsMarks(int sm) {
sportsMarks = sm;
}
void displaySportsResult() {
int academicTotal = getTotalMarks();
int total = academicTotal + sportsMarks;
cout << "Sports Marks: " << sportsMarks << endl;
cout << "Total with Sports: " << total << endl;
}
};
int main() {
// Multiple Inheritance
Result studentResult;
studentResult.setPersonInfo("Vighnesh", 18);
studentResult.setMarks(98, 93, 96);
cout << "Academic Result Analysis:" << endl;
studentResult.displayResult();
// Hierarchical Inheritance
SportsResult sportsResult;
sportsResult.setMarks(98, 93, 96);
sportsResult.setSportsMarks(80);
cout << "\nSports Result Analysis:" << endl;
sportsResult.displaySportsResult();
return 0;
}