|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Student.cpp- #include "SeqList.h"
- #include "Student.h"
- #include <string.h>
- double average(SeqList<Student> &stulist)
- {
- int n=stulist.length();
- if(n>0)
- {
- double sum=0.0;
- for(int i=0;i<n;i++)
- sum+=stulist.get(i).score;
- return sum/n;}
- return 0.0;
- }
- void printGrade(SeqList<Student> &stulist)
- {
- int n=stulist.length();
- if(n>0)
- {
- int grade[5]={0};
- for(int i=0;i<n;i++)
- {
- double x=stulist.get(i).score;
- if(x>=90&&x<=100)
- grade[0]++;
- if(x>=80&&x<90)
- grade[1]++;
- if(x>=70&&x<80)
- grade[2]++;
- if(x>=60&&x<70)
- grade[3]++;
- else if(x>=0&&x<60)
- grade[4]++;
- }
- cout<<"优秀"<<grade[0]<<",良好"<<grade[1]<<",中等"<<grade[2]<<",及格"<<grade[3]<<",不及格"<<grade[4]<<endl;
- }
- }
- int main()
- {
- Student group[]={{200977400,"王明",100}};
- SeqList<Student> stulist(group,1);
- cout<<"1.输出学生成绩表"<<endl;
- cout<<"2.添加学生成绩信息"<<endl;
- cout<<"3.查找学生信息"<<endl;
- cout<<"4.删除学生信息"<<endl;
- cout<<"5.输出平均成绩"<<endl;
- int n=0;
- cin>>n;
- while(n!=0)
- {
- if(n==1)
- {
- cout<<"学生成绩("<<stulist.length()<<"人):";
- cout<<stulist;
- cout<<endl;
- int len1=stulist.length();
- cout<<len1<<endl;
- }
- if(n==2)
- {cout<<"输入学生个数:";
- int k;
- cin>>k;
- Student stu1;
- for(int j=0;j<k;j++)
- {cout<<"姓名:";
- cin>>stu1.name;
- stu1.number=stulist.length()+200977400;
- cout<<"学号:"<<stu1.number<<endl;
- cout<<"成绩:";
- cin>>stu1.score;
- stulist.insert(stu1);
- cout<<endl;
- }
- }
- if(n==3)
- {char c[20];
- char q[20]="q";
- cout<<"输入姓名(输入q退出):";
- cin>>c;
- while(strcmp(c,q)==1)
- {
- for(int i=0;i<stulist.length();i++)
- {
-
- if (strcmp(c,stulist.get(i).name)==0)
- {
- cout<<stulist.get(i).name<<endl;
- cout<<stulist.get(i).number<<endl;
- cout<<stulist.get(i).score<<endl;
- cout<<"输入姓名继续查找(输入q退出):";
- }
- }cout<<"查找失败重新输入:";
- cin>>c;
- }
- }
- if(n==4)
- {int c;
- Student stu;
- cout<<"输入删除学号:";
- cin>>c;
- for(int i=0;i<stulist.length();i++)
- {
-
- if (c==stulist.get(i).number)
- {
- stulist.remove(i,stu);
- }
- }
- cout<<"已删除"<<stu.name<<endl;
- }
- if(n==5)
- {
- printGrade(stulist);
- cout<<"平均成绩:"<<average(stulist)<<endl;
- }
- cout<<"其他操作(输入Q退出):";
- cin>>n;
- }
- return 0;
- }
复制代码 查找的地方- {char c[20];
- char q[20]="q";
- cout<<"输入姓名(输入q退出):";
- cin>>c;
- while(strcmp(c,q)==1)
- {
- for(int i=0;i<stulist.length();i++)
- {
-
- if (strcmp(c,stulist.get(i).name)==0)
- {
- cout<<stulist.get(i).name<<endl;
- cout<<stulist.get(i).number<<endl;
- cout<<stulist.get(i).score<<endl;
- cout<<"输入姓名继续查找(输入q退出):";
- }
- }cout<<"查找失败重新输入:";
- cin>>c;
- }
- }
复制代码 变成这样- {char c[20];
- char q[20]="q";
- cout<<"输入姓名(输入q退出):";
- cin>>c;
- while(strcmp(c,q)==1)
- {
- for(int i=0;i<stulist.length();i++)
- {
-
- if (strcmp(c,stulist.get(i).name)==0)
- {
- cout<<stulist.get(i).name<<endl;
- cout<<stulist.get(i).number<<endl;
- cout<<stulist.get(i).score<<endl;
- cout<<"输入姓名继续查找(输入q退出):";
- else
- cout<<cout<<"查找失败重新输入:";
- }
- }
- cin>>c;
- }
- }
复制代码 老是循环的时候出错 |
|