自考新教材p124

#include <iostream>
using namespace std;
class CType
{
private:
int radius;
int width;
public:
CType():radius(16),width(185){};
CType(int r,int w):radius(r),width(w){};
int getRadius()
{
return radius;
}
int getWidth()
{
return width;
}
};

class CCar
{
private:
int price;
CType type;
public:
CCar();
CCar(int p,int tr,int tw);
int getPrice()
{
return price;
}
CType getCType()
{
return type;
}
};

CCar::CCar()
{
price=50010;
CType();
}
CCar::CCar(int p,int tr,int tw):price(p),type(tr,tw){};
int main()
{
CCar car(48900,17,225);
cout<<"price"<<car.getPrice();
cout<<" CType.Radius="<<car.getCType().getRadius()<<" CType.Width="<<car.getCType().getWidth()<<endl;
CCar car1;
cout<<"price"<<car1.getPrice();
cout<<" CType.Radius="<<car1.getCType().getRadius()
<<" CType.Width="<<car1.getCType().getWidth()<<endl;
return 1;
}

 运行结果:

原文地址:https://www.cnblogs.com/duanqibo/p/14057614.html