-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathques16-2.cpp
68 lines (63 loc) · 1.62 KB
/
ques16-2.cpp
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
/*Create a class marks and student. Initialize marks of three subjects in marks class using constructor and initialize roll number, student name and course name in student class. The member functions of marks class is total which returns sum of all subjects and also define member functions of student calss that is get_rollno, get_name and get_course. They return rollno,, name, and course of the student. Derive a result class ftom marks and student using cnstructor of result initialize marks and student data. Also define display function that shows rollno, name, coutse and total marks of the student*/
#include <iostream>
#include <string>
using namespace std;
class Marks
{
int* marks;
int totalMarks;
public:
Marks()
{
marks = new int[3];
for (int i = 0; i < 3; ++i)
{
cout << "Enter Marks of subject " << i+1 << endl;
cin >> marks[i];
}
}
int total()
{
totalMarks = 0;
for (int i = 0; i < 3; ++i)
{
totalMarks += marks[0];
}
return totalMarks;
}
~Marks()
{
delete[] marks;
}
};
class Student
{
string name;
int roll;
string course;
public:
Student(string n, string s, int r) : name(n), course(s), roll(r){}
void display()
{
cout << "Name: " << name << endl;
cout << "Section: " << course << endl;
cout << "Roll No: " << roll << endl;
}
string get_name(){return name;}
string get_course(){return course;}
int get_rollno(){return roll;}
~Student(){};
};
class Result : public Marks, public Student
{
public:
Result(string n, string s, int r):Student(n,s,r),Marks(){}
~Result(){}
};
int main()
{
Result r("Saurabh Thakur", "OOP",16101783);
r.display();
cout << r.total();
return 0;
}