Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Person
- {
- string name;
- int age;
- public:
- Person(string name, int age)
- {
- this->name = name;
- this->age = age;
- cout << "Constructor: Person Parameter\n";
- }
- void show()
- {
- cout << "Name: " << name << endl;
- cout << "Age: " << age << endl;
- }
- ~Person()
- {
- cout << "Destructing... Person: " << name << endl;
- }
- };
- class Result
- {
- int theory;
- int seasonal;
- public:
- Result() { cout << "Constructor: Result Default\n"; }
- Result(int theory, int seasonal)
- {
- this->theory = theory;
- this->seasonal = seasonal;
- cout << "Constructor: Result Parameter\n";
- }
- void setMarks(int theory, int seasonal)
- {
- this->theory = theory;
- this->seasonal = seasonal;
- }
- void getResult()
- {
- cout << "Theory: " << theory << endl;
- cout << "Seasonal: " << seasonal << endl;
- }
- ~Result()
- {
- cout << "Destructing... Result" << endl;
- }
- };
- class Student : private Result, public Person
- {
- int id;
- public:
- Student(string name, int age, int id, int theory, int seasonal) : Person(name, age)
- {
- this->id = id;
- setMarks(theory, seasonal); ///This is delegate function
- cout << "Constructor: Student Parameter\n";
- }
- void show()
- {
- Person::show();
- cout << "Id: " << id << endl;
- getResult();
- }
- ~Student()
- {
- cout << "Destructing... student: " << id << endl;
- }
- };
- class weakStudent : public Student
- {
- int logs;
- public:
- weakStudent(string name, int age, int id, int theory, int seasonal, int logs) : Student(name, age, id, theory, seasonal)
- {
- this->logs = logs;
- cout << "Constructor: weakStudent Parameter\n";
- }
- void show()
- {
- Student::show();
- cout << "Logs: " << logs << endl;
- cout << "This is a weak student\n";
- }
- ~weakStudent()
- {
- cout << "Destructing... weakstudent: " << logs << endl;
- }
- };
- class brilliantStudent : public Student
- {
- double cgpa;
- public:
- brilliantStudent(string name, int age, int id, int theory, int seasonal, double cgpa) : Student(name, age, id, theory, seasonal)
- {
- this->cgpa = cgpa;
- cout << "Constructor: brilliantStudent Parameter\n";
- }
- void show()
- {
- Student::show();
- cout << "CGPA: " << cgpa << endl;
- cout << "This is a brilliant student\n";
- }
- ~brilliantStudent()
- {
- cout << "Destructing... brilliantstudent: " << cgpa << endl;
- }
- };
- int main()
- {
- weakStudent st("Tamim", 20 , 28, 50, 75, 10);
- st.show();
- brilliantStudent st2("RJ", 20 , 39, 300, 299, 3.99);
- st2.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement