C++关于学生成绩管理方面的程序

#include<iostream>
using namespace std;
#include<cmath>
#include<cstring>
#include<cstdlib>

int main()
{
	Student std1;
	std1.set_data(1, "xiaoming");
	std1.inputdata();
	std1.show();
	getchar();
	getchar();

	return 0;
}

class Student
{
private:
	int no; //学生学号
	char name[20]; //学生姓名
	double score[3]; //课程成绩
	double average();
	double sum();
public:
	void set_data(int n, char *p);
	void inputdata();
	void show();
};

void Student::set_data(int n, char *p)
{
	no = n;
	strcpy(name, p);
}

void Student::inputdata()
{
	int i;

	cout << "please input score of " << name << ": " << endl;
	for (i = 0; i < 3;i++)
	{
		cin >> score[i];
	}
}

double Student::sum()
{
	return score[0] + score[1] + score[2];
}

double Student::average()
{
	return sum() / 3;
}

void Student::show()
{
	cout << "No.: " << no << ", Name: " << name << endl;
	cout << "Score: " << score[0] << ", " << score[1] << ", " << score[2] << endl;
	cout << "average: " << average() << '\t' << "Sum: " << sum() << endl << endl;
}
直接上程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值