#include<iostream>
#include<string>
using namespace std;
class Book{
private:
string book;
string zuozhe;
string chubannianfen;
public:
Book(string b,string z ,string c)
{
book=b;
zuozhe=z;
chubannianfen=c;
}
void display()
{
cout<<book<<endl<<zuozhe<<endl<<chubannianfen<<endl;
}
};
class Student{
private:
string name ;
string id;
int age;
Book stu;
public:
Student(string b,string z,string c,string n,string i,int a):stu(b,z,c)//类的组合也和类的继承差不多
{
name=n;
age=a;
id=i;
}
void display1()
{
stu.display();//只写display(),不行
cout<<name<<endl<<id<<endl<<age<<endl;
}
};
int main()
{
Student s1("格林童话","安徒生","2009.10.21","王小明","12345567",18);
s1.display1();
return 0;
}
类的组合12345
最新推荐文章于 2024-08-17 08:45:02 发布