1 #include2 #include 3 #include 4 using namespace std; 5 6 int num; //总学生人数 7 8 class student { 9 friend class studentMessage; 10 private: 11 string ID; 12 string name; 13 double score[5]; //1-4代表math、English、OPP和总成绩 ,0号单元空出 14 student * next; 15 public: 16 student(); 17 string getName(){ return name;} 18 string getID(){ return ID;} 19 double getMath(){ return score[1];} 20 double getEnglesh(){ return score[2];} 21 double getOPP(){ return score[3];} 22 double gettotol(){ return score[4];} 23 student* getNext(){ return next;} 24 25 static void analyse(int ,student * ); //分析成绩 26 void display(); //打印成绩 27 void swap(); //交换对象和对象->next的信息 28 }; 29 30 student::student() 31 { 32 cout<<"请输入学生学号 : ";cin>>ID; 33 cout<<"请输入学生姓名 : ";cin>>name; 34 cout<<"请输入学生的数学、英语和OPP成绩 : "< >a; 37 while(a<0||a>100) 38 { 39 cout<<"输入成绩有误,请重新输入: "< >a; 41 } 42 cin>>b; 43 while(b<0||b>100) 44 { 45 cout<<"输入成绩有误,请重新输入: "< >b; 47 } 48 cin>>c; 49 while(c<0||c>100) 50 { 51 cout<<"输入成绩有误,请重新输入: "< >c; 53 } 54 score[1]=a; 55 score[2]=b; 56 score[3]=c; 57 score[4]=a+b+c; 58 next=NULL; 59 } 60 61 void student::analyse(int a,student * first) 62 { 63 int you=0,liang=0,zhong=0,jige=0,bujige=0; 64 student * t=first; 65 double average=0; //平均分 66 while(t) 67 { 68 int b = int(t->score[a]/10); 69 switch(b) 70 { 71 case 10: 72 case 9:you++;break; 73 case 8:liang++;break; 74 case 7:zhong++;break; 75 case 6:jige++;break; 76 default:bujige++; 77 } 78 average+=t->score[a]; 79 t=t->next; 80 } 81 average=average/num; 82 cout<<" 考生总人数 : "< <<" 平均分 : "< < name;next->name=na;103 id=ID;ID=next->ID;next->ID=id;104 for(j=1;j<=4;j++)105 { 106 sco[j]=score[j];107 score[j]=next->score[j]; 108 next->score[j]=sco[j];109 }110 }111 112 class studentMessage{113 private:114 student * first;115 student * last;116 public:117 studentMessage();118 student* getFirst(){ return first;}119 student* getLast(){ return last;}120 int getNum(){ return num;}121 void add(); //向表中增加学生成绩记录122 void search(); //在表中查找学生成绩记录123 void del(); //在表中删除学生成绩记录124 void showOne(); //分析一门课的成绩125 void showAll(); //输出所有同学所有科目的成绩126 void sort(); //按一门课成绩或总成绩排序127 void clear(); //清空所有信息并退出系统128 129 };130 131 studentMessage::studentMessage()132 {133 first=NULL;134 last=NULL;135 num=0;136 }137 138 void studentMessage::add() 139 {140 student * t =new student;141 student *p = first;142 while(p){143 if(p->ID==t->ID)144 {145 cout<<"\n学号输入错误或该学生成绩已经存在!(如需修改,请先删除再重新录入)"< next;149 }150 num++;151 if(first==NULL)152 {153 first=last=t;154 155 }156 else157 { 158 last->next=t;159 last=last->next;160 }161 }162 163 void studentMessage::search()164 {165 string a;166 cout<<"\n请输入要查找的学生的学号:";cin>>a;167 student *t = first;168 while(t){169 if(t->ID==a)170 break;171 t=t->next;172 }173 if(!t)174 {175 cout<<"\n未找到要查找学生!"< display(); 181 }182 183 void studentMessage::del() 184 {185 string a;186 cout<<"\n请输入要删除的学生的学号: ";cin>>a;187 student *t = first;188 student *p=NULL;189 while(t){190 if(t->ID==a)191 break;192 p=t;193 t=t->next;194 }195 if(!t)196 {197 cout<<"\n未找到要删除学生!"< next;203 cout<<"\n成功删除学生"< < next=t->next;209 cout<<"成功删除学生"< <>a;222 if(a!=1&&a!=2&&a!=3)223 cout<<"\n输入序号有误,请重新输入!"< display();238 t=t->next;239 }240 }241 242 void studentMessage::sort()243 {244 int a,n=0; //n--排名245 cout<<"想要按照什么成绩排序?请输入相应序号(1.数学 2.英语 3.OPP 4.总成绩): ";246 while(1)247 {248 cin>>a;249 if (a!=1&&a!=2&&a!=3&&a!=4)250 cout<<"\n输入序号有误,请重新输入 : ";251 else252 break;253 }254 student *t=first;255 student *p=t;256 while(p->next)257 {258 t=first;259 while(t->next)260 {261 if(t->next->score[a]>=t->score[a])262 {263 t->swap();264 }265 t=t->next;266 }267 p=p->next;268 }269 t = first;270 cout<<"\n\t 成绩表如下: "< getID()<<" \t"< getName()<<" \t";275 switch(a)276 {277 case 1 :cout< getMath()<<" \t"< < getEnglesh()<<" \t"< < getOPP()<<" \t"< < gettotol()<<" \t"< < next; 283 }284 }285 286 void studentMessage::clear()287 {288 int x;289 cout<<"确认要清空所有信息?请输入1或2 (1:确认 2:取消) : ";cin>>x;290 if (x==2) 291 {292 cout<<"\n取消清空\n"< next;300 delete p;301 }302 cout<<"\n清空成功!\n";303 cout<<"退出成功!\n";304 }305 306 void showMenu()307 {308 cout << " \n";309 cout << "===============================\n";310 cout << " 学生成绩管理系统\n\n";311 cout << " 1.显示所有学生成绩\n";312 cout << " 2.添加信息\n";313 cout << " 3.查询信息\n";314 cout << " 4.删除信息\n";315 cout << " 5.成绩排序\n";316 cout << " 6.单科成绩分析\n";317 cout << " 7.清空所有信息并退出系统\n";318 cout << " 0.退出系统\n";319 cout << "===============================\n";320 cout << " \n";321 }322 323 int main()324 {325 int h;326 studentMessage stuM=studentMessage();327 while(1)328 {329 showMenu();330 cout << "请输入操作对应的序号 : ";331 cin >>h;332 cout<
历时两天整 重要把C++的课设做出来啦!吼开心! 第一次写课设 有不完善的还请多多指教哈