題目:
定義一個學生類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;
}```
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/271637.html
標籤:其他
上一篇:PAT甲級 1001 A+B Format (20 分) 全網最細 題目詳解 翻譯 完整代碼 PAT真題決議
下一篇:方舟JavaScript 引擎
