课程设计

  1. #include<iostream>  
  2. #include<iomanip>  
  3. #include<string>  
  4. using namespace std;  
  5. class student  
  6. {  
  7.     int num;  
  8.     char name[20];  
  9.     char class1[20];  
  10.     double chinese;  
  11.     double math;  
  12.     double english;  
  13.     double youxiu;//优秀率  
  14.     double bujige;//不及格率  
  15.     double sum;//总成绩  
  16.     double aver1;//平均成绩  
  17.   
  18. public:  
  19.     void set()  
  20.     {  
  21.   
  22.       cout<<"\t学生学号:";  
  23.       cin>>num;  
  24.       cout<<"\t学生姓名:";  
  25.       cin>>name;  
  26.       cout<<"\t学生班级:";  
  27.       cin>>class1;  
  28.       cout<<"\t语文成绩:";  
  29.       cin>>chinese;  
  30.       cout<<"\t英语成绩:";  
  31.       cin>>english;  
  32.       cout<<"\t数学成绩:";  
  33.       cin>>math;  
  34.     }  
  35.     void show()  
  36.     {  
  37.         cout<<"该学生的学号:"<<num<<endl;  
  38.         cout<<"该学生的姓名:"<<name<<endl;  
  39.         cout<<"该学生的班级:"<<class1<<endl;  
  40.         cout<<"该学生的语文成绩:"<<chinese<<endl;  
  41.         cout<<"该学生的数学成绩:"<<math<<endl;  
  42.         cout<<"该学生的英语成绩:"<<english<<endl;  
  43.     }  
  44.     double ad(){return sum=chinese+english+math;}  
  45.     double aver()  
  46.     {  
  47.         aver1=(chinese+english+math)/3;  
  48.         return aver1;  
  49.     }  
  50.     friend  void    show();  
  51.     friend  void    search();   
  52.     friend  void    change();   
  53.     friend  void    add();   
  54.     friend  void    paixu();  
  55.     friend  void    del();   
  56.   
  57. };  
  58.     void    input();  
  59.     void    show();  
  60.     void    search();   
  61.     void    change();   
  62.     void    add();   
  63.     void    paixu();  
  64.     void    del();   
  65.     student s[100];  
  66.     int n=0;  
  67.   
  68. int main()  
  69. {  
  70.   
  71.     int select;     
  72.     while(1)  
  73.     {  
  74.         system("cls");  
  75.         cout<<"\t ******************欢迎使用******************\n";  
  76.         cout<<"\t **************学生成绩管理系统**************\n";  
  77.         cout<<"\t *------------------------------------------*\n";  
  78.         cout<<"\t *         1——录入学生信息                *\n";  
  79.         cout<<"\t *         2——显示学生信息                *\n";  
  80.         cout<<"\t *         3——查询学生信息                *\n";  
  81.         cout<<"\t *         4——修改学生信息                *\n";  
  82.         cout<<"\t *         5——添加学生信息                *\n";   
  83.         cout<<"\t *         6——删除学生信息                *\n";  
  84.         cout<<"\t *         0——退出                        *\n";  
  85.         cout<<"\t *------------------------------------------*\n";  
  86.         cout<<"\t 你要输入的编号是(0--6):";  
  87.         cin>>select;  
  88.         if(select==0) break;  
  89.         switch(select){  
  90.         case 1:  
  91.             input(); //调用input函数录入数据  
  92.             system("pause");  
  93.             break;  
  94.         case 2:  
  95.             show(); //调用show函数显示学生信息   
  96.             system("pause");  
  97.             break;  
  98.         case 3:  
  99.             search();  //调用search函数查询学生信息  
  100.             system("pause");  
  101.             break;  
  102.         case 4:  
  103.             change();  //调用change函数修改学生信息  
  104.             system("pause");  
  105.             break;  
  106.         case 5:  
  107.             add();     //调用add函数添加学生信息  
  108.             system("pause");  
  109.             break;  
  110.         case 6:  
  111.             paixu();     //调用add函数添加学生信息  
  112.             system("pause");  
  113.             break;  
  114.         case 7:  
  115.             del();    // 调用del函数删除学生信息  
  116.             system("pause");  
  117.             break;  
  118.   
  119.               
  120.   
  121.                 system("pause");  
  122.         default:  
  123.             cout<<"没有此选项,请重新选择!"<<endl;  
  124.         }  
  125.     }  
  126.     return 0;  
  127. }  
  128.     void input() //录入学生信息的函数  
  129. {  
  130.   char sel;  
  131.   do  
  132.   {  
  133.       n++;  
  134.       cout<<"\t请输入第"<<n<<"个学生信息:\t"<<endl;  
  135.        s[n].set();  
  136.       cout<<"是否要继续录入学生信息(Y/N):";  
  137.       cin>>sel;  
  138.   }while(sel=='Y' || sel=='y' );   
  139. }  
  140. void show()  
  141. {  
  142.     cout<<left; //设置输出左对齐  
  143.     cout<<setw(10)<<"学生学号"  
  144.         <<setw(10)<<"学生姓名"  
  145.         <<setw(13)<<"学生班级"  
  146.         <<setw(12)<<"语文成绩"  
  147.         <<setw(12)<<"数学成绩"  
  148.         <<setw(12)<<"英语成绩"  
  149.         <<endl;  
  150.     for(int i=1;i<=n;i++)  
  151.     {  
  152.         cout<<setw(10)<<s[i].num  
  153.             <<setw(10)<<s[i].name  
  154.             <<setw(13)<<s[i].class1  
  155.             <<setw(12)<<s[i].chinese  
  156.             <<setw(12)<<s[i].math  
  157.             <<setw(12)<<s[i].english<<endl;  
  158.     }  
  159.     cout<<endl;  
  160.   
  161. }  
  162.   
  163. void search()//查询  
  164. {   
  165.   
  166.     int a,b,i;char c[20];  
  167.     cout<<"请选择查询方式:"<<endl;  
  168.     cout<<"按学生姓名查询请按1"<<endl;  
  169.     cout<<"按学生学号查询请按2"<<endl;  
  170.     cin>>a;  
  171.     switch(a)  
  172.     {  
  173.     case 1:   
  174. {char sel;  
  175.   do{  
  176.         cout<<"请输入你要查的学生的姓名:"<<endl;  
  177.         cin>>c;  
  178.         for(i=1;i<=n;i++)  
  179.             if(strcmp(s[i].name,c)==0)  
  180.             {cout<<"你要查的学生信息为:"<<endl;  
  181.             cout<<"学生学号:"<<s[i].num<<endl<<"学生姓名:"  
  182.                 <<s[i].name<<endl<<"学生班级:"  
  183.                 <<s[i].class1<<endl<<"语文成绩:"  
  184.                 <<s[i].chinese<<endl<<"数学成绩:"  
  185.                 <<s[i].math<<endl<<"英语成绩:"  
  186.                 <<s[i].english<<endl;  
  187.             break;  
  188.             }  
  189.             else if(strcmp(s[i].name,c)!=0&&i==n)  
  190.             {cout<<"没有这个学生!"<<endl;break;}  
  191.         cout<<"是否要继续查询学生信息(Y/N):";  
  192.       cin>>sel;  
  193.     }while(sel=='Y' || sel=='y' );   
  194.     break;  
  195. }  
  196.     case 2:  
  197. {   char sel;  
  198.  do{  
  199.         cout<<"请输入你要查的学生的学号:"<<endl;  
  200.         cin>>b;  
  201.         for(i=1;i<=n;i++)  
  202.             if(s[i].num==b)  
  203.             {  
  204.             cout<<"你要查的学生信息为:"<<endl;  
  205.             cout<<"学生学号:"<<s[i].num<<endl<<"学生姓名:"  
  206.                 <<s[i].name<<endl<<"学生班级:"  
  207.                 <<s[i].class1<<endl<<"语文成绩:"  
  208.                 <<s[i].chinese<<endl<<"数学成绩:"  
  209.                 <<s[i].math<<endl<<"英语成绩:"  
  210.                 <<s[i].english<<endl;  
  211.             break;  
  212.             }  
  213.             else if(s[i].num!=b&&i==n)  
  214.             {cout<<"没有这个学生!请核对后再输入!"<<endl;break;}  
  215.         cout<<"是否要继续查询学生信息(Y/N):";  
  216.       cin>>sel;  
  217.     }while(sel=='Y' || sel=='y' );   
  218.     break;}  
  219.   
  220.     default:  
  221.         cout<<"您的输入有误!"<<endl;  
  222.     }  
  223.           
  224. }  
  225.   
  226. void change()  
  227. {  
  228.  {  char sel;  
  229.     int d,i,e,f,g=0;  
  230.  do{  
  231.         cout<<"请输入你要修改的学生的学号:"<<endl;  
  232.         cin>>d;  
  233.         for(i=1;i<=n;i++)  
  234.             if(s[i].num==d)  
  235.             {  
  236.             cout<<"你要修改的学生信息为:"<<endl;  
  237.             cout<<"学生学号:"<<s[i].num<<endl<<"学生姓名:"  
  238.                 <<s[i].name<<endl<<"学生班级:"  
  239.                 <<s[i].class1<<endl<<"语文成绩:"  
  240.                 <<s[i].chinese<<endl<<"数学成绩:"  
  241.                 <<s[i].math<<endl<<"英语成绩:"  
  242.                 <<s[i].english<<endl;  
  243.                 e=1;  
  244.             break;  
  245.             }  
  246.             else if(s[i].num!=d&&i==n)  
  247.             {cout<<"没有这个学生!请核对后再输入!"<<endl;  
  248.             e=0;break;}  
  249.             while(e==1)  
  250.         {   {cout<<"请输入该学生要修改的信息对应的数字:"<<endl;  
  251.             cout<<"学生学号:1"  
  252.                 <<'\t'<<"学生姓名:2"  
  253.                 <<'\t'<<"学生班级:3"  
  254.                 <<'\t'<<"语文成绩:4"  
  255.                 <<'\t'<<"数学成绩:5"  
  256.                 <<'\t'<<"英语成绩:6"<<endl;  
  257.             }  
  258.             cin>>f;  
  259.             switch(f)  
  260.             {case 1:cout<<"\t新的学生学号为:";  
  261.             cin>>s[i].num;break;  
  262.             case 2:cout<<"\t新的学生姓名为:";  
  263.             cin>>s[i].name;break;  
  264.             case 3:cout<<"\t新的学生班级为:";  
  265.             cin>>s[i].class1;break;  
  266.             case 4:cout<<"\t新的语文成绩为:";  
  267.             cin>>s[i].chinese;break;  
  268.             case 5:cout<<"\t新的数学成绩为:";  
  269.                 cin>>s[i].math;break;  
  270.             case 6:cout<<"\t新的英语成绩为:";  
  271.                 cin>>s[i].english;break;  
  272.             default:cout<<"您的输入有误,请重新输入!";  
  273.                 cin>>f;}  
  274.                 e=0;  
  275.                 g=1;  
  276.         }  
  277.             if(g==1)  
  278.             {   cout<<"修改成功!";}  
  279.         cout<<"是否要继续修改学生信息(Y/N):";  
  280.       cin>>sel;  
  281.     }while(sel=='Y' || sel=='y' );   
  282.   }  
  283.     
  284. }  
  285.   
  286. void add()  
  287. {  
  288. char sel;  
  289.   do  
  290.   {  
  291.       n++;  
  292.       cout<<"\n请输入第"<< n <<"个学生信息:\n";  
  293.       cout<<"\t学生学号:";  
  294.       cin>>s[n].num;  
  295.       cout<<"\t学生姓名:";  
  296.       cin>>s[n].name;  
  297.       cout<<"\t学生班级:";  
  298.       cin>>s[n].class1;  
  299.       cout<<"\t语文成绩:";  
  300.       cin>>s[n].chinese;  
  301.       cout<<"\t数学成绩:";  
  302.       cin>>s[n].math;  
  303.       cout<<"\t英语成绩:";  
  304.       cin>>s[n].english;  
  305.       cout<<"是否要继续添加学生信息(Y/N):";  
  306.       cin>>sel;  
  307.   }while(sel=='Y' || sel=='y' );   
  308.     
  309. }     
  310.     void del()  
  311. {  
  312.   
  313.         int j,i,k;char c[10],sel,y;  
  314.     do{  
  315.         cout<<"请输入你要删除的学生的姓名:"<<endl;  
  316.         cin>>c;  
  317.         for(i=1;i<=n;i++)  
  318.             if(strcmp(s[i].name,c)==0)  
  319.             {cout<<"你要删除的学生信息为:"<<endl;  
  320.             cout<<"学生学号:"<<s[i].num<<endl  
  321.                 <<"学生姓名:"<<s[i].name<<endl  
  322.                 <<"学生班级:"<<s[i].class1<<endl  
  323.                 <<"语文成绩:"<<s[i].chinese<<endl  
  324.                 <<"数学成绩:"<<s[i].math<<endl  
  325.                 <<"英语成绩:"<<s[i].english<<endl;  
  326.             cout<<"确认删除?(y/n):";  
  327.             cin>>y;  
  328.             if(y=='Y'||y=='y')  
  329.             {  
  330.             for(j=i;j<=n+1;j++)  
  331.             {  
  332.                 s[j]=s[j+1];  
  333.             }   k=1;  
  334.             }  
  335.             else   
  336.                 cout<<"删除失败!"<<endl;  
  337.           
  338.   
  339.             break;  
  340.             }  
  341.             else if(strcmp(s[i].name,c)!=0&&i==n)  
  342.             {cout<<"没有这个学生!请核对后再输入!"<<endl;  
  343.             k=0;break;}  
  344.             while(k==1)  
  345.             {  
  346.                 if(y=='Y'||y=='y')  
  347.                 cout<<"删除成功!";  
  348.                 n--;  
  349.                 k=0;  
  350.             }  
  351.         cout<<"是否要继续删除学生信息(Y/N):";  
  352.       cin>>sel;  
  353.       
  354.     }while(sel=='Y' || sel=='y' );   
  355.       
  356.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值