• 自考新教材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;
    }

     运行结果:

  • 相关阅读:
    SpringBoot JdbcTemplate多数据源
    SpringBoot Mybatis多数据源
    SpringBoot 配置文件2
    SpringBoot 配置文件1
    SpringBoot 日志配置
    乌镇行
    防火墙
    PL/SQL查询结果窗口太小且显示不完全
    python 列表解析
    HTML
  • 原文地址:https://www.cnblogs.com/duanqibo/p/14057614.html
Copyright © 2020-2023  润新知