Please help me to correct the errors in this code and run it on
the program. Please if you are able to do it just because I need it
to work fully
Write C++ program to declare student status, the program should
have class 1 insert student name and age call by reference, class 2
should insert student status (success, fail) using static member
function and inherit class 1, class 3 should insert subject name
inherit class 1, and class 4 inherit class 2&3 and test if
student success of not and display all information (student name,
age, success or not, subject name).
Where:
If success=1 and fail=0 display success
If success=0 and fail=1 display fail
-------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
class Student {
public:
string name;
int age;
Student(string name, int age)
{
this->name = name;
this->age = age;
}
};
class Result : public Student {
public:
static int success;
static int fail;
Result(string name, int age) : Student(name, age)
{
}
};
int Result::success = 0;
int Result::fail = 0;
class Subject : public Student {
public:
string name;
Subject(string name, int age, string sub) : Student(name,
age)
{
this->name = sub;
}
};
class Display : public Result, public Subject {
public:
Display(string name, int age, string sub) : Student(name, age),
Result(name, age), Subject(name, age, sub)
{
}
void show()
{
cout << Name: << name << endl;
cout << Age: << age << endl;
if (success == 1 && fail == 0) {
cout << Result: Success << endl;
}
else if (success == 0 && fail == 1) {
cout << Result: Fail << endl;
}
cout << Subject: << name << endl;
}
};
int main()
{
Display d("James", 20, "History");
d.success = 1;
d.fail = 0;
d.show();
return 0;
Please help me to correct the errors in this code and run it on the program. Please if you are able to do it just becaus
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am