
- #include
- using namespace std;
- class Rec
- {
- int length;
- int width;
- public:
- void set_length(int l); //设置长度
- void set_width(int w); //设置宽度
- int get_length(); //获取长度
- int get_width(); //获取宽度
- void show(); //输出周长和面积
- };
- void Rec::set_length(int l)
- {
- length=l;
- }
- void Rec::set_width(int w)
- {
- width=w;
- }
- int Rec::get_length()
- {
- return length;
- }
- int Rec::get_width()
- {
- return width;
- }
- void Rec::show()
- {
- cout << "周长=" << get_length()+get_width() <
- cout << "面积=" << get_length()*get_width() <
- }
- int main()
- {
- Rec p;
- p.set_length(6);
- p.set_width(5);
- p.show();
- return 0;
- }

- #include
- using namespace std;
- class Yuan
- { double PI=3.14;
- int r;
- public:
- void set_r(int sum); //设置半径
- void show(); //输出周长和面积
- };
- void Yuan::set_r(int sum)
- {
- r=sum;
- }
- void Yuan::show()
- {
- cout << "周长=" << 2*PI*r << endl;
- cout << "面积=" << PI*r*r <
- }
- int main()
- {
- Yuan p;
- p.set_r(5);
- p.show();
- return 0;
- }

- #include
- using namespace std;
- class Car
- {
- string brand;
- string color;
- int speed;
- public:
- void display();
- void accelerate(int amount);
- void set (string b,string c,int s);
- };
- void Car::display()
- {
- cout << "品牌:" << brand <
- cout << "颜色:" << color <
- cout << "速度:" << speed <
- }
- void Car::accelerate(int amount)
- {
- speed=speed+amount;
- }
- void Car::set(string b, string c, int s)
- {
- brand=b;
- color=c;
- speed=s;
- }
- int main()
- {
- Car p;
- p.set("Volvo","black",100);
- p.display();
- p.accelerate(20);
- p.display();
- return 0;
- }


-
相关阅读:
2023下半年北京软考高项-系统架构设计师-考试心得分享
2022年Vue.js面试题汇总及答案【建议收藏】
Day774.能向 Redis 学到什么 -Redis 核心技术与实战
4.1_5 文件存储空间管理
元宇宙:区块链成熟的开始
cuda编程学习——运行错误检测(四)
C++11:异常和智能指针
营丘福稻品牌山东大米 国稻种芯·中国水稻节:淄博高青招牌
DSPE-PEG2K-MAL|磷脂聚乙二醇马来酰亚胺(DSPE-PEG-MAL)|二硬脂酰基磷脂酰乙醇胺 聚乙二醇 马来酰亚胺,齐岳生物
网站APP信息以及用户数据泄露排查方案
-
原文地址:https://blog.csdn.net/Y571428/article/details/138166289