學生資訊系統中要求建一個學生類,學生類包括姓名、學號、年齡、數學成績、英語成績、總分6個資料成員及一些函式成員。主函式中通過鍵盤獲取3個學生的姓名、學號、年齡、數學成績、英語成績,通過設定學生資訊成員函式能夠設定學生的姓名、學號、年齡、數學成績、英語成績;在計算總分成員函式中計算學生總分,并在輸出成員函式中顯示學生的姓名、學號、年齡、數學成績、英語成績、總分。部分代碼如下請將此程式補充完整。運行效果如下圖所示:

#include <iostream>
#include <iomanip>
#include<string.h>
using namespace std;
class CStudent{
private :
char Name[21] ;
int Num ;
int Age ;
float MathS;
float EngS;
float TotalS;
public :
void SetInfo(char *na,int num,int age,float math,float eng);
void TotalScore( ) ; //計算學生總成績
void OutPut( ) //輸出學生資訊
{
cout<<setw(12)<<Name;
…
cout<<endl;
}
};
void CStudent::SetInfo(char *na,int num,int age,float math,float eng)
{
…
EngS=eng;
}
void CStudent::TotalScore()
{
…
}
int main()
{
CStudent stu[3];
char Na[21] ;
int Nu ;
int Ag ;
float MS;
float ES;
cout<<"輸入學生資訊:"<<endl;
for(int i=0;i<3;i++)
{
cin>>Na;
cin>>Nu;
cin>>Ag;
cin>>MS;
cin>>ES;
…
}
cout<<"輸出學生資訊:"<<endl;
cout<<" 姓名"<<" 學號"<<" 年齡"<<" 英語"<<" 數學"<<" 總分"<<endl;
for(int i=0;i<3;i++)
{
…
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/103041.html
標籤:C++ 語言
上一篇:小白的疑問-為什么ShowListData函式中需要head=head->next,哪一步說明head==NULL?
