21.03.31定义类实现学生管理

题目:

定义一个学生类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;
}```

猜你喜欢

转载自blog.csdn.net/MailWithoutName/article/details/115359485