分享
 
 
 

一个小型学生成绩管理程序

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//小型学生成绩管理程序

#include

#include

// Declaration and definition of class base_Student

class base_Student

{

public:

base_Student(); //constructor

base_Student(base_Student&); //copy constructor

char* operator =(char Name1[]) //overload operator =

{

return Name1;

}

void Initial(void);

float ShowScore(void);

void Show(void);

private:

int ID;

char Name[20];

float Score;

};

//constructor

base_Student::base_Student()

{

ID=0;

Score=0;

}

//copy constructor

base_Student::base_Student(base_Student& Student1)

{

Student1.ID=ID;

strcpy(Student1.Name,Name);

Student1.Score=Score;

}

//initialize student's data

void base_Student::Initial(void)

{

cout<<"ID:";

cin>>ID;

cout<<"Name:";

cin>>Name;

cout<<"Score:";

cin>>Score;

}

//return student's score

float base_Student::ShowScore(void)

{

return Score;

}

//display student's information

void base_Student::Show(void)

{

cout<

cout<<"ID:"<

cout<<"Name:"<

cout<<"Score:"<

}

// Declaration and definition of class Student derived from class base_Student

class Student:public base_Student

{

friend class StudentManager; //definite StudentManager as friend class

public:

Student();

Student(Student&);

void ChangeOrder(int i){Order=i;};

int ShowOrder();

void Show(void);

private:

int Order;

};

//constructor

Student::Student()

{

Order=0;

}

//copy constructor

Student::Student(Student& Student1)

{

Student1.Order=Order;

}

//return Order

int Student::ShowOrder()

{

return Order;

}

//return student's information

void Student::Show()

{

base_Student::Show();

cout<<"Order:"<

}

// Declaration and definition of class StudentManager for student management

class StudentManager

{

public:

StudentManager();

void SetClassName(char*);

int SetSize(int i);

void Input(void);

float Average(void);

int Swap(Student&,Student&);

void SetOrder(void);

void SortAsOrder(void);

int Show(void);

private:

char* ClassName;

Student students[60];

int Size;

float Aver_Score;

};

StudentManager::StudentManager()

{

ClassName=NULL;

}

void StudentManager::SetClassName(char* newClassName)

{

ClassName=newClassName;

}

//set class size

int StudentManager::SetSize(int i)

{

Size=i;

return 0;

}

//input every student's information of the class

void StudentManager::Input(void)

{

int i;

cout<<"Please input students' information:"<

for(i=0;i

{

cout<

students[i].Initial();

students[i].Order=i+1;

}

}

//calculate average score of the class

float StudentManager::Average(void)

{

int i(0);

float sum(0.0);

for(i=0;i

sum+=students[i].ShowScore();

Aver_Score=sum/Size;

cout< return Aver_Score;} //swap two students's dataint StudentManager::Swap(Student& Student1,Student& Student2) { Student Temp; Temp=Student1; Student1=Student2; Student2=Temp; return 0;} //set student's order according to his scorevoid StudentManager::SetOrder(void) { int i(0),j(0); for(i=0;i for(j=i;j if(students[j].ShowScore()>students[i].ShowScore()) { students[i].ChangeOrder(j+1); students[j].ChangeOrder(i+1); }} //exchange student's position according to his scorevoid StudentManager::SortAsOrder(void) { int i; for(i=0;i Swap(students[i],students[students[i].ShowOrder()-1]);} //display the whole class's informationint StudentManager::Show() { int i; cout< for(i=0;i students[i].Show(); return 0;} //main entry of the programint main(void){ int n; char ClassName[10]; StudentManager stuManager; cout<<"Please input your class's name:"< cin>>ClassName; stuManager.SetClassName(ClassName); cout<<"How many students are there in your class?"< cin>>n; stuManager.SetSize(n); stuManager.Input(); stuManager.Average(); stuManager.SetOrder(); stuManager.Show(); stuManager.SortAsOrder(); cout< stuManager.Show(); return 0;}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有