c++ジョブ4

2347 ワード

プロジェクト1-竜三
#include <iostream>  
#include <string>  
using namespace std;  
class Person
{  
public:  
    Person(string s)
	{  
        name=s;  
    }  
    void display( )
	{  
        cout<<"Name: "<<name<<endl;  
    }  
private:  
    string name;  
};  
class Student: public Person//(1)  
{  
public:  
    Student(string s, int g):Person(s) // (2)    P169       
    {
		grade=g;
	}  
    void display1( ) 
	{  
        display( );   //(3)  
        cout<<"Grade: "<<grade<<endl;  
    }  
private:  
    int grade;  
};  
int main( )  
{  
    Student s("  ",19);  
    s.display1();       //  (4)  
    return 0;  
}  

プロジェクト2-学生クラス
#include<iostream>
#include<string>
using namespace std;
class Stu   //      
{  
public:  
    Stu(int n, string nam );  //        
    void display( );          //    ,          
protected:        //(*)               
    int num;      //      
    string name;  //      
};  
Stu::Stu(int n, string nam )
{
	num=n;
    name=nam;
}
void Stu::display()
{
	cout<<"  :"<<num<<endl;
	cout<<"  :"<<name<<endl;
}

class StuDetail: public Stu              //     StuDetail  
{  
public:  
    //  nam,  n,a ,  ad,     nam1,  n1  
    StuDetail(int n, string nam,int a, string ad,int n1, string nam1); //         
    void show( ); //    ,         
    void show_monitor( );    //    ,        
private:  
    Stu monitor;   //        ,     , Stu      
    int age;       //      
    string addr;   //       
};  
StuDetail::StuDetail(int n, string nam,int a, string ad,int n1, string nam1):Stu(n,nam),monitor(n1,nam1)
{
	age=a;
	addr=ad;
}
void StuDetail::show()
{
	display( );
	cout<<"  :"<<age<<endl;
	cout<<"  :"<<addr<<endl;
}
void StuDetail::show_monitor( )
{
	monitor.display();
}

int main( )  
{  
    //    ,10010 ,19 ,      ,       ,  10001  
    StuDetail s(10010,"  ",19,"    ",10001,"  ");  
    cout<<"    :"<<endl;
	s.show( );                       //      
	cout<<endl;
	cout<<"    :"<<endl;
    s.show_monitor();                //        
    return 0;  
}