冲刺第七天

今天是冲刺最后一天,

我的任务是将学生成绩记录器的代码全部编写出来,

下面便是我编写出的全部代码:

public:
 Student()
 {
  this->name="wu";
  this->num=0;
  this->yuwen=0;
  this->shuxue=0;
  this->yinyu=0;
  this->average=0;
  this->all=0;
 }
 Student(string name,double num,double yuwen,double shuxue,double yinyu)
 {
  this->name=name;
  this->num=num;
  this->yuwen=yuwen;
  this->shuxue=shuxue;
  this->yinyu=yinyu;
 };
 Student(Student &p)
 {
  name=p.name;
  num=p.num;
  yuwen=p.yuwen;
  shuxue=p.shuxue;
  yinyu=p.yinyu;
  average=p.average;
  all=p.all;
 }
 ~Student(){};
 void Setname(string name);
 void Setnum(double num);
 void Setyuwen(double yuwen);
 void Setshuxue(double shuxue);
 void Setyinyu(double yinyu);
 void Setall(string name,double num,double yuwen,double shuxue,double yinyu);
 
protected:
 double yuwen,shuxue,yinyu,average,all,num;
 string name;
};
void Student::Setname(string name)
{
 this->name=name;
}
void Student::Setnum(double num)
{
 this->num=num; 
}
void Student::Setyuwen(double yuwen)
{
 this->yuwen=yuwen;
}
void Student::Setshuxue(double shuxue)
{
 this->shuxue=shuxue;
}
void Student::Setyinyu(double yinyu)
{
 this->yinyu=yinyu;
}
void Student::Setall(string name,double num,double yuwen,double shuxue,double yinyu)
{
 this->name=name;
 this->num=num;
 this->yuwen=yuwen;
 this->shuxue=shuxue;
 this->yinyu=yinyu;
}
class fun:public Student
{
public:
 void Display();
 void Average();
 void All();
 void SC();
 void XG();
 void PM();
 void CK();
 void CZ();
 void Luru();
 void CP();
};
fun stu[100];
int DQ_num;
void fun::Display()
{
 cout<<setiosflags(ios::left)<<setw(10)<<name;
 cout<<setw(10)<<num<<setw(10)<<yuwen<<setw(10)<<shuxue<<setw(10)<<yinyu<<setw(10)<<average<<setw(10)<<all<<endl;
}
void fun::Average()
{
 average=(yuwen+shuxue+yinyu)/3;
}
void fun::All()
{
 all=yuwen+shuxue+yinyu;
}
void fun::CZ()

 fun shift;
 int i=0,n=DQ_num;
 string strname;
 int flag=0;
 double strnum;
 char ch;
 system("cls");
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"******             ******"<<endl;
 cout<<"******   1.按学号查找         ******"<<endl;
 cout<<"******   2.按姓名查找         ******"<<endl;
 cout<<"******                    ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"********************************************************************"<<endl; 
 cout<<"请输入你的选择:";
 cin>>ch;
 if('1'==ch)
 {
  cout<<"请输入要查询学生的学号:";
  cin>>strnum;
  cout<<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"语文"<<setw(10)<<"数学"<<setw(10)<<"外语"<<setw(10)<<"平均"<<setw(10)<<"总分"<<endl;
  for(i=0;i<n;i++)
  {
   if(strnum==stu[i].num)
   {
    stu[i].Display();
    flag=1;
   }
  }
  if(flag==0)
  {
   cout<<"没有该学生";
  }
  if(flag==1)
  {
   cout<<"查找成功!!";
  }
  cout<<"按任意键返回";
  fflush(stdin);
  getchar();
 }
 if('2'==ch)
 {
  cout<<"请输入要查询学生的姓名:";
  cin>>strname;
  cout<<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"语文"<<setw(10)<<"数学"<<setw(10)<<"外语"<<setw(10)<<"平均"<<setw(10)<<"总分"<<endl;
  for(i=0;i<n;i++)
  {
   if(strname==stu[i].name)
   {
    stu[i].Display();
    flag=1;
   }
  }
  if(flag==0)
  {
   cout<<"没有该学生";
  }
  if(flag==1)
  {
   cout<<"查找成功!!";
  }
  cout<<"按任意键返回";
  fflush(stdin);
  getchar();
 }
}
void fun::PM()
{
 system("cls");
 fun shift;
 int i=DQ_num,j,k;
 char ch;
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"******             ******"<<endl;
 cout<<"******   1.按学号排名         ******"<<endl;
 cout<<"******   2.按总分排名         ******"<<endl;
 cout<<"******   3.按语文排名         ******"<<endl;
 cout<<"******   4.按数学排名         ******"<<endl;
 cout<<"******   5.按外语排名         ******"<<endl;
 cout<<"******   6.各个分数段信息        ******"<<endl;
 cout<<"******                    ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"请输入你的选择:";
 cin>>ch;
 if(ch=='1')
 {
  for(j=0;j<i;j++)
  {
   for(k=j+1;k<i;k++)
   {
    if(stu[j].num>stu[k].num)
    {
     shift=stu[j];
     stu[j]=stu[k];
     stu[k]=shift;
    }
   }
  }
  cout<<"排名成功。。。。按任意键返回";
 }
 else if(ch=='2')
 {
  for(j=0;j<i;j++)
  {
   for(k=j+1;k<i;k++)
   {
    if(stu[j].all<stu[k].all)
    {
     shift=stu[j];
     stu[j]=stu[k];
     stu[k]=shift;
    }
   }
  }
  cout<<"排名成功。。。。按任意键返回";
 }
 else if(ch=='3')
 {
  for(j=0;j<i;j++)
  {
   for(k=j+1;k<i;k++)
   {
    if(stu[j].yuwen<stu[k].yuwen)
    {
     shift=stu[j];
     stu[j]=stu[k];
     stu[k]=shift;
    }
   }
  }
  cout<<"排名成功。。。。按任意键返回";
 }
 else if(ch=='4')
 {
  for(j=0;j<i;j++)
  {
   for(k=j+1;k<i;k++)
   {
    if(stu[j].shuxue<stu[k].shuxue)
    {
     shift=stu[j];
     stu[j]=stu[k];
     stu[k]=shift;
    }
   }
  }
  cout<<"排名成功。。。。按任意键返回"; 
 }
 else if(ch=='5')
 {
  for(j=0;j<i;j++)
  {
   for(k=j+1;k<i;k++)
   {
    if(stu[j].yinyu<stu[k].yinyu)
    {
     shift=stu[j];
     stu[j]=stu[k];
     stu[k]=shift;
    }
   }
  }
  cout<<"排名成功。。。。按任意键返回"; 
 }
 else if(ch=='6')
 {
  int n=0;
  string str;
  float n1;
  float q,h,t;
  cout<<"请输入学科(中文):";
  cin>>str;
  while(str!="语文"&&str!="数学"&&str!="英语")
  {
   cout<<"没有该学科,从新输入"<<endl;
   cout<<"请输入学科(拼音):";
   cin>>str;
  }
  cout<<"请输入分数段(0—100)";
  cin>>q>>h;
  while(q<0||q>100||h<0||h>100)
  {
   cout<<"输入有误,从新输入"<<endl;
   cout<<"请输入分数段(0—100)";
   cin>>q>>h;
  }
  if(q>h)
  {
   t=q;
   q=h;
   h=t;
  }
  if(str=="语文")
  {
   for(j=0;j<i;j++)
   {
    if(stu[j].yuwen>=q&&stu[j].yuwen<=h)
    {
     n++;
    }
   }
   n1=((float)n/i)*100;
   cout<<"该分数段的学生人数为"<<n<<"占总人数的百分比为"<<n1<<"%"<<endl;
  }
  if(str=="数学")
  {
   for(j=0;j<i;j++)
   {
    if(stu[j].shuxue>=q&&stu[j].shuxue<=h)
    {
     n++;
    }
   }
   n1=((float)n/i)*100;
   cout<<"该分数段的学生人数为"<<n<<"占总人数的百分比为"<<n1<<"%"<<endl;
  }
  if(str=="英语")
  {
   for(j=0;j<i;j++)
   {
    if(stu[j].yinyu>=q&&stu[j].yinyu<=h)
    {
     n++;
    }
   }
   n1=((float)n/i)*100;
   cout<<"该分数段的学生人数为"<<n<<"占总人数的百分比为"<<n1<<"%"<<endl;
  }
 }
 cout<<"按任意键返回";
 fflush(stdin);
 getchar();  
}
void fun::XG()
{
 double str;
 int i=DQ_num,j;
 system("cls");
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"请输入想修改的学号:";
 cin>>str;
 for(j=0;j<i;j++)
 {
  if(stu[j].num==str)
  {
   double yw,sx,yy,nu;
   string n;
   int m=0;
   cout<<setw(5)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"语文"<<setw(10)<<"数学"<<setw(10)<<"外语"<<setw(10)<<"平均"<<setw(10)<<"总分"<<endl;
   stu[j].Display();
   cout<<"请输入:"<<endl;
   cout<<"姓名";
   cin>>n; 
   cout<<"学号";
   cin>>nu;
   while(m<DQ_num)
   {
    if(stu[m].num==nu&&m!=j)
    {
     cout<<"该学号已存在,请从新输入"<<endl;
     cout<<"学号";
     cin>>nu;
     i=0;
    }
    m++;
   }
   cout<<"语文";
   cin>>yw;
   while(yw>100||yw<0)
   {
    cout<<"不符合逻辑请从新输入"<<endl;
    cout<<"语文";
    cin>>yw;
   }
   cout<<"数学";
   cin>>sx;
   while(sx>100||sx<0)
   {
    cout<<"不符合逻辑请从新输入"<<endl;
    cout<<"数学";
    cin>>sx;
   }
   cout<<"英语";
   cin>>yy;
   while(yy>100||yy<0)
   {
    cout<<"不符合逻辑请从新输入"<<endl;
    cout<<"英语";
    cin>>yy;
   }
   stu[j].Setall(n,nu,yw,sx,yy);
   stu[j].Average();
   stu[j].All();
   cout<<setw(5)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"语文"<<setw(10)<<"数学"<<setw(10)<<"外语"<<setw(10)<<"平均"<<setw(10)<<"总分"<<endl;
   stu[j].Display();
   cout<<"修改成功";
   fflush(stdin);
   cout<<"按任意键返回";
   getchar();
   break;
  }
 }
 if(i==j)
 {
  cout<<"没有该学生。。。。按任意键返回";
  fflush(stdin);
  getchar();
 }
}
void fun::SC()
{
 system("cls");
 double str;
 char ch;
 int i=DQ_num,j,flag=0;
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"请输入想删除的学号:";
 cin>>str;
 for(j=0;j<i;j++)
 {
  if(stu[j].num==str)
  {
   cout<<"是否要删除?Y/N";
   cin>>ch;
   if(ch=='Y'||ch=='y')
   {
    stu[j].Setnum(0);
    flag=1;
   }
   else if(ch=='N'||ch=='n')
   {
    flag=2;
    cout<<"按任意键返回";
    getchar();
   }
  }
 }
 if(0==flag)
 {
  cout<<"没有该学生。。。。按任意键返回";
  fflush(stdin);
  getchar();
 }
 else if(1==flag)
 {
  cout<<"删除成功。。。。按任意键返回";
  fflush(stdin);
  getchar();
 }
 if(2==flag)
 {};
}
void fun::Luru()
{
 system("cls");
 fun clas;
 int i=0,j,m;
 double yw,sx,yy,nu;
 string n;
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"请输入要输入的学生人数:"<<endl;
 cin>>m;
 for(j=0;j<m;j++)
 { 
  cout<<"输入第"<<j+1<<"个学生的信息"<<endl;
  cout<<"姓名";
  cin>>n; 
  cout<<"学号";
  cin>>nu;
  while(i<DQ_num)
  {
   if(stu[i].num==nu)
   {
    cout<<"该学号已存在,请从新输入"<<endl;
    cout<<"学号";
    cin>>nu;
    i=0;
   }
   i++;
  }
  cout<<"语文";
  cin>>yw;
  while(yw>100||yw<0)
  {
   cout<<"不符合逻辑请从新输入"<<endl;
   cout<<"语文";
   cin>>yw;
  }
  cout<<"数学";
  cin>>sx;
  while(sx>100||sx<0)
  {
   cout<<"不符合逻辑请从新输入"<<endl;
   cout<<"数学";
   cin>>sx;
  }
  cout<<"英语";
  cin>>yy;
  while(yy>100||yy<0)
  {
   cout<<"不符合逻辑请从新输入"<<endl;
   cout<<"英语";
   cin>>yy;
  }
  stu[DQ_num].Setall(n,nu,yw,sx,yy);
  stu[DQ_num].Average();
  stu[DQ_num].All();
  cout<<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"语文"<<setw(10)
   <<"数学"<<setw(10)<<"外语"<<setw(10)<<"平均"<<setw(10)<<"总分"<<endl;
  stu[DQ_num].Display(); 
  DQ_num++;
 }
 cout<<"按任意键返回";
 fflush(stdin);
 getchar(); 
}
void fun::CK()
{
 fun clas;
 int i=0; 
 system("cls");
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"语文"<<setw(10)<<"数学"<<setw(10)<<"外语"<<setw(10)<<"平均"<<setw(10)<<"总分"<<endl;
 for(i=0;i<DQ_num;i++)
 {
  if(stu[i].num!=0)
  stu[i].Display();
 }
 cout<<"按任意键返回";
 fflush(stdin);
 getchar();
}
void fun::CP()
{
 char ch;
 system("cls");
 cout<<"********************************************************************"<<endl;
 cout<<"******   学生成绩管理系统        ******"<<endl;
 cout<<"********************************************************************"<<endl;
 cout<<"是否确定存盘,存盘将会覆盖以前的数据?(Y/N)";
 cin>>ch;
 if(ch=='Y'||ch=='y')
 {
  int j;
  ofstream outfile;
  outfile.open("f1.txt",ios::out);
  if(!outfile)
  {
   outfile.close();
   cout<<"文件打开错误!......按任意键返回";
   getchar();
  }
  else
  {
   for(j=0;j<DQ_num&&stu[j].num!=0;j++)
   outfile<<stu[j].name<<" "
    <<stu[j].num<<" "
    <<stu[j].yuwen<<" "
    <<stu[j].shuxue<<" "
    <<stu[j].yinyu<<" "
    <<stu[j].average<<" "
    <<stu[j].all<<" ";
   cout<<"存入成功";
  }
 }
 if(ch=='N'||ch=='n')
 {}
 fflush(stdin); 
 cout<<"按任意键返回";
 getchar();
}
void main()
{
 char ch;
 fun clas;
 int i=0;
 ifstream inFile;
 inFile.open("f1.txt",ios::in);
 if(!inFile)
 {
  cout<<"文件打开错误!";
  fflush(stdin);
  getchar();
  inFile.close();
 }
 while(!inFile.eof())
 {
  double yw,sx,yy,av,al,nu;
  string n;
  inFile>>n;
  inFile>>nu;
  inFile>>yw;
  inFile>>sx;
  inFile>>yy;
  inFile>>av;
  inFile>>al;
  if(i==0)
  {
   stu[i].Setall(n,nu,yw,sx,yy);
   stu[i].Average();
   stu[i].All();
   i++;
   if(inFile.eof())
   break;
  }
  else
  {
   if(inFile.eof())
   break;
   stu[i].Setall(n,nu,yw,sx,yy);
   stu[i].Average();
   stu[i].All();
   i++;
  }
 }
 inFile.close();
 DQ_num=i;
 while(1)
 {
  system("cls");
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
  cout<<"********************************************************************"<<endl;
  cout<<"******   学生成绩管理系统        ******"<<endl;
  cout<<"********************************************************************"<<endl;
  cout<<"******             ******"<<endl;
  cout<<"******   1.学生数据录入         ******"<<endl;
  cout<<"******   2.成绩统计排名         ******"<<endl;
  cout<<"******   3.修改          ******"<<endl;
  cout<<"******   4.删除          ******"<<endl;
  cout<<"******   5.查看          ******"<<endl;
  cout<<"******   6.查找                 ******"<<endl;
  cout<<"******   7.存盘                 ******"<<endl;
  cout<<"******   8.退出                 ******"<<endl;
  cout<<"******                    ******"<<endl;
  cout<<"********************************************************************"<<endl;
  cout<<"********************************************************************"<<endl; 
  cout<<"请输入你的选择:";
  cin>>ch;
  switch(ch)
  {
  case '1':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_BLUE);
    clas.Luru();break;
   }
  case '2':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
    clas.PM();break;
   }
  case '3':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
    clas.XG();break;
   }
  case '4':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN);
    clas.SC();break;
   }
  case '5':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN);
    clas.CK();break;
   }
  case '6':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN);
    clas.CZ();break;
   }
  case '7':
   {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
    clas.CP();break;
   }
  case '8':exit(0);
  }
冲一周完结。

猜你喜欢

转载自www.cnblogs.com/shijiazhuangtiedaodaxue/p/9997439.html