21.03.31定义类实现学生管理

   日期:2021-04-02     浏览:94    评论:0    
核心提示:题目:定义一个学生类CStudent实现简单的学籍管理功能,要求该类至少实现以下功能:(1) 录入学生的基本信息(包括姓名,学号,性别,年龄,专业,入学时间,各门功课成`绩)(2) 定义Date类来定义学生入学时间(3) 定义Subject类表示学生三门功课成绩:数学,英语和C语言。统计学生每门功课总成绩和平均成绩。(4) main()函数中初始化5个学生基本信息(5) 输出学生的基本信息(6) 输出每门功课总成绩(7) 输出每门功课平均成绩解答:#include<iostre

题目:

定义一个学生类CStudent实现简单的学籍管理功能,要求该类至少实现以下功能:
(1) 录入学生的基本信息(包括姓名,学号,性别,年龄,专业,入学时间,各门功课成`绩)
(2) 定义Date类来定义学生入学时间
(3) 定义Subject类表示学生三门功课成绩:数学,英语和C语言。统计学生每门功课总成绩和平均成绩。
(4) main()函数中初始化5个学生基本信息
(5) 输出学生的基本信息
(6) 输出每门功课总成绩
(7) 输出每门功课平均成绩
解答:

#include<iostream>
using namespace std;
class Date { 
public:
	int year;
	int month;
	int day;
};
class Subject { 
public:
	double math;
	double english;
	double CProgram;
};
class CStudent{ 
private:
	string name;
	int studentID;
	string sex;
	int age;
	string major;
	Date enrollmentTime;
	Subject score;
	double scoreTotal;
	double scoreAverage;

public:
	static double number;
	static double mathTotal;
	static double englishTotal;
	static double CProgramTotal;
	CStudent(string n,
		int I,
		string s,
		int a,
		string m,
		int ye,int mo,int da,
		double mat,double eng,double CPr
		) { 
		name = n;
		studentID = I;
		sex = s;
		age = a;
		major = m;
		enrollmentTime.year = ye;
		enrollmentTime.month = mo;
		enrollmentTime.day = da;
		score.math = mat;
		score.english = eng;
		score.CProgram = CPr;
		scoreTotal = mat + eng + CPr;
		scoreAverage = scoreTotal / 3;
		number++;
		mathTotal += mat;
		englishTotal += eng;
		CProgramTotal += CPr;
	}
	void showStudent(void) { 
		cout << name << "\t"
			<< studentID << "\t"
			<< sex << "\t"
			<< age << "\t"
			<< major << "\t"
			<< enrollmentTime.year << "-" << enrollmentTime.month << "-" << enrollmentTime.day << "\t"
			<< score.math << "\t\t"
			<< score.english << "\t\t"
			<< score.CProgram << "\t\t"
			<< scoreTotal << "\t"
			<< scoreAverage << endl;
	}
};

double CStudent::number = 0;
double CStudent::mathTotal = 0;
double CStudent::englishTotal = 0;
double CStudent::CProgramTotal = 0;
int main(void)
{ 
	CStudent student1("张三", 01, "男", 18, "计算机", 2020, 9, 01, 100, 99, 98.1);
	CStudent student2("李四", 02, "男", 18, "信安", 2020, 9, 01, 97,96, 95);
	CStudent student3("王五", 03, "男", 18, "大数据", 2020, 9, 01, 94 ,93, 92);
	CStudent student4("赵六", 04, "男", 18, "物联网", 2020, 9, 01, 91, 90, 89);
	CStudent student5("赵小六", 05, "女", 18, "中加", 2020, 9, 01, 88, 87, 86);
	cout << "姓名\t" << "学号\t" << "性别\t" << "年龄\t" << "专业\t" << "入学时间\t" << "数学成绩\t" << "英语成绩\t" << "C语言成绩\t" << "总成绩\t" << "平均成绩\t" << endl;
	student1.showStudent();
	student2.showStudent();
	student3.showStudent();
	student4.showStudent();
	student5.showStudent();
	cout << endl;
	cout << "数学平均成绩:" << CStudent::mathTotal / CStudent::number << endl;
	cout << "英语平均成绩:" << CStudent::englishTotal / CStudent::number << endl;
	cout << "C语言平均成绩:" << CStudent::CProgramTotal / CStudent::number << endl;
	return 0;
}```

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
更多>相关资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服