个人成绩管理系统

#include 

#include 

using namespace std;

class Student

{

public:

Student();

  void output();

  void change();

  void sort1();

  void sort0();

  void Sum();

private:

string name;

string sex;

double score[5];

double old;

string class_1;

string str[5];

};

Student::Student()

{

         name="梁燕婷";

  sex="";

  old=19;

  class_1="软件114";

  score[0]=99;score[1]=21;score[2]=28;score[3]=98;score[4]=74;

  str[0]="高等数学";str[1]="C++程序设计";str[2]="计算机文化";str[3]="离散数学";str[4]="大学英语";

}

void Student::output()

{

cout<<"姓名:"<<name<<endl;

cout<<"年龄:"<<old<<endl;

cout<<"性别:"<<sex<<endl;

cout<<"班级:"<<class_1<<endl;

cout<<"分数:";

for(int i=0;i<5;i++)

cout<<str[i]<<":  "<<score[i]<<" ,  ";

}

void Student::change()

{

string str1;

    cout<<"请输入要修改的内容:姓名or年龄or性别or班级or分数 : ";

cin>>str1;system("cls");system("pause");

if(str1=="姓名")

{cout<<"请输入新的姓名:";cin>>name;}

else if(str1=="年龄")

{cout<<"请输入新的年龄:";cin>>old;}

else if(str1=="班级")

{cout<<"请输入新的班级:";cin>>class_1;}

else if(str1=="性别")

{cout<<"请输入性别:";cin>>sex;}

else if(str1=="分数")

{

cout<<"请输入新的分数:"<<endl;

for(int i=0;i<5;i++)

{cout<<"请重新输入"<<str[i]<<"的分数:";

cin>>score[i];

}

}

}

void Student::sort1()

{

int i,j=0,temp;

string ss;

for(j=0;j<5;j++)

  for(i=0;i<5-j;i++)

if(score[i+1]>score[i])

{

temp=score[i+1];

score[i+1]=score[i];

score[i]=temp;

ss=str[i+1];

str[i+1]=str[i];

str[i]=ss;

}

}

void Student::sort0()

{

int i,j=0,temp;

string ss;

for(j=0;j<4;j++)

   for(i=0;i<4-j;i++)

if(score[i]

{

temp=score[i+1];

score[i+1]=score[i];

score[i]=temp;

ss=str[i+1];

str[i+1]=str[i];

str[i]=ss;

}

}

void Student::Sum()

{

double sum=0;

for(int i=0;i<5;i++)

sum=sum+score[i];

cout<<"总分:"<<sum<<endl;

}

void fun1(Student &stu)

{

stu.change();

cout<<"是否想继续修改数据???Y or N: ";

}

void fun2(Student &stu)

{

string str0;char c;

cout<<"你是相对分数进行升序还是将序排序???";cin>>str0;

if(str0=="升序")

{

stu.sort1();

cout<<"* * * * * * * * * * * * * * * * * * * * * * *"<<endl;

cout<<"是否想求总分??? Y or N:  ";cin>>c;     

if(c=='Y')

{

cout<<"* * * * * * * * * * * * * * * * * * * * * * *"<<endl;

stu.output();cout<<endl;

stu.Sum();

}

else stu.output();

}

else if(str0=="降序")

{

stu.sort0();

cout<<"是否想求总分??? Y or N:  ";cin>>c;     

if(c=='Y')

{

cout<<"* * * * * * * * * * * * * * * * * * * * * * *"<<endl;

   stu.output();cout<<endl;

   stu.Sum();

}

else stu.output();

}

}

int main()

{

system("mode con cols=80 lines=30");

system("title 学生个人成绩管理系统-梁燕婷");

system("color f9");

Student stud1;char c;string str0;

stud1.output();

cout<<endl<<"* * * * * * * * * * * * * * * * * * * * * * *"<<endl;

cout<<endl<<"是否要对以上分数进行修改???Y or N:  ";cin>>c;system("cls");system("pause");

while(c=='Y')

{

fun1(stud1);

cin>>c;

}

cout<<endl<<"是否想对以上分数进行排序???Y or N:  ";cin>>c;system("cls");system("pause");

while(c=='Y')

fun2(stud1);

break;

}

cout<<"* * * * * * * * * * * * * * * * * * * * * * *"<<endl;

return 0;

}

 

 

 

posted on 2012-12-07 23:35  木本  阅读(166)  评论(0编辑  收藏  举报

导航