Problem Description
Every student in a school has to learn three public courses: Chinese, English and mathematics. Students majoring in accounting should study accounting and economics
Two professional courses. Students majoring in chemistry should study two professional courses: Organic Chemistry and chemical analysis.
(1) Write the ComFinal base class. The data members include: name (character array type), Chinese score, English score and math score.
Member functions include: constructor, destructor, function for calculating the total score of public courses, function for calculating the average score of public courses
Function to display name, Chinese score, English score, mathematics score, total score of public courses and average score of public courses
(2) Write an Account derived class. The data members include: Accounting scores and economics scores.
Member functions include: constructor, destructor, function for calculating the total score of professional courses, function for calculating the average score of professional courses
Display name, Chinese score, English score, math score, total score of public courses, average score of public courses
Function of accounting score, economics score, total score of professional courses and average score of professional courses
(3) Write a Chemistry derived class, and the data members include: scores in organic Chemistry and analytical Chemistry.
Member functions include: constructor, destructor, function for calculating the total score of professional courses, function for calculating the average score of professional courses
Display name, Chinese score, English score, math score, total score of public courses, average score of public courses
Organic chemistry score, analytical chemistry score, total score of professional courses and average score of professional courses.
Please complete the following procedure:
//Your code will be embedded here
int main(void)
{
Account s1("AAA", 90, 86, 80, 93, 91);
s1.Display();
Chemistry s2("BBB", 92, 78, 98, 90, 67);
s2.Display();
return 0;
}
Input Description
nothing
Output Description
Output all student information
Sample Output
Name: AAA
Language: 90
English: 86
Mathematics: 80
Total score of public courses: 256
Average score of public courses: 85
Accounting: 93
Economics: 91
Total score of professional courses: 184
Average score of professional courses: 92
Name: BBB
Language: 92
English: 78
Mathematics: 98
Total score of public courses: 268
Average score of public courses: 89
Organic chemistry: 90
Chemical analysis: 67
Total score of professional courses: 157
Average score of professional courses: 78
#include <iostream> using namespace std; #include <string> //The base class should be placed before the derived class //Base class class ComFinal { private: string m_name; int Cscore; int Escore; int Mscore; public: //Constructor ComFinal(string n, int a, int b, int c)//Parameterized constructor { m_name = n; Cscore = a; Escore = b; Mscore = c; } //Destructor ~ComFinal() {} void Display() { cout << "full name:" << m_name << endl; cout << "chinese:" << Cscore << endl; cout << "English:" << Escore << endl; cout << "mathematics:" << Mscore << endl; //Cout < < total score of public courses: < < Cscore + eSCORE + mscore < < endl; //Cout < < average score of public courses: "< (Cscore + eSCORE + mscore) / 3 < < endl; sumscore(); average(); } void sumscore() { cout << "Total score of public courses:" <<Cscore + Escore + Mscore << endl; } void average() { cout << "Average score of public courses:" <<( Cscore + Escore + Mscore) / 3 << endl; } }; class Account :public ComFinal //Derived class: inheritance mode base class { private: int kuaijiscore; int jingjiscore; public: Account(string a, int b, int c, int d, int e, int f) :ComFinal(a, b, c, d) { kuaijiscore = e; jingjiscore = f; } void Display() { ComFinal::Display(); //Functions under ComFinal scope cout << "Accounting:" << kuaijiscore << endl; cout << "economics:" << jingjiscore << endl; cout << "Total score of professional courses:" << kuaijiscore + jingjiscore << endl; cout << "Average score of professional courses:" << (kuaijiscore + jingjiscore) / 2 << endl; } ~Account() {} }; class Chemistry :public ComFinal { private: int youjiscore; int fenxiscore; public: Chemistry(string a, int b, int c, int d, int e, int f) :ComFinal(a, b, c, d) { youjiscore = e; fenxiscore = f; } ~Chemistry() {} void Display() { ComFinal::Display();//Functions under ComFinal scope cout << "Organic chemistry:" << youjiscore << endl; cout << "Chemical analysis:" << fenxiscore << endl; cout << "Total score of professional courses:" << youjiscore + fenxiscore << endl; cout << "Average score of professional courses:" << (youjiscore + fenxiscore) / 2 << endl; } }; int main(void) { Account s1("AAA", 90, 86, 80, 93, 91); s1.Display(); Chemistry s2("BBB", 92, 78, 98, 90, 67); s2.Display(); return 0; }