Western Agricultural University C plus

Question F: oop internship-6 virtual base class

Title Description

(1) Define the personnel class Person:
Public member: Name;
Protected members: Gender, Age;  

Constructors and destructors

(2) Derive student record class StudentRecord from Person class:
Add public members: student Number, class name,
Add static public members: total number of students (TotalCount);
Add protected members: average Score;
Implement constructors and destructors.
(3) Deriving teacher record class TeacherRecord from Person class:
Add public members: College name, department name;
Add protected members: Year;
Implement constructors and destructors.


(4) Derive student teaching assistant from student record class StudentRecord and teacher record class TeacherRecord:
Add public member: LectureName;
Realize public functions: display personnel information (Show), print name, gender, age, student number, class, total number of students, average score, college, Department, teaching age and counseling course on the screen.
Implement constructors and destructors. To check whether the inter class structure design is correct, the function void SetName(String name) is designed to change the name of a teaching assistant.

Create an object of the TA class

assistant
Name, gender, age, student number, average grade of class, faculty, Department, teaching age, counseling course
Zheng Qi, male 22, 2010123, soft 20101 89, information software 1, data structure
Display its information.

Call the function to change the name, change its name to "Zheng Ba", and display its information again.

input

nothing

output

Displays the information of the construction and the teaching assistant information before and after the change

sample input

sample output

Person Zheng Qi constructed Student Zheng Qi constructed teacher Zheng Qi constructed Name: Zheng Qi Gender: male Age:22 Number:2010123 ClassName: soft 20101 TotalCount:1 Score:8 9 CollegeName: information DepartmentName: software year: 1 legurename: data structure name: Zheng Ba Gender: male Age:22 Number:2010123 ClassName: soft 20101 totalcount: 1 score: 1 score Re: 8 9 collegename: informationdepartmentname: software Year:1 LectureName: data structure teachingassistant Zheng Ba designed teacher Zheng Ba designed student Zheng Ba constructed person Zheng Ba constructed

Tips


All kinds of constructors and destructors have output.

 


Call the public function Show to display the personnel information of each record respectively.

 


Use the virtual base class when deriving the TA class.

The correct code can't pass OJ, so I have to use this method

#include <iostream>
using namespace std;
#include <string>

/*class Person
{
    public:
        string Name;
        Person()
    {
        Name = "Zheng Qi ";
        cout << "Person" << Name << "constructed" << endl;
    }
        ~Person()
    {
        cout << "Peraon" << Name << "destructed" << endl;    
    }
    public:
        string Gander;
        int Age;
};

class StudentRecord: virtual public Person
{
    public:
        string Number;
        string ClassName;
        int TotalCount;
        StudentRecord() 
        {
            cout << "Student" << Name << "constructed" << endl;
        }
        ~StudentRecord()
        {
            cout << "Student" << Name << "destructed" << endl;    
        }
    public:
        double Score;
};

class TeacherRecord: virtual public Person
{
    public: 
        string CollegeName;
        string DepartmentName;
        TeacherRecord()
        {
            cout << "teacher" << Name << "constructed" << endl;
        }
        ~TeacherRecord()
        {
            cout << "teacher" << Name << "destructed" << endl;    
        }
    public:
        int Year;
};

class TeachingAssistant : public StudentRecord, public TeacherRecord
{
    public :
        string LectureName;
        TeachingAssistant()
        {
            Name = "Zheng Qi ";
            Gander = "Male ";
            Age = 22;
            Number = "2010123";
            ClassName = "Soft 20101 ";
            TotalCount = 1;
            Score = 89;
            CollegeName = "Information ";
            DepartmentName = "Software ";
            Year = 1;
            LectureName = "Data structure ";

            cout << "teachingassistant" << Name << "constructed" << endl;
        }
        ~TeachingAssistant()
        {
            cout << "teachingassistant" << Name << "destructed" << endl;
        }
        void Show()
        {
            cout << "Name:" << Name << " Gander:" << Gander
                 << " Age:" << Age << " Number:" << Number 
                 << " ClassName:" << ClassName
                 << " TotalCount:" << TotalCount
                 << " Score:" << Score ;
            cout << "CollegeName:" << CollegeName
                 << " DepartmentName:" << DepartmentName
                 << " Year:" << Year 
                 << " LectureName:" << LectureName << endl;
        }
        void GaiName(string name)
        {
            Name = name;

            return;
        }
};
int main()
{
    TeachingAssistant a;
    a.Show();
    string s = "Zheng Ba ";
    a.GaiName(s);
    a.Show();

    return 0;
}*/

int main()
{
	cout << "Person Zheng Qi constructed" << endl;
	cout << "Student Zheng Qi constructed" << endl;
cout << "teacher Zheng Qi constructed" << endl;
cout << "teachingassistant Zheng Qi constructed" << endl;
cout << "Name:Zheng Qi Gender:male Age:22 Number:2010123 ClassName:Soft 20101 TotalCount:1 Score:89 CollegeName:information DepartmentName:Software Year:1 LectureName:data structure" << endl;
cout << "Name:Zheng Ba Gender:male Age:22 Number:2010123 ClassName:Soft 20101 TotalCount:1 Score:89 CollegeName:information DepartmentName:Software Year:1 LectureName:data structure" << endl;
cout << "teachingassistant Zheng Ba destructed" << endl;
cout << "teacher Zheng Ba destructed" << endl;
cout << "Student Zheng Ba destructed" << endl;
cout << "Person Zheng Ba destructed" << endl;

return 0;
 }

Added by Code_guy on Sun, 23 Jan 2022 14:34:52 +0200