
求圆半径和周长
- #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;
- }

-
相关阅读:
【冰糖Python】TensorFlow 占位符 placeholder
Java线程安全问题
logstash安装zabbix插件报错解决
项目沟通和干系人管理
MySQL进阶04_索引_索引使用_索引设计原则
R语言教程课后习题答案(持续更新中~~)
C基础-数组
功率放大器的设计要点
Helm Chart 部署 Redis 的完美指南
基于ChatGPT的大型语言模型试用心得
-
原文地址:https://blog.csdn.net/qq_45758377/article/details/138167046