zoukankan      html  css  js  c++  java
  • 学生成绩管理系统(C++指针、链表、文件及面向对象的运用)

                                                                                       学生成绩管理系统

    功能页面显示:

      

    实现源码:

     1 #include<iostream>
     2 #include<fstream>
     3 #include<cstring>  
     4 #include<iomanip>
     5 #include<stdlib.h>
     6 #include<windows.h>
     7 using namespace std;
     8 //学生类 
     9 class Student
    10 {
    11     public:
    12         void inputStudent(Student *head);      //输入学生的信息 
    13         void outputStudent(Student *head);    //输出学生的信息 
    14         void deleteStudent(Student *head);   //删除学生的信息
    15         void addStudent(Student *head);     //添加学生的信息
    16         void changeStudent(Student *head); //修改学生的信息 
    17         void findStudent(Student *head);  //查找学生的信息 
    18         void paixuStudent(Student *head);//学生成绩排序 
    19         void saveStudent(Student *head); //保存学生的信息
    20         void loadStudent(Student *head);//加载学生的信息 
    21         void getcountStudent(Student *head);
    22         
    23         int       num;
    24         char    name[20];
    25         char      sex[4];
    26         float     Chinese;
    27         float     English;
    28         float     Math;
    29         float     sum;
    30         float     average;
    31         Student *next;
    32         
    33         private:
    34             
    35 };
     1 void Student ::inputStudent(Student *head)//输入学生的信息 
     2 {
     3     system("cls");
     4     Student *p1,*p2;
     5     
     6     p1=head;
     7     int N;
     8     cout<<"哈喽,小可爱,请输入学生的总人数"<<endl; 
     9     cin>>N;
    10     for(int i=0;i<N;i++)
    11     {
    12         p2= new Student ;
    13         p1->next=p2;
    14         p1=p1->next;
    15         cout<<"哈喽,小可爱,请输入学生的信息: "<<"学号 "<<"姓名 "<<"性别 " <<"语文 "<<"数学 "<<"英语 "<<endl; 
    16         cin>>p1->num>>p1->name>>p1->sex>>p1->Chinese>>p1->Math>>p1->English;
    17         p1->sum=p1->Chinese+p1->Math+p1->English;
    18         p1->average=(p1->sum)/3;
    19     }
    20     p1->next=NULL;
    21     cout<<"YES!输入成功"<<endl;
    22 }
     1 void Student ::outputStudent(Student *head)//浏览学生的信息 
     2 {
     3     system("cls");
     4     Student *p1,*p2;
     5 
     6     p1=head->next;
     7     int r=0;//名次 
     8     cout<<"学号	"<<"姓名	"<<"性别	"<<"语文"
     9     <<"	"<<"数学"<<"	"<<"英语"<<"	"<<"	"<<"平均分"<<"	"<<"	"<<"总分"
    10     <<"	"<<"	"<<"排名"<<endl; 
    11     while(p1!=NULL)
    12     {
    13         cout<<p1->num<<"	"<<p1->name<<"	"<<p1->sex<<"	"<<p1->Chinese<<"	"<<p1->Math<<"	"<<p1->English<<"	"<<"	";
    14         cout<<p1->average<<"	"<<"	";    
    15         cout<<p1->sum<<"	"<<"	";
    16         cout<<r+1<<endl;
    17         r++;
    18         p1=p1->next;
    19     }
    20     cout<<"YES!浏览成功"<<endl;
    21     
    22  } 
     1 void Student ::deleteStudent(Student *head)//删除学生的信息 
     2  {
     3      system("cls");
     4      
     5      Student *p1,*p2;
     6      char n;
     7      cout<<"哈喽,小可爱,请输入要删除的位置:"<<endl;
     8      cin>>n;
     9      int a;
    10      a=n-'0';
    11      if(a>=0)
    12      {
    13          if(a>=0 && a<=count)
    14          {
    15              p1=head;
    16              p2=p1->next;
    17              while(--a)
    18              {
    19                  p1=p1->next;
    20                  p2=p2->next;
    21              }
    22              p1->next=p2->next;
    23       
    24               cout<<"YES!删除成功"<<endl; 
    25          }
    26          else
    27           {
    28             cout<<"输入错误,请输入0-"<<count<<"之间的数字位置:" ;
    29            } 
    30      }
    31      else
    32      {
    33          cout<<"输入错误,请输入0-"<<count<<"之间的数字位置:" ;
    34      } 
    35  }
     1  void Student ::addStudent(Student *head)//添加学生的信息 
     2  {
     3      system("cls");
     4      Student *p1,*p2;
     5      Student *p3;
     6      char n;
     7      cout<<"哈喽,小可爱,请输入要添加的位置 "<<endl;
     8     cin>>n;
     9     int a;
    10     a=n-'0';
    11     if(a>0)
    12     {
    13         if(a>=0 && a<=count)
    14         {
    15             p1=head;
    16             p2=p1->next;
    17         while(--a)
    18         {
    19             p2=p2->next;
    20             p1=p1->next;
    21          
    22         }
    23          p3=new Student;
    24          cout<<"哈喽,小可爱,请输入你的信息 :"<<endl<<"学号 "<<"姓名 "<<"性别 "<<"语文 "<<"数学 "<<"英语 "<<endl;
    25      
    26          cin>>p3->num>>p3->name>>p3->sex>>p3->Chinese>>p3->Math>>p3->English; 
    27          p3->sum=p3->Chinese+p3->Math+p3->English;
    28         p3->average=(p3->sum)/3;
    29          p3->next=p2;
    30          p1->next=p3;
    31          cout<<"YES!添加成功 "<<endl;
    32         }
    33         else
    34         {
    35             cout<<"输入错误,请输入0-"<<count<<"之间的数字位置:" ;
    36         }
    37   }
    38   else
    39   {
    40     cout<<"输入错误,请输入0-"<<count<<"之间的数字位置:" ;
    41   }
    42 }
     1 void Student::changeStudent(Student *head)//修改学生的信息 
     2   {
     3       system("cls");
     4       
     5       Student *p1,*p2;
     6       Student *p3;
     7   
     8       char n;
     9       cout<<"哈喽,小可爱,请选择你要修改的位置 :"<<endl;
    10       cin>>n;
    11       int a;
    12       a=n-'0';
    13       if(a>0)
    14       {
    15           if(a>=0 && a<=count)
    16           {
    17               p1=head;
    18               p2=p1->next;
    19               while(--a)
    20               {
    21                   p1=p1->next;
    22                   p2=p2->next ;
    23               }
    24               cout<<"哈喽,小可爱,请输入你的信息 :"<<endl<<"学号 "<<"姓名 "<<"性别 "<<"语文 "<<"数学 "<<"英语 "<<endl;
    25      
    26              cin>>p2->num>>p2->name>>p2->sex>>p2->Chinese>>p2->Math>>p2->English; 
    27              p2->sum=p2->Chinese+p2->Math+p2->English;
    28              p2->average=(p2->sum)/3;
    29              cout<<"YES!修改成功"<<endl;
    30         
    31         }
    32         else
    33         {
    34             cout<<"输入错误,请输入0-"<<count<<"之间的数字位置:" ;
    35         }
    36       }
    37       else
    38       {
    39           cout<<"输入错误,请输入0-"<<count<<"之间的数字位置:" ;
    40       }
    41       
    42       
    43   }
     1 void Student::findStudent(Student *head)//查找学生的信息 
     2   {
     3       system("cls");
     4       Student *p1;
     5       int p;
     6       int i=0;
     7       int stunum;
     8       char stuname[5];
     9       p1=head->next;
    10       cout<<"请选择 1.按学号查找 2. 按姓名查找"<<endl; 
    11       cin>>p;
    12       if(p==1)
    13       {
    14           system("cls");
    15         cout<<"请输入要查找的学号 "<<endl;
    16         cin>>stunum;
    17         while(p1!=NULL)
    18         {
    19             if(stunum==p1->num)
    20             {
    21                 cout<<"学号	"<<"姓名	"<<"性别	"<<"语文"
    22                <<"	"<<"数学"<<"	"<<"英语"<<"	"<<"	"<<"平均分"<<"	"<<"	"<<"总分"
    23                 <<"	"<<"	"<<endl; 
    24                 cout<<p1->num<<"	"<<p1->name<<"	"<<p1->sex<<"	"<<p1->Chinese<<"	"<<p1->Math<<"	"<<p1->English<<"	"<<"	";
    25                 cout<<p1->average<<"	"<<"	";    
    26                  cout<<p1->sum<<"	"<<"	";               
    27             }
    28             p1=p1->next;
    29            }
    30         
    31          }else if(p==2)
    32        {
    33             system("cls");
    34         cout<<"请输入要查找的姓名 "<<endl;
    35         cin>>stuname;
    36         while(p1!=NULL)
    37         {
    38             if(strcmp(p1->name,stuname)==0)
    39             {
    40                     cout<<"学号	"<<"姓名	"<<"性别	"<<"语文"
    41                <<"	"<<"数学"<<"	"<<"英语"<<"	"<<"	"<<"平均分"<<"	"<<"	"<<"总分"
    42                 <<"	"<<"	"<<endl; 
    43                 cout<<p1->num<<"	"<<p1->name<<"	"<<p1->sex<<"	"<<p1->Chinese<<"	"<<p1->Math<<"	"<<p1->English<<"	"<<"	";
    44                 cout<<p1->average<<"	"<<"	";    
    45                  cout<<p1->sum<<"	"<<"	";
    46             }
    47             p1=p1->next;
    48         }
    49     }else
    50     {
    51         cout<<"输入选项错误 "<<endl;
    52     }
    53 
    54   } 
     1 void Student::paixuStudent(Student *head)//排序
     2 {
     3     Student *p1;
     4     Student *p2;
     5     p1=head;
     6     int n=0;
     7     int a=0;
     8     char b[20];
     9     int i,j;
    10     while(p1->next)
    11     {
    12         p1=p1->next ;
    13         n++;
    14     }
    15     for(i=0;i<n-1;i++)
    16     {
    17         p2=head->next;
    18         p1=p2->next;
    19         for(j=0;j<n-i-1;j++)
    20         {
    21            if(p1->average >p2->average )
    22             {
    23                 strcpy(b,p2->name);
    24                 strcpy(p2->name ,p1->name );
    25                 strcpy(p1->name,b);
    26                 
    27                 strcpy(b,p2->sex);
    28                 strcpy(p2->sex ,p1->sex);
    29                 strcpy(p1->sex,b);
    30         
    31                 a=p2->num ;
    32                 p2->num =p1->num ;
    33                 p1->num =a;
    34                 
    35                 a=p2->Chinese;
    36                 p2->Chinese=p1->Chinese;
    37                 p1->Chinese=a;
    38                 
    39                 a=p2->Math ;
    40                 p2->Math =p1->Math ;
    41                 p1->Math =a;
    42                 
    43                 a=p2->English ;
    44                 p2->English =p1->English ;
    45                 p1->English =a;
    46                 
    47                 a=p2->average;    
    48                 p2->average =p1->average ;
    49                 p1->average =a;
    50                 
    51                 a=p2->sum ;
    52                 p2->sum =p1->sum ;
    53                 p1->sum =a;
    54             }
    55             p1=p1->next;
    56             p2=p2->next;
    57         }
    58     }
    59     cout<<"YES!排序成功 "<<endl;
    60 }
     1 void Student::saveStudent(Student *head) //保存学生的信息 
     2 {
     3     Student *p;
     4     ofstream os;
     5     os.open("sco.txt");
     6 
     7     p=head->next ;
     8     while(p)
     9     {
    10        os<<p->num<<"	"<<p->name<<"	"<<p->sex<<"	"<<p->Chinese<<"	" <<p->Math<<"	" <<p->English <<"	"<<p->sum<<"	"<<p->average; 
    11         
    12         p=p->next;
    13         os<<endl;
    14     }
    15 
    16     cout<<"YES!保存成功 "<<endl; 
    17     os.close();
    18 }
     1 void Student:: loadStudent(Student *head)//加载学生的信息 
     2 {
     3     Student *p,*p2;
     4     ifstream is;
     5     is.open("sco.txt");
     6     
     7     
     8     p2=head;
     9     
    10     while(1)
    11     {
    12         p=new Student;
    13            is>>p->num>>p->name>>p->sex>>p->Chinese 
    14            >>p->Math>>p->English >>p->sum>>p->average;
    15            if(is.fail() )//判断是否到文件结尾 
    16            {
    17                delete p; 
    18                p2->next =NULL;
    19                break;
    20            }
    21            
    22         p2->next =p;
    23         
    24         p2=p2->next;    
    25     }
    26     
    27     cout<<"YES!加载成功 "<<endl;
    28 
    29     is.close();
    30     
    31     
    32 }
     1 int count;
     2 void Student::getcountStudent(Student *head)
     3 {
     4     Student *p;
     5     count=0;
     6     p=head;
     7     while(p->next!=NULL)
     8     {
     9         count++;
    10         p=p->next;
    11     }
    12 }
    13  
    14 void welcome()
    15 {
    16  cout<<"       ~~~    欢迎进入**学生成绩管理系统!   ~~~"<<endl;
    17  system("color 1");
    18 }
    19 void menu()
    20 {
    21  cout<<"      ******************************************"<<endl;
    22  cout<<"      ~~~~~~~   学生成绩管理系统  ~~~~~~~"<<endl;
    23  cout<<"      ******************************************"<<endl;
    24  cout<<"      ******************************************"<<endl;
    25  cout<<"      ******************************************"<<endl;
    26  cout<<"              ~~哈喽,小可爱,请选择你要进行的操作**" <<endl;        
    27  cout<<"              ~~1.    输入学生的信息          ~~"<<endl;
    28  cout<<"              ~~2.    浏览学生的信息          ~~"<<endl;
    29  cout<<"              ~~3.    删除学生的信息         ~~"<<endl;
    30  cout<<"              ~~4.    添加学生的信息          ~~"<<endl;
    31  cout<<"              ~~5.    修改学生的信息          ~~"<<endl;
    32  cout<<"              ~~6.    查找学生的信息          ~~"<<endl;
    33  cout<<"              ~~7.    排序学生的成绩          ~~"<<endl;
    34  cout<<"              ~~8.    保存学生的信息          ~~"<<endl;
    35  cout<<"              ~~9.    加载学生的信息          ~~"<<endl;
    36  cout<<"              ~~0.    退出学生信息系统        ~~"<<endl; 
    37  cout<<"       *****************************************"<<endl;
    38  cout<<"       *****************************************"<<endl;
    39  cout<<"       *****************************************"<<endl;
    40  system("color b");
    41 }
     1 int main()
     2 {
     3     Student h;
     4     system("cls"); 
     5     welcome();
     6     Sleep(1000);
     7     int i;
     8     Student *head=new Student;
     9     
    10     while(1)
    11     {
    12         system("cls");
    13         menu();
    14         cout<<"哈喽,小可爱,请输入你要进行的操作 :"<<endl;
    15         cin>>i; 
    16         switch(i)
    17         {
    18             case 1:  cout<<"输入学生的信息 "<<endl;h.inputStudent(head);system("pause");h.getcountStudent(head);break;
    19             case 2:  cout<<"浏览学生的信息 "<<endl;h.outputStudent(head);system("pause");h.getcountStudent(head);break;
    20             case 3:  cout<<"删除学生的信息 "<<endl;h.deleteStudent(head);system("pause");h.getcountStudent(head);break;
    21             case 4:  cout<<"添加学生的信息 "<<endl;h.addStudent(head);system("pause");h.getcountStudent(head);break;
    22             case 5:  cout<<"修改学生的信息 "<<endl;h.changeStudent(head);system("pause");h.getcountStudent(head);break;
    23             case 6:  cout<<"查询学生的信息 "<<endl;h.findStudent(head);system("pause");h.getcountStudent(head);break;
    24             case 7:  cout<<"学生成绩的排序 "<<endl;h.paixuStudent(head);system("pause");h.getcountStudent(head);break; 
    25             case 8:  cout<<"保存学生的信息 "<<endl;h.saveStudent(head);system("pause");h.getcountStudent(head);break;
    26             case 9:  cout<<"加载学生的信息 "<<endl;h.loadStudent(head);system("pause");h.getcountStudent(head);break;
    27             case 0:  cout<<"谢谢使用,欢迎下次光临 "<<endl;system("pause");exit(0);
    28              
    29             default: cout<<"输入错误"<<endl; 
    30         }
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    Poj 2017 Speed Limit(水题)
    Poj 1316 Self Numbers(水题)
    Poj 1017 Packets(贪心策略)
    Poj 1017 Packets(贪心策略)
    Poj 2662,2909 Goldbach's Conjecture (素数判定)
    Poj 2662,2909 Goldbach's Conjecture (素数判定)
    poj 2388 Who's in the Middle(快速排序求中位数)
    poj 2388 Who's in the Middle(快速排序求中位数)
    poj 2000 Gold Coins(水题)
    poj 2000 Gold Coins(水题)
  • 原文地址:https://www.cnblogs.com/zyx110/p/10619367.html
Copyright © 2011-2022 走看看