-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLA2.cpp
More file actions
69 lines (53 loc) · 1.3 KB
/
LA2.cpp
File metadata and controls
69 lines (53 loc) · 1.3 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
#include <iostream>
using namespace std;
class Person {
private:
string name;
int age;
public:
void setPersonInfo(string n, int a) {
name = n;
age = a;
}
void displayPersonInfo() {
cout << "Name: " << name << ", Age: " << age << endl;
}
};
// Single Inheritance
class Student : public Person {
private:
int marks1, marks2, marks3;
public:
void setMarks(int m1, int m2, int m3) {
marks1 = m1;
marks2 = m2;
marks3 = m3;
}
void displayMarks() {
cout << "Marks - Subject 1: " << marks1 << ", Subject 2: " << marks2 << ", Subject 3: " << marks3 << endl;
}
int getTotalMarks() {
return marks1 + marks2 + marks3;
}
};
// Multi-level Inheritance
class Result : public Student {
public:
void displayResult() {
int total = getTotalMarks();
float percentage = total / 3.0;
displayPersonInfo();
displayMarks();
cout << "Total Marks: " << total << ", Percentage: " << percentage << "%" << endl;
}
};
int main() {
Result student;
// Set student information and marks
student.setPersonInfo("Vighnesh", 18);
student.setMarks(95, 90, 97);
// Display result analysis
cout << "Result Analysis:" << endl;
student.displayResult();
return 0;
}