- #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(){
- cout<<"请输入长度:";
- cin>>length;
- return length;
- }
- int Rec::get_width(){
- cout<<"请输入宽度:";
- cin>>width;
- return width;
- }
- void Rec::show(){
- cout<<"周长:"<<(length+width)*2<
- cout<<"面积:"<
- }
-
- int main()
- {
- Rec a;
- a.set_length(a.get_length());
- a.set_width(a.get_width());
- a.show();
- return 0;
- }

圆类
- #include
-
- using namespace std;
- class circle
- {
- int r;
- // double PI=3.14;
- public:
- int set_r(int l);
- void show(int r,double PI=3.14);
- };
- int circle::set_r(int l){
- r=l;
- return r;
- }
- void circle::show(int r, double PI){
- cout<<"周长:"<<2*r*PI<
- cout<<"面积:"<
- }
- int main()
- {
- circle a;
- a.show(a.set_r(3));
- return 0;
- }

Car类
- #include
-
- using namespace std;
- class Car{
- private:
- string brand;
- string color;
- int speed;
- public:
- void display();
- void accelerate(int amount);
- void set(string brand,string color,int speed);
- };
- void Car::display(){
- cout<<"brand:"<
- cout<<"color:"<
- cout<<"speed:"<
- }
- void Car::accelerate(int amount){
- speed+=amount;
- }
- void Car::set(string brand, string color, int speed){
- Car::brand=brand;
- this->color=color;
- this->speed=speed;
- }
- int main()
- {
- Car car;
- car.set("geely","white",10);
- car.display();
- car.accelerate(10);
- car.display();
- return 0;
- }

-
相关阅读:
1-Maven-settings配置
五、 通信协议
车船边缘网关是如何给车辆船只定位的?
在pandas中使用query替代loc进行高效简洁的条件筛选
二叉树的遍历(非递归版)
玉米地里的小鸟
五、T100固定资产之固定资产盘点管理篇
CMake 基础学习
如何设置跨域隔离启用 SharedArrayBuffer
2022届秋招Java岗高频面试题盘点,老司机也未必全会,真的太卷了
-
原文地址:https://blog.csdn.net/weixin_44559978/article/details/138166878