-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviva_question.cpp
More file actions
91 lines (81 loc) · 2.04 KB
/
viva_question.cpp
File metadata and controls
91 lines (81 loc) · 2.04 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
87
88
89
90
91
/*Consider an example of declaring the exam result. Design three classes student ,exam,result
The student class has data members such as roll no,names,etc. Create a class exam by inheriting
the student class. The exam class should have data members representing marks scored in 6 subjects.
Derive class result from the exam class and it should have it's own data members such as total
marks. write an interactive program to model this relationship. Which type of inhertiance this
model belongs to ?*/
// Made by Abhinav Singh
// Date:- 14 December 2022.
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
string name;
int roll_no;
void getData()
{
cout << "Enter name: ";
cin >> name;
cout << "Enter your roll number:- ";
cin >> roll_no;
}
};
class Exam : public Student
{
public:
float ary[6];
void getMarks()
{
for (int i = 0; i < 6; i++)
{
Error:
cout << "Enter subject " << i + 1 << " marks : ";
cin >> ary[i];
if (ary[i] > 100)
{
cout << "Enter marks under 100 ! " << endl;
goto Error;
}
}
}
};
class Result : public Exam
{
public:
float total;
void getResult()
{
system("cls");
for (int i = 0; i < 6; i++)
{
total += ary[i];
}
cout << "Name: " << name << endl;
cout << "Roll no: " << roll_no << endl;
cout << "The total result is: " << total << "/600" << endl;
system("pause");
}
};
int main()
{
Menu:
system("cls");
Result r1;
r1.getData();
r1.getMarks();
r1.getResult();
system("cls");
cout << "This model belongs to Multilevel type of inheritance." << endl;
cout << "Do you want to repeat ?\n1.Yes\n2.No\n";
int choice;
cin >> choice;
switch (choice)
{
case 1:
goto Menu;
default:
break;
}
}