zoukankan      html  css  js  c++  java
  • 自考新教材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;
    }

     运行结果:

  • 相关阅读:
    Windows下输入法全角符,半角符的切换
    hdu 2546 饭卡
    hdu 1712 ACboy needs your help
    hdu 3033 I love sneakers!
    hdu 1171 Big Event in HDU
    hdu 1114 Piggy-Bank
    HDU 1058 Humble Numbers
    hdu 1297
    hdu 2050
    hdu 2563
  • 原文地址:https://www.cnblogs.com/duanqibo/p/14057614.html
Copyright © 2011-2022 走看看