实验三、类与对象定义初始化 一、有一圆形游泳要在周围建圆形过道四周围上栅栏, 二、有三个学生组队参加某比赛,每个学生信息包含准考证号,姓名,个人成绩,团队成绩

该博客包含两个部分:一是计算圆形游泳池周围3米宽过道和栅栏的总造价,其中过道每平方米20元,栅栏每米35元;二是描述了包含准考证号、姓名、个人成绩和团队成绩的学生信息,通过输入实现学生信息的设置和团队成绩的计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
* 实验三、类与对象定义初始化
* 1、有一圆形游泳池,现在需要在其周围建一圆形过道,并在其四周围上栅栏,
* 栅栏造价35元/米,过道造价为20元/平方米,求过道和栅栏的造价
* 2、有三个学生组队参加某比赛,每个学生信息包含准考证号,姓名,个人成绩,团队成绩

*/

 

 

/*
* 一游泳池需要围栅栏, 铺过道,
* 过道每平米价格 20
* 栅栏每米价格 35
* 过道宽度为 3
* 求建设 栅栏 过道 的总价分别是多少?
*/
#include <iostream>
#define PI 3.1415926
#define eachSqmPrice 20
#define eachMiterPrice 35
#define wide 3
using namespace std;
class swimminPool {
public:
	double r;
public:
	double totalPriceOfRoad(double r) {
		double area = PI * (r + wide) * (r + wide) - PI * r * r;
		double totalMoney = area * eachSqmPrice;
		return totalMoney;
	}
public:
	double totalPriceOfBarrier(double r) {
		double length = 2 * PI * r + 2 * PI * (r + 3);
		double totalMoney = length * eachMiterPrice;
		return totalMoney;
	}
};
int main() {
	swimminPool swimmingpool;
	cout << "请输入游泳池的半径r:" << endl;
	int r;
	cin >> r;
	double priceOfArea = swimmingpool.totalPriceOfRoad(r);
	double priceOfLenght = swimmingpool.totalPriceOfBarrier(r);
	cout << "过道总价为:" << priceOfArea << endl << "栅栏总价为:" << priceOfLenght << endl;
	return 0;
}

 

/*
* 实验三、类与对象定义初始化
* 1、有一圆形游泳池,现在需要在其周围建一圆形过道,并在其四周围上栅栏,
* 栅栏造价35元/米,过道造价为20元/平方米,求过道和栅栏的造价
* 2、有三个学生组队参加某比赛,每个学生信息包含准考证号,姓名,个人成绩,团队成绩
* 
*/
#include <iostream>
#include <cstring>
using namespace std;

class Student {
private:
	string number;
	string name;

public:
	double score = 0;
	double totalscore = 0;

public:

	void setName(string Name) {
		name = Name;
	}

	string getName() {
		return name;
	}

	void setNumber(string Number) {
		number = Number;
	}

	string getNumber() {
		return number;
	}

	/*double totalScore(double score1, double score2, double score3) {
		double totalscore = score1 + score2 + score3;
		return totalscore;
	}*/
};


int main() {
	Student student1;
	Student student2;
	Student student3;
	/*cout << "请输入学生准考证号和姓名:" << endl;
	string number1;
	string name1;
	cin >> number1;
	cin >> name1;
	student1.setNumber(number1);
	student1.setName(name1);
	cout << "准考证为:" << student1.getNumber() << " 的学生姓名为:" << student1.getName() << endl;*/


	/*for (int i = 1; i <= 3; i++) {
		cout << "请输入学生 " << i << " 准考证号和姓名:" << endl;
		string number1;
		string name1;
		cin >> number1;
		cin >> name1;
		student1.setNumber(number1);
		student1.setName(name1);
		cout << "请输入学生 " << i << " 的分数:" << endl;
		int score1;
		cin >> score1;
		student1.score = score1;
		cout << "准考证为:" << student1.getNumber() << " 的学生姓名为:" << student1.getName() << " 分数为:" << score1 << endl;
	}*/
	cout << "请输入 学生1 的准考证号:" << endl;
	string number1;
	cin >> number1;
	cout << "请输入 学生1 的姓名:" << endl;
	string name1;
	cin >> name1;
	student1.setNumber(number1);
	student1.setName(name1);
	cout << "请输入 学生1 的分数:" << endl;
	int score1;
	cin >> score1;
	student1.score = score1;
	cout << "准考证号为:" << student1.getNumber() << " 的学生姓名为:" << student1.getName() << " 分数为:" << student1.score << endl << endl;

	
	cout << "请输入 学生2 的准考证号:" << endl;
	string number2;
	cin >> number2;
	cout << "请输入 学生2 的姓名:" << endl;
	string name2;
	cin >> name2;
	student2.setNumber(number2);
	student2.setName(name2);
	cout << "请输入 学生2 的分数:" << endl;
	int score2;
	cin >> score2;
	student2.score = score2;
	cout << "准考证号为:" << student2.getNumber() << " 的学生姓名为:" << student2.getName() << " 分数为:" << student2.score << endl << endl;

	
	cout << "请输入 学生3 的准考证号:" << endl;
	string number3;
	cin >> number3;
	cout << "请输入 学生3 的姓名:" << endl;
	string name3;
	cin >> name3;
	student3.setNumber(number3);
	student3.setName(name3);
	cout << "请输入 学生3 的分数:" << endl;
	double score3;
	cin >> score3;
	student3.score = score3;
	cout << "准考证号为:" << student3.getNumber() << " 的学生姓名为:" << student3.getName() << " 分数为:" << student3.score << endl << endl;

	cout << "团队成绩为:" << endl;
	double totalscore = student1.score + student2.score + student3.score;
	cout << totalscore << endl;

	return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值