鱼C论坛

 找回密码
 立即注册
查看: 2241|回复: 0

C++做的学生管理系统,好几处没法解决,求大神

[复制链接]
发表于 2012-5-1 23:26:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Student.cpp
  1. #include "SeqList.h"
  2. #include "Student.h"
  3. #include <string.h>
  4. double average(SeqList<Student> &stulist)
  5. {
  6.         int n=stulist.length();
  7.         if(n>0)
  8.         {
  9.         double sum=0.0;
  10.         for(int i=0;i<n;i++)
  11.                 sum+=stulist.get(i).score;
  12.         return sum/n;}
  13.         return 0.0;
  14. }
  15. void printGrade(SeqList<Student> &stulist)
  16. {
  17.         int n=stulist.length();
  18.         if(n>0)
  19.         {
  20.                 int grade[5]={0};
  21.                 for(int i=0;i<n;i++)
  22.                 {
  23.                         double x=stulist.get(i).score;
  24.                         if(x>=90&&x<=100)
  25.                                 grade[0]++;
  26.                         if(x>=80&&x<90)
  27.                                 grade[1]++;
  28.                         if(x>=70&&x<80)
  29.                                 grade[2]++;
  30.                         if(x>=60&&x<70)
  31.                                 grade[3]++;
  32.                         else if(x>=0&&x<60)
  33.                                 grade[4]++;
  34.                 }
  35.                 cout<<"优秀"<<grade[0]<<",良好"<<grade[1]<<",中等"<<grade[2]<<",及格"<<grade[3]<<",不及格"<<grade[4]<<endl;
  36.         }
  37. }
  38. int main()
  39. {
  40.         Student group[]={{200977400,"王明",100}};
  41.         SeqList<Student> stulist(group,1);
  42.         cout<<"1.输出学生成绩表"<<endl;
  43.         cout<<"2.添加学生成绩信息"<<endl;
  44.         cout<<"3.查找学生信息"<<endl;
  45.         cout<<"4.删除学生信息"<<endl;
  46.         cout<<"5.输出平均成绩"<<endl;
  47.                 int n=0;
  48.         cin>>n;
  49.         while(n!=0)
  50.         {
  51.                 if(n==1)
  52.         {
  53.                 cout<<"学生成绩("<<stulist.length()<<"人):";
  54.                 cout<<stulist;
  55.                 cout<<endl;
  56.                 int len1=stulist.length();
  57.                 cout<<len1<<endl;
  58.         }
  59.         if(n==2)
  60.         {cout<<"输入学生个数:";
  61.         int k;
  62.         cin>>k;
  63.         Student stu1;
  64.         for(int j=0;j<k;j++)
  65.         {cout<<"姓名:";
  66.         cin>>stu1.name;
  67.         stu1.number=stulist.length()+200977400;
  68.         cout<<"学号:"<<stu1.number<<endl;
  69.         cout<<"成绩:";
  70.         cin>>stu1.score;
  71.         stulist.insert(stu1);
  72.         cout<<endl;
  73.         }
  74.         }
  75.         if(n==3)
  76.         {char c[20];
  77.         char q[20]="q";
  78.         cout<<"输入姓名(输入q退出):";
  79.         cin>>c;
  80.          while(strcmp(c,q)==1)
  81.          {
  82.                 for(int i=0;i<stulist.length();i++)
  83.                 {
  84.                
  85.                          if (strcmp(c,stulist.get(i).name)==0)
  86.                                         {
  87.                                                 cout<<stulist.get(i).name<<endl;
  88.                                                 cout<<stulist.get(i).number<<endl;
  89.                                                 cout<<stulist.get(i).score<<endl;
  90.                                                 cout<<"输入姓名继续查找(输入q退出):";
  91.                                         }
  92.                 }cout<<"查找失败重新输入:";
  93.                         cin>>c;
  94.          }       
  95.         }
  96.         if(n==4)
  97.         {int c;
  98.         Student stu;
  99.         cout<<"输入删除学号:";
  100.         cin>>c;
  101.                 for(int i=0;i<stulist.length();i++)
  102.                 {
  103.                
  104.                          if (c==stulist.get(i).number)
  105.                                         {
  106.                                                 stulist.remove(i,stu);
  107.                                         }
  108.                 }
  109.                 cout<<"已删除"<<stu.name<<endl;

  110.         }
  111.         if(n==5)
  112.         {
  113.                 printGrade(stulist);
  114.         cout<<"平均成绩:"<<average(stulist)<<endl;
  115.         }

  116.         cout<<"其他操作(输入Q退出):";
  117.         cin>>n;
  118.         }
  119.         return 0;
  120. }
复制代码
查找的地方
  1.         {char c[20];
  2.         char q[20]="q";
  3.         cout<<"输入姓名(输入q退出):";
  4.         cin>>c;
  5.          while(strcmp(c,q)==1)
  6.          {
  7.                 for(int i=0;i<stulist.length();i++)
  8.                 {
  9.                
  10.                          if (strcmp(c,stulist.get(i).name)==0)
  11.                                         {
  12.                                                 cout<<stulist.get(i).name<<endl;
  13.                                                 cout<<stulist.get(i).number<<endl;
  14.                                                 cout<<stulist.get(i).score<<endl;
  15.                                                 cout<<"输入姓名继续查找(输入q退出):";
  16.                                         }
  17.                 }cout<<"查找失败重新输入:";
  18.                         cin>>c;
  19.          }       
  20.         }
复制代码
变成这样
  1.         {char c[20];
  2.         char q[20]="q";
  3.         cout<<"输入姓名(输入q退出):";
  4.         cin>>c;
  5.          while(strcmp(c,q)==1)
  6.          {
  7.                 for(int i=0;i<stulist.length();i++)
  8.                 {
  9.                
  10.                          if (strcmp(c,stulist.get(i).name)==0)
  11.                                         {
  12.                                                 cout<<stulist.get(i).name<<endl;
  13.                                                 cout<<stulist.get(i).number<<endl;
  14.                                                 cout<<stulist.get(i).score<<endl;
  15.                                                 cout<<"输入姓名继续查找(输入q退出):";
  16.                                              else
  17.                                               cout<<cout<<"查找失败重新输入:";
  18.                                         }
  19.                 }
  20.                         cin>>c;
  21.          }       
  22.         }
复制代码
老是循环的时候出错
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-13 04:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表