学生信息管理系统

时间:2022-10-30 17:37:42
#include <iostream>
#include<cstdlib>
using namespace std;
class Time
{
public :
   void m_set( );//公用成员函数
   void m_show( );//公用成员函数
   void m_give();
   void m_chushizhi();
   void m_zengtian();
   void m_chazhao();
   void m_paixu();
   void m_shanchu();
   void m_xiugai();
private : //数据成员为私有
     int n,t1,t2,t3,m;
  int num;
  char name[20];
  char sex;
  float score; 
}boy[1000];
void Time::m_chushizhi()
{
 t1=0;
 t2=0;
 t3=0;
}

void Time::m_xiugai()
{
 cout<<"请输入要修改的学生学号:";
 long long a;
 int x;
 cin>>a;
 for(x=0;x<t1;x++)
 {
  if(boy[x].num==a)
  break;
 }
 cout<<"请输入需要修改的信息:"<<endl;
 cin>>boy[x].num>>boy[x].name>>boy[x].sex>>boy[x].score;
 cout<<"修改成功,请按任意键返回主页面:";
 getchar();
 getchar();
 system("cls");
}
void Time::m_shanchu()
{
 cout<<"请输入要删除的学生学号:";
 long long a;
 int x;
 cin>>a;
 for( x=0;x<t1;x++)
 {
  if(boy[x].num==a)
  break;
 }
 for(;x<=t1-2;x++)
 {
  boy[x]=boy[x+1];
 }
 t1--;
 cout<<"学生信息已成功删除,请按任意键返回页面:";
 getchar();
 getchar();
 system("cls");
}

void Time::m_paixu()
{
 for(int i=1;i<t1;i++)
  for(int j=0;j<t1-i;j++)
   if(boy[j].score<boy[j+1].score)
   {
    boy[999]=boy[j+1];
    boy[j+1]=boy[j];
    boy[j]=boy[999];
   }
 cout<<"排序成功,请按任意键返回主页面:";
 getchar();
 getchar();
 system("cls");
}
void Time::m_chazhao()
{
 long long a;
 int i;
 cout<<"请输入学生学号:"; cin>>a;
 for( i=0;i<=t1;i++)
 {
  if(boy[i].num==a)
  {
   cout<<"查找成功:"<<endl;
   break;
  }
 }
 cout<<boy[i].num<<"       "<<boy[i].name<<"       "<<boy[i].sex<<"       "<<boy[i].score<<endl;
 cout<<"请按任意键返回主页面:";
 getchar();
 getchar();
 system("cls");
}

void Time::m_zengtian(){
 cout<<"请输入添加学生个数: ";  cin>>m;
 cout<<"请依次输入学号、姓名、性别、成绩。"<<endl;
 int a=t1;
 for(;   t1<a+m;   t1++)
 cin>>boy[t1].num>>boy[t1].name>>boy[t1].sex>>boy[t1].score;
 cout<<"信息已保存,请按任意键返回主页面:";
 getchar();
 getchar();
 system("cls");
}

void Time::m_set()
{
   cout<<"请输入录入信息的个数: ";
   cin>>n;
   cout<<"请依次输入学号、姓名、性别、成绩: "<<endl;
   for(int i=0;i<n;i++)
 {
  t1++;  
  cin>>boy[i].num>>boy[i].name>>boy[i].sex>>boy[i].score;
 }
    cout<<"信息已保存,请按任意键返回主页面:";
    getchar();
    getchar();
    system("cls");
}

void Time::m_give()
{
 cin>>n;
}

void Time::m_show() //在类外定义show_time函数
{
 cout<<"        -------------------------------------------------"<<endl;
 cout<<"         "<<"学号          "<<"姓名          "<<"性别          "<<"成绩"<<endl ;
 for(int i=0;i<t1;i++)
 {
  cout<<"        -------------------------------------------------"<<endl; 
  cout<<"         "<<boy[i].num<<"              ";
  cout<<boy[i].name<<"             "<<boy[i].sex<<"              "<<boy[i].score<<endl;
 }
  cout<<"        --------------------------------------------------"<<endl;
 cout<<"请按任意键返回主页面: ";
 getchar();
 getchar();
 system("cls");
}

int main()
{
    Time T;//定义对象t1
    T.m_chushizhi();
 int a1,a2,a3,a4;
     //system("pause");
       
     while(1)
{
 cout <<"                                                               " << endl;
    cout <<"                                   -------- 欢迎进入学生信息管理系统 ---------" << endl;
    cout <<"                                                               " << endl;
    cout << "                                                                         1.录入    学生信息      " << endl;
    cout << "                                                                         2.输出    学生信息      " << endl;
    cout << "                                                                         3.添加    学生信息      " << endl;
    cout << "                                                                         4.查找    学生信息      " << endl;
    cout << "                                                                         5.排序    学生信息      " << endl;
    cout << "                                                                         6.删除    学生信息      " << endl;
    cout << "                                                                         7.修改    学生信息      " << endl;
 cout << "                                                                         8.退出!      " << endl;
 cout <<"请输入对应数字进行操作:"<<endl;
 
     cin>>a1;
  switch(a1)
 {
  case 1:
       T.m_set( );
       continue;
  case 2:
      {
       T.m_show();
       continue;
   }
     case 3:
      {
       T.m_zengtian();
       continue;
   }
  case 4:
      {
       T.m_chazhao();
       continue;
   }
        case 5:
         {
           T.m_paixu();
           continue;
   }
  case 6:
   {
    T.m_shanchu();
    continue;
   }
  case 7:
   {
    T.m_xiugai();
    continue;
   }
  case 8:
  {
   return 0;
     }
 }
}
   return 0;
}