(継承)Problem C:家庭教師コース

5921 ワード

Problem C:家庭教師レッスン
Description
先生は貧乏人ばかりなので、よく外でアルバイトをしなければなりません.しかし、授業以外は何もできませんね.だから家庭教師をするしかない.今はオブジェクト向けのアイデアを利用してこのようなシステムを設計してください.次のクラスがあります.
  • Personクラス:stringタイプのプロパティがあり、オブジェクトの名前を示します.StudentとTeacherの親です.
  • Studioクラス:Personクラスのサブクラスで、intタイプの属性を持ち、オブジェクトのシーケンス番号を示す.
  • Teacherクラス:Personクラスのサブクラスで、stringタイプの属性を持ち、オブジェクトの職名を示す.
  • Courseクラス:Teacherクラスのオブジェクトが1つ、Studentタイプのオブジェクトが1つ、stringタイプのプロパティ(オブジェクト名を示す)が1つの組合せクラスです.

  • 上記のクラスのコンストラクション関数とコンストラクション関数を定義し、関数に対応する文字列を出力してください.具体的なフォーマットはサンプル出力を参照してください.
    Input
    5行を入力し、最初の4文字列は、先生の名前、学生の名前、先生の職名、授業の名前の4文字列です.最後の行は整数で、学生のシーケンス番号を表します.
    Output
    例を見て~
    Sample Input
    Tom Jack Prof C++ 10
    Sample Output
    Person Tom is created. Person Jack is created. Person Tom is created. Teacher Tom with position Prof is created. Person Jack is created. Student Jack with id 10 is created. Person Jack is created. Teacher Jack with position Prof is created. Person Jack is created. Student Jack with id 10 is created. Course C++ is created. Course C++ is erased. Student Jack with id 10 is erased. Person Jack is erased. Teacher Jack with position Prof is erased. Person Jack is erased. Student Jack with id 10 is erased. Person Jack is erased. Teacher Tom with position Prof is erased. Person Tom is erased. Person Jack is erased. Person Tom is erased.
    HINT
    注意main関数に基づいて、各構造関数の各パラメータの意味を分析します.
    Append Code
    int main()
    {
        string s1, s2, s3, s4;
        int i;
        cin>>s1>>s2>>s3>>s4>>i;
        Person person1(s1), person2(s2);
        Teacher teacher(s1, s3);
        Student student(s2, i);
        Course course(s1, s2, s3, s4, i);
        return 0;
    }
    
    #include 
    #include 
    using namespace std;
    
    class Person
    {
    public:
        Person(string n)
        {
            name=n;
            cout <<"Person "<" is created."<"Person "<" is erased." << endl;
        }
        string name_(){return name;}
    private:
        string name;
    };
    
    class Student:public Person
    {
    public:
        Student(string b,int c):cnt(c),Person(b)
        {
            cout <<"Student "<" with id "<" is created."<< endl;
        }
        ~Student()
        {
              cout <<"Student "<" with id "<" is erased." << endl;
        }
    private:
        int cnt;
    };
    
    class Teacher:public Person
    {
    public:
        Teacher(string b,string c) : Person(b), zc(c)
        {
            cout <<"Teacher "<" with position "<" is created."<< endl;
        }
        ~Teacher()
        {
              cout <<"Teacher "<" with position "<" is erased." << endl;
        }
    private:
        string zc;
    };
    
    class Course:public Teacher,public Student
    {
    public:
        Course(string n1,string n2,string pos,string n3,int id):Teacher(n2,pos),Student(n2,id)
        {
            Nm=n3;
            cout <<"Course "<" is created."<"Course "<" is erased." << endl;
        }
    private:
        string Nm;
    };
    
    
    
    int main()
    {
        string s1, s2, s3, s4;
        int i;
        cin>>s1>>s2>>s3>>s4>>i;
        Person person1(s1), person2(s2);
        Teacher teacher(s1, s3);
        Student student(s2, i);
        Course course(s1, s2, s3, s4, i);
        return 0;
    }