
求圆半径和周长
- #include
- using namespace std;
-
- struct Cir
- {
- private:
- int r;
- public:
- void set_r(int i);
- void show();
- };
- void Cir::set_r(int i)//设置半径
- {
- r = i;
- }
- void Cir::show()//打印周长面积
- {
- double Pi = 3.14;
- double l = 2*Pi*r;
- double s = Pi*r*r;
- cout<< "周长=" << l << endl;
- cout<< "面积=" << s << endl;
- }
- int main()
- {
- Cir cir;
- int i;
- cin >> i;
- cir.set_r(i);
- cir.show();
- return 0;
- }

汽车
- #include
- using namespace std;
-
- struct Car
- {
- string brand;
- string color;
- int speed;
- void dispaly();
- void accelerate(int amount);
- void set(string a,string b,int c);
- };
-
- void Car::dispaly()
- {
- cout << "汽车信息如下:" << endl;
- cout << "品牌:" << brand <
- cout << "颜色:" << color <
- cout << "初速度:" << speed << "km/h" << endl;
- }
-
- void Car::accelerate(int amount)
- {
- speed += amount;
- }
-
- void Car::set(string a,string b,int c)
- {
- brand = a;
- color = b;
- speed = c;
- }
-
- int main()
- {
- Car car;
- string a,b;int c;
- cin >> a >> b >> c;
- car.set(a,b,c);
- car.dispaly();
- int amount;
- cout << "请输入加速值:";
- cin >> amount;
- car.accelerate(amount);
- car.dispaly();
-
- return 0;
- }

-
相关阅读:
4800计算器求直线、缓和曲线、圆曲线上任一里程中桩坐标及左右任意角度、任意距离的点的坐标的程序
【Unity | Editor强化工具】资产快速访问工具
基于springboot的支教系统-计算机毕业设计源码
电脑文件自动上传百度网盘,自动备份
问题 B: 邻接表存储的图转化为邻接矩阵存储的图-附加代码模式
linux minicom 调试串口
Java很简单的文件上传(transferTo方式)
C语言实现字符串的部分匹配算法
PAT 1035 插入与归并
css 占位隐藏
-
原文地址:https://blog.csdn.net/qq_45758377/article/details/138167046