題目:ios
按照下圖的類層次要求編寫程序。定義屬於類score的對象c1及類teacher的對象t1,分別輸入各數據成員的值後顯示出這些數據。ide
源代碼:學習
//科目:C++實驗5<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
//題目:定義屬於類score的對象c1及類teacher的對象t1
//做者:武葉
//語言:C++
//創做時間:2012年4月14日
#include<iostream>
#include<string>
using namespace std;
class person{
public:
person(string name1,string id1)
{
name=name1;
id=id1;
}
void print()
{
cout<<"姓名:"<<name<<endl;
cout <<"×××:"<<id<<endl;
}
public:
string name ;
string id;
};
class teacher: public person{
public:
teacher(string degree1,string dep1,string name1,string id1):person(name1,id1)
{
degree=degree1;
dep=dep1;
}
void print1()
{
print();
cout<<"學位:"<<degree<<endl;
cout<<"部門:"<<dep<<endl;
}
public:
string degree;
string dep;
};
class student: public person{
public:
student(int number1,int age1,string name1,string id1):person(name1,id1)
{
number =number1;
age=age1;
}
void print2()
{
print();
cout<<"年齡:"<<age<<endl;
cout<<"學號:"<<number<<endl;
}
protected:
int number;
int age;
};
class stu{
public:
string addr ;
string tel;
public:
stu(string addr1,string tel1)
{
addr=addr1;
tel=tel1;
}
void print3()
{
cout <<"地址:"<<addr<<endl;
cout<<"電話:"<<tel<<endl;
}
};
class score:public student,public stu{
public:
score(int math1,int eng1,string addr1,string tel1,int number1,int age1,string name1,string id1):stu(addr1,tel1),student( number1, age1,name1,id1)
{
math=math1;
eng=eng1;
}
void print4()
{
print2();
print3();
cout<<"數學成績:"<<math<<endl;
cout <<"英語成績:"<<eng<<endl;
}
public:
int math;
int eng;
};
int main()
{
score c1(89,94,"四川省雅安市雨城區新康路46號","15284522476",20095789,21,"武葉","625014");
c1.print4();
teacher t1("學者","工學院","蔣健","15283764098");
t1.print1();
return 0;
}url
更多詳細內容::::去學習spa