西加加:7-1 计算全班学生C++课程的总成绩和平均成绩

定义一个类Student,记录学生C++课程的成绩。要求使用静态数据成员或静态成员函数计算全班学生C++课程的总成绩和平均成绩。

输入格式:

输入5个不超过100的正整数,作为C++成绩。

输出格式:

在第一行中输出成绩的和,第二行输出平均成绩。

输入样例:

90 80 70 60 50

输出样例:

350
70

代码实现:

#include <iostream>
using namespace std;

class Student
{
	static int total_score;
	static float average;
	int score;
	public:
		void Setscore()
		{
			int x;
			cin >> x;
			score = x;
		}
		int add()
		{
			total_score += score;
			return total_score;
		}
		int aver()
		{
			average *= total_score/5;
		}
		void show()
		{
			cout << total_score << endl;
			cout << average << endl;
		}
};
int Student::total_score = 0;
float Student::average = 1;

int main()
{
	Student a[5];
	int i;
	for (i=0;i<5;i++)
	{
		a[i].Setscore();
		a[i].add();
	}
	a[i].aver();
	a[i].show();
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值