zoukankan      html  css  js  c++  java
  • 学生成绩管理系统C++

    今天晚上终于做完了学生成绩管理系统!激动!开心!!!哈哈哈~~~~

    总共298行代码,第一次写这么多。

    其中遇到了好多困难,也烦恼了好久,不过最终都解决了!

    做了之后果然,满满的成就感!抑制不住的兴奋,特此纪念一下!

    可能还有些小问题,,,不过已经很开心啦,啦啦啦~~~

      1 #include<iostream>
      2 #include<iomanip> 
      3 
      4 using namespace std;
      5 void menu();//菜单函数 
      6 int choice(int x); //选项函数 
      7 void Input(float stu[],int &num);//1.输入成绩函数 
      8 void Output(float stu[],int &num);//2.输出成绩函数
      9 void Order(float stu[],int &num);//3.排序函数 
     10 void Search(float stu[],int &num);//4.查找学生函数 
     11 void Insert(float stu[],int &num);//5.插入学生函数 
     12 void Delete(float stu[],int &num);//6.删除学生函数 
     13 void Statistical_number(float stu[],int &num);//7.统计各分数段人数函数 
     14 
     15 
     16 const int MAX_STUDENT_NUM=40;//班级人数 
     17 float stu[MAX_STUDENT_NUM];
     18 int currentN=0;    
     19 
     20 int main()
     21 {
     22     menu(); 
     23     int x;
     24     cin>>x;
     25     choice(x);
     26     //菜单循环 
     27     while (x!=0)
     28     {
     29          
     30         menu();
     31         cin>>x;
     32         choice(x);
     33     }
     34 }
     35 
     36 
     37 //菜单 
     38 void menu()
     39 {
     40     cout<<"													
    ";
     41     cout<<"			欢迎使用成绩管理系统	
    ";
     42     cout<<"		=========================================
    ";
     43     cout<<"		1.录入学生            2.显示信息
    ";
     44     cout<<"		3.排序总评            4.查找学生
    "; 
     45     cout<<"		5.插入学生            6.删除学生
    ";
     46     cout<<"		7.统计人数            0.退出
    ";
     47     cout<<"		=========================================
    ";
     48     cout<<"请从0-7中选择一个数:";
     49 }
     50 
     51 //选项 
     52 int choice(int x)
     53 {
     54     
     55     switch (x)
     56         {
     57             case 0:return 0;
     58             case 1:cout<<"你选择了 录入学生"<<endl;
     59                    Input(stu,currentN); 
     60                    break; 
     61             case 2:cout<<"你选择了 显示信息"<<endl;
     62                    Output(stu,currentN);
     63                    break; 
     64             case 3:cout<<"你选择了 排序总评"<<endl;
     65                    Order(stu,currentN);
     66                    break; 
     67             case 4:cout<<"你选择了 查找学生"<<endl;
     68                    Search(stu,currentN);
     69                    break; 
     70             case 5:cout<<"你选择了 插入学生"<<endl;
     71                    Insert(stu,currentN);
     72                    break; 
     73             case 6:cout<<"你选择了 删除学生"<<endl;
     74                    Delete(stu,currentN);
     75                    break; 
     76             case 7:cout<<"你选择了 统计人数"<<endl;
     77                    Statistical_number(stu,currentN);
     78                    break;
     79             default:cout<<"输入非法,请重新输入!
    "<<endl;break; 
     80         }
     81 }
     82 
     83 
     84 //1.输入成绩
     85 void Input(float stu[],int &num)
     86 {
     87     char a;
     88     while(1)
     89     {
     90         int temp=num;
     91         if(temp>=MAX_STUDENT_NUM)
     92         {
     93             cout<<"人数已达到上限,无法再输入!"<<endl;
     94             break;
     95         }
     96         cout<<"请输入成绩(0-100):"<<endl;
     97         cin>>stu[num];
     98         if(stu[num]<0 || stu[num]>100)
     99         {
    100             cout<<"输入错误!成绩应该在0到100之间!"<<endl;
    101             continue; 
    102         }
    103         cout<<"是否继续输入学生数据请按Y或N:"<<endl;
    104         cin>>a;
    105         num++;
    106         if(a=='y'||a=='Y')
    107         {
    108             
    109             if(num>=MAX_STUDENT_NUM)
    110             {    
    111                 cout<<"人数已达到上限,无法再输入!"<<endl;
    112                 break;
    113             }
    114         }
    115         else if(a=='n'||a=='N')
    116         {
    117             break;
    118         }
    119     }
    120 }
    121 
    122 
    123 //2.输出显示信息 
    124 void Output(float stu[],int &num)
    125 {
    126     cout<<"成绩信息如下:"<<endl; 
    127     for(int i=0;i<num;i++) 
    128     {
    129         cout<<fixed<<setprecision(1)<<setw(5)<<stu[i]<<' '; 
    130     } 
    131 }
    132 
    133 
    134 //3.排序 
    135 void Order(float stu[],int &num)
    136 {
    137     for(int i=0;i<num-1;i++)
    138     for(int i=0;i<num-1;i++)
    139     {
    140         for(int j=0;j<num-i;j++)
    141         {
    142             if(stu[i]>stu[i+1])
    143             { 
    144                 float temp=stu[i];
    145                 stu[i]=stu[i+1];
    146                 stu[i+1]=temp;
    147             }
    148         }
    149     }
    150     Output(stu,num);
    151 } 
    152 
    153 
    154 //4.查找 
    155 void Search(float stu[],int &num)
    156 {
    157     int x,i,j=0,n=1,counter=1;
    158     char a;
    159     while(1)
    160     {
    161     
    162     cout<<"请输入你要查找的成绩:"; 
    163     cin>>x;
    164     for(i=0;i<num;i++)
    165     {     
    166         j++;
    167     }
    168     for(i=0;i<=j;i++)
    169     {
    170         
    171         if(x==stu[i])
    172         {
    173             cout<<"查找到第"<<counter<<"个相符的成绩"<<fixed<<setprecision(1)<<stu[i]<<endl;
    174             n=0;counter++;
    175         } 
    176     }
    177     if(n)
    178         cout<<"没有该学生信息!"<<endl;
    179         
    180     cout<<"是否继续查找请按Y或N:"<<endl;
    181     cin>>a;
    182     if(a=='y'||a=='Y')
    183     {
    184         counter=1; 
    185         continue;
    186     }
    187     else if(a=='n'||a=='N')
    188     {
    189         break;
    190     }
    191     
    192         
    193     }
    194 }
    195 
    196 
    197 //5.插入 
    198 void Insert(float stu[],int &num)
    199 {
    200     char a;
    201     while(1)
    202     {
    203         int temp=num;
    204         if(temp>=MAX_STUDENT_NUM)
    205         {
    206             cout<<"人数已达到上限,无法再输入!"<<endl;
    207             break;
    208         }
    209         cout<<"请输入插入的成绩(0-100):"<<endl;
    210         cin>>stu[num];
    211         if(stu[num]<0 || stu[num]>100)
    212         {
    213             cout<<"数据不符合要求!请重新输入!"<<endl;
    214             continue; 
    215         }
    216         cout<<"是否继续输入学生数据请按Y或N:"<<endl;
    217         cin>>a;
    218         num++;
    219         if(a=='y'||a=='Y')
    220         {
    221             if(num>=MAX_STUDENT_NUM)
    222             {    
    223                 cout<<"人数已达到上限,无法再输入!"<<endl;
    224                 break;
    225             }
    226         }
    227         else if(a=='n'||a=='N')
    228         {
    229             break;
    230         }
    231     }
    232 }
    233 
    234 
    235 //6.删除
    236 void Delete(float stu[],int &num)
    237 {
    238     float x;
    239     char a;
    240     int counter=1,n=0,temp=num;
    241     while(1)
    242     {
    243     
    244     cout<<"请输入要删除的数据:"<<endl;
    245     cin>>x;
    246     for(int i=0;i<num;i++)
    247     {
    248         if(x==stu[i])
    249         {
    250             for(int j=i;j<num;j++)
    251                 stu[j]=stu[j+1];
    252             num--;i--;n=1;
    253         }
    254     }
    255     if(n)
    256     {
    257         n=0;
    258         cout<<x*1.0<<"分学生信息删除成功!"<<endl;
    259     }
    260     else
    261         cout<<"没有该学生!"<<endl;
    262     
    263     cout<<"是否继续删除其他学生请按Y或N:"<<endl;
    264     cin>>a;
    265     if(a=='y'||a=='Y')
    266     {
    267         continue;
    268     }
    269     else if(a=='n'||a=='N')
    270     {
    271         Output(stu,num);
    272         break;
    273     }
    274     
    275     }
    276 } 
    277 
    278 
    279 //7.统计各分数段人数 
    280 void Statistical_number(float stu[],int &num)
    281 {
    282     int a=0,b=0,c=0,d=0,e=0;
    283     for(int i=0;i<num;i++)
    284     {
    285         if(stu[i]>=90)
    286             a++;
    287         else if(stu[i]>=80)
    288             b++;
    289         else if(stu[i]>=70)
    290             c++;
    291         else if(stu[i]>=60)
    292             d++;
    293         else 
    294             e++;
    295     }
    296     cout<<"100^90    89^80    79^70    69^60    <60"<<endl;
    297     cout<<a<<"    "<<b<<"    "<<c<<"    "<<d<<"    "<<e<<endl;
    298 } 
    学生成绩管理系统
  • 相关阅读:
    [C++] static member variable and static const member variable
    [C++] const inside class VS const outside class
    [C++] OOP
    [C++] Function Template
    [C++] right value reference
    [C++] advanced reference
    [C++] const and char*
    [C++] c Struct VS c++ Struct
    [C++] decltype(auto) C++ 11 feature
    easyui-validatebox 的简单长度验证
  • 原文地址:https://www.cnblogs.com/huerxiong/p/6787618.html
Copyright © 2011-2022 走看看