学生信息管理系统的代码

      从开学到现在,老师叫我们用C++编写了几个程序,现在贴一个上来,是关于学生信息管理的。其中代码的“骨架”是从网上找的,自己也加工了下,里面也有很多自己的心血,主要是增加了输入数据的合法性,还有变得更加人性化吧。代码如下:

 

# include <iostream>
# include <string.h>
# include <stdio.h>
# include <stdlib.h>
# include <fstream>
# include <conio.h>
using namespace std;

//*****定义一个学生原子的的数据结构*****//
struct stuatom
{
 char *name;
 int id;
 char sex;
 float math, eng, comp, totll, aver;
 void show();
 void setup();
};


//*********定义一系列对学生的操作**********//
class student
{
 private:
  stuatom ob[100];
  int stulen;
 public:
  student();
  void input();
  void order();
  void save();
  void check();
  void clean();
  void query();
  void read();
  void add();
  void del();
  void modify();
};

//********对学生数据的初始化(类的构造函数)**********//
student::student()
{
 //用for循环对全部数组中的数据初始化
 for(int i=0;i <100;i++)
 {
  ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0;
  ob[i].id =0;
  ob[i].sex =' ';
  ob[i].name =NULL;
 }
 this->stulen =0;
}


//********输入学生的数据,并判断是否在规定数据域内*******//
void stuatom::setup()
{
 char n[20]; char s;
 int b;

 //如果输入学号在数据域内,跳出循环并且赋值。
 //如果不在数据域内,一直循环到输入数据符合数据域为止
 do
 {
  cout<<" 学号(1001与1020之间): ";
  cin>>b;
  if(b>1020||b <1001)
  cout<<" 数据有误!!重新输入.."<<endl<<endl;
 }while (b <1001||b>1020);

 id=b;

 //如果输入姓名在数据域内,跳出循环并且赋值。
 //如果不在数据域内,一直循环到输入数据符合数据域为止
 do
 {
  name=new char[strlen(n)+1];
  cout<<" 姓名: ";
  cin>>n;
  /*if( strlen(n)>6 || strlen(n) <4 )
   cout<<"Bad data input!!" <<endl <<endl; */
 }while ( strlen(n)>6 && strlen(n) <4 );           //等于没判断

 strcpy(name,n);
 cout<<" 性别(m/f):" ;
 cin>>s;

 //如果输入性别在数据域内,跳出循环并且赋值。
 //如果不在数据域内,一直循环到输入数据符合数据域为止
 while (s!='m' && s!='f')
 {
  cout<<" 数据有误!!重新输入.."<<endl<<endl;
  cout<<" 性别(m/f):";
  cin>>s;
 } 

 sex=s;
 float m, e, co;
 cout<<" 数学(0-100): ";
 cin>>m;

 //如果输入成绩在数据域内,跳出循环并且赋值。
 //如果不在数据域内,一直循环到输入数据符合数据域为止
 while (m <0 || m>100)
 {
  cout<<" 数据有误!!重新输入.."<<endl<<endl;
  cout<<" 数学(0-100): ";
  cin>>m;
 }

 math=m;
 cout<<" 英语(0-100): ";
 cin>>e;

 while (e <0 || e>100)
 { 
  cout<<" 数据有误!!重新输入.."<<endl<<endl;
  cout<<" 英语(0-100): ";
  cin>>e;
 }

 eng=e;
 cout<<" C++(0-100): ";
 cin>>co;

 while (co <0 || co>100)
 {
  cout<<" 数据有误!!重新输入.."<<endl<<endl;
  cout<<" C++(0-100): ";
  cin>>co;
 }

 comp=co;
 totll=math+eng+comp;
 aver=(math+eng+comp)/3;
}

//*******按照规定格式把该学生的数据显示在屏幕上******//
void stuatom::show()
{
 cout.setf(ios::left);
 cout.width(6);
 cout<<""<<id<<"     ";
 cout.width(8);
 cout<<name;
 cout.width(10);
 cout<<sex;
 cout.width(9);
 cout<<math;
 cout.width(9);
 cout<<eng;
 cout.width(11);
 cout<<comp;
 cout.width(10);
 cout<<totll<<aver<<endl;
}

//**************输入学生的数据***********************//
void student::input()
{
 int n;
 cout <<endl <<" 输入将要录入的学生数目: ";
 cin>>n;
 int j,i;

 //通过循环输入要求输入学生个数的学生的数据。
 for(j=(this->stulen+1) ; j <=(this->stulen+n); j++)
 {
  cout <<" 输入学生信息 " <<j <<endl;
  ob[j-1].setup();
 }

 //检查学号是否有重复
 int a[100];
 int b=0,c=0,d;
 char Y;
 if(this->stulen!=0)
 {
  for (i=0;i<this->stulen ;i++)
  {
   for(j=this->stulen ;j<(this->stulen+n);j++)
   {
    if (ob[i].id==ob[j].id)
    {
     if (c==0)       //c只是为了美观而已。。
     {
      cout<<" 错误!系统检测到第"<<(j+1 )<<"位学生学号与第"<<(i+1)<<"位学生学号相同/n";
      a[b]=j;
      b++;c++;
     }
     else
     {
      cout<<"                 第"<<(j+1 )<<"位学生学号与第"<<(i+1)<<"位学生学号相同/n";
      a[b]=j;
      b++;c++;
     }
    }
   }
  }
  for(c=0;c<b;c++)
  {
   cout << " 是否重新输入第" << (a[c]+1)<< "位学生成绩?(Y/N--选N则第" << (a[c]+1)<<"位学生成绩将不保存)";
   cin>>Y;
   while(Y!='y'&& Y!='Y'&& Y!='N'&& Y!='n')
   {
    cout<<" 无效的命令,请重新输入../n";
    cout<<" 是否重新输入第"<<(a[c]+1)<<"位学生成绩?(Y/N--选N则第"<<(a[c]+1)<<"位学生成绩将不保存)";
    cin>>Y;
   }
   if(Y=='y'||Y=='Y')
   {
    d=a[c];
    ob[d].setup();
   }
   else
   {
    n--;
    for(d=a[c];d<(this->stulen+n);d++)
     ob[d]=ob[d+1];
    for(d=(c+1);d<b;d++)
     a[d]--;
   }
  }
 }
 else
 {
  for(i=0;i<n-1;i++)
  {
   for(j=i+1;j<n;j++)
   {
    if(ob[i].id==ob[j].id)
    {
     if (c==0)
     {
      cout<<" 错误!系统检测到第"<<(j+1)<<"位学生学号与第"<<(i+1)<<"位学生学号相同/n";
      a[b]=j;
      b++;c++;
     }
     else
     {
      cout<<"                 第"<<(j+1)<<"位学生学号与第"<<(i+1)<<"位学生学号相同/n";
      a[b]=j;
      b++;c++;
     }
    }
   }
  }
  for(c=0;c<b;c++)
  {
   cout << " 是否重新输入第" << (a[c]+1) << "位学生成绩?(Y/N--选N则第" << (a[c]+1)<<"位学生成绩将不保存)";
   cin>>Y;
   while(Y!='y'&& Y!='Y'&& Y!='N'&& Y!='n')
   {
    cout<<" 无效的命令,请重新输入../n";
    cout<<" 是否重新输入第"<<(a[c]+1)<<"位学生成绩?(Y/N--选N则第"<<(a[c]+1)<<"位学生成绩将不保存)";
    cin>>Y;
   }
   if(Y=='y'||Y=='Y')
   {
    d=a[c];
    ob[d].setup();
   }
   else
   {
    n--;
    for(d=a[c];d<n;d++)
     ob[d]=ob[d+1];
    for(d=(c+1);d<b;d++)
     a[d]--;
   }
  }
 }

 

 //学生数据显示格式
 system("cls");
 cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
 cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分" <<endl;

 //通过循环输出所有学生数据。
 for(j=this->stulen ; j <(this->stulen+n); j++)
 { 
  ob[j].show();
 }
 this->stulen+=n;     //学生个数赋值

 /*cout <<endl;
 cout <<" 是否保存? (Y/N): ";
 char Y;
 cin>>Y;
 system("cls"); */
}

//***********把学生成绩排序******************//
void student::query()
{
 int x;
 cout <<endl <<" 输入要查询学生的学号: ";
 cin>>x;
 
 int i;
 for(i=0;i <this->stulen ;i++)
 {
  if (x==ob[i].id)
   break;
  /*{
   cout <<"      学号     姓名    性别     数学    英语       C++       总分    平均分"  <<endl;
   cout.setf(ios::left);
   cout.width(6);
   cout <<"" <<ob[i].id <<"     ";
   cout.width(8);
   cout <<ob[i].name;
   cout.width(10);
   cout <<ob[i].sex;
   cout.width(9);
   cout <<ob[i].math;
   cout.width(9);
   cout <<ob[i].eng;
   cout.width(11);
   cout <<ob[i].comp;
   cout.width(10);
   cout <<ob[i].totll <<ob[i].aver <<endl;
  } */
 }
 if(i<this->stulen )
 {
  cout <<"      学号     姓名    性别     数学    英语       C++       总分    平均分"  <<endl;
  cout.setf(ios::left);
  cout.width(6);
  cout <<"" <<ob[i].id <<"     ";
  cout.width(8);
  cout <<ob[i].name;
  cout.width(10);
  cout <<ob[i].sex;
  cout.width(9);
  cout <<ob[i].math;
  cout.width(9);
  cout <<ob[i].eng;
  cout.width(11);
  cout <<ob[i].comp;
  cout.width(10);
  cout <<ob[i].totll <<ob[i].aver <<endl;
 }
 else
  cout<<" 没有找到该学生成绩...";
 _getch();
}
//*******************保存学生数据**************************//
void student::save()
{
 int i;
 ofstream outfile;
 outfile.open("list.txt",ios::trunc);
 if(!outfile)
 {
  cout <<" 无法打开数据文件!/n";
 }

 //通过循环把所有的学生数据保存在list.txt里边。
 for(i=0; i <this->stulen; i++)
 {
  outfile <<ob[i].id <<" " <<ob[i].name <<" " <<ob[i].sex <<" " <<
  ob[i].math <<" " <<ob[i].eng <<" " <<ob[i].comp <<" " <<ob[i].totll <<" " <<ob[i].aver <<endl;
 }
 outfile.close();
 ofstream outfile1;
 outfile1.open("stulen.txt",ios::trunc );
 outfile1<<this->stulen ;
 outfile1.close();
}


//********重新初始化********//
void student::clean()
{
 int i;
 char b[20];
 ifstream infile;
 infile.open("list.txt",ios::in);
 if(!infile)
 {
  for(int i=(this->stulen-1);i <100;i++)
  {
   ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0;
   ob[i].id =0;
   ob[i].sex =' ';
   ob[i].name =NULL;
  }
  this->stulen=0;
  ifstream infile1;
  infile1.open("stulen.txt",ios::in);
  infile1>>this->stulen ;
  infile1.close();
 }
 else
 {
  ifstream infile1;
  infile1.open("stulen.txt",ios::in);
  infile1>>this->stulen ;
  infile1.close();
  for(i=0;i<this->stulen ;i++)
  {
   infile>>ob[i].id;
   ob[i].name =new char[strlen(b)+1];
   infile>>b;
   strcpy(ob[i].name,b);
   infile>>ob[i].sex ;
   infile>>ob[i].math ;
   infile>>ob[i].eng;
   infile>>ob[i].comp;
   infile>>ob[i].totll;
   infile>>ob[i].aver ;
  }
  infile.close ();
 }
}
//*************显示所有学生数据*********************//
void student::read()
{
 int i;
 float averm,avere,averc;
 averm=avere=averc=0;
 //system("cls");
 cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
 cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分" <<endl;
 
 for(i=0; i <this->stulen; i++)
 {
  ob[i].show();
 }
 cout <<"/n/n/n";
 for(i=0; i <this->stulen; i++)
 {
  averm +=ob[i].math;
 }
 if(i!=0)
  cout <<"  数学平均成绩为" <<averm/i <<endl;
 /*else
  cout <<"  数学平均成绩为0" <<endl;*/
 for(i=0; i <this->stulen; i++)
 {
  avere +=ob[i].eng;
 }
 if(i!=0)
  cout <<"  英语平均成绩为" <<avere/i <<endl;
 /*else
  cout <<"  英语平均成绩为0" <<endl;*/
 for(i=0; i <this->stulen; i++)
 {
  averc +=ob[i].comp;
 }
 if(i!=0)
  cout <<"  C++平均成绩为" <<averc/i;
 /*else
  cout <<"  C++平均成绩为0" <<endl;*/
 _getch();

//*******************一个学生的数据****************//
void student::add()
{
 int i, d=this->stulen ;
 int c=0;
 cout <<" 输入要添加学生的信息:" <<endl;
 do
 {
  cout<<"/n";
  ob[d].setup();
  for(i=0;i<d;i++)
  {
   if(ob[i].id==ob[d].id )
   {
    cout<<" 系统检测到此次输入的学号和已有学生学号相同,请核实再输..";
    _getch();
    ob[d].math=ob[d].eng=ob[d].comp =ob[d].totll =ob[d].aver =0;
    ob[d].id =0;
    ob[d].sex =' ';
    ob[d].name =NULL;
    c=1;
    break;
   }
   else c=0;
  }
 }while(c!=0);
 
 cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
 cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分"  <<endl;

 for(i=0; i <=d; i++)
 {
  ob[i].show();
 }
 this->stulen++;

 ofstream fout("list.txt",ios::app);

 if(!fout)
 {
  cout <<" 无法打开数据文件!/n,";
 }

 //把添加的学生数据添加到list.txt里边去。
 fout <<ob[d].id <<" " <<ob[d].name <<" " <<ob[d].sex <<" " <<
 ob[d].math <<" " <<ob[d].eng <<" " <<ob[d].comp <<" " <<ob[d].totll <<" " <<ob[d].aver <<endl;

 fout.close();
 ofstream outfile1;
 outfile1.open("stulen.txt",ios::trunc );
 outfile1<<this->stulen ;
 outfile1.close();
 _getch();
}


//*********************删除指定名字学生的数据*******************//
void student::del()
{
 int i,p;
 int x;
 p=-1;
 if(this->stulen==0)
 {
  cout<<" 目前没有学生成绩!";
  _getch();
 }
 else
 {
  cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
  cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分" <<endl;
 
  for(i=0; i <this->stulen; i++)
  {
   ob[i].show();
  }
  char a;
  cout <<"/n/n 输入要删除的学生学号:" ;
  cin>>x;

  //通过for循环查找要删除学生的学号
  for(i=0; i <stulen; i++)
  {
   if(x==ob[i].id )
   {
    p=i; 
    cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分"  <<endl;
    cout <<"      " <<ob[i].id <<"       " <<ob[i].name <<"      " <<ob[i].sex <<"      " <<ob[i].math <<"      " <<ob[i].eng <<"      " <<ob[i].comp <<"       " <<ob[i].totll <<"       " <<ob[i].aver <<endl;
    break;
   }
   else
    continue;
  }
  if(p==-1)
  {
   cout<<" 没有此学生成绩!";
   _getch();
  }
  else
  {
   cout<<" 确定删除此学生成绩?<Y/N>";
   cin>> a;
   if (a=='y'|| a=='Y')
   {
    cout <<" 删除成功!" <<endl;
    /*cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
    cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分"  <<endl; */

    //删除了之后,应该把后面的数据往前移,把要删除的数据覆盖,并且学生长度减1
    stulen--;
    for(i;i <stulen;i++)
    {
     ob[i]=ob[i+1];
    } 
    ofstream outfile;
    outfile.open("list.txt",ios::trunc);
    for(i=0; i <this->stulen; i++)
    {
     outfile <<ob[i].id <<" " <<ob[i].name <<" " <<ob[i].sex <<" " <<
     ob[i].math <<" " <<ob[i].eng <<" " <<ob[i].comp <<" " <<ob[i].totll <<" " <<ob[i].aver <<endl;
    }
    outfile.close();
    ofstream outfile1;
    outfile1.open("stulen.txt",ios::trunc );
    outfile1<<this->stulen ;
    outfile1.close();
    this->read ();

  
    //_getch();
   }
   else
   {
    cout<<" 回到主界面...";
    _getch();
   }
  }
 }
}

//********************排序*****************//
void student::order()
{
 int k,j;
 float t; char n[20];
 cout <<" 成绩排名:" <<endl;
 cout <<" 姓名   总成绩   名次" <<endl;

 //排序算法。
 for(j = 0; j <=(stulen-2); j++)
 {
  for(k=j+1; k <=(stulen-1); k++)
  {
   if(ob[j].totll < ob[k].totll)
   {
    t = ob[j].totll;
    ob[j].totll = ob[k].totll;
    ob[k].totll = t;
    strcpy(n, ob[j].name);
    strcpy(ob[j].name, ob[k].name);
    strcpy(ob[k].name, n);
   }

  }
 }
 
 for(k=0; k <=(stulen-1); k++)
 {
  cout <<" ";
  cout.setf(ios::left);
  cout.width(9);
  cout <<ob[k].name;
  cout.width(9);
  cout <<ob[k].totll <<(k+1) <<endl;
 }   
 _getch();
}
//********修改学生信息********//
void student::modify()
{
 int a,i,p,b;
 p=-1;
 system("cls");
 cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
 cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分" <<endl;
 
 for(i=0; i <this->stulen; i++)
 {
  ob[i].show();
 }
    cout <<"/n/n 请输入要修改学生的学号:";
 cin>>a;
 for(i=0; i <stulen; i++)
 {
  if(a==ob[i].id)
  {
   p=i; 
   cout <<endl <<"      学号     姓名    性别     数学    英语     C++       总分    平均分"  <<endl;
   cout <<"      " <<ob[i].id <<"     " <<ob[i].name <<"      " <<ob[i].sex <<"      " <<ob[i].math <<"      " <<ob[i].eng <<"      " <<ob[i].comp <<"       " <<ob[i].totll <<"       " <<ob[i].aver <<endl;
   break;
  }
  else
   continue;
 }
 if(p==-1)
 {
  cout<<" 没有此学生成绩!";
  _getch();
 }
 else
 {
  cout<<"/n/n 请输入要修改的课程名的编号(1.数学, 2.英语,3.C++):";
  cin>>b;
  while(b!=1 &&b!=2 &&b!=3)
  {
    cout<<" 无效输入,请重新输入!/n";
    cout<<"/n/n 请输入要修改的课程名的编号(1.数学, 2.英语,3.C++):";
    cin>>b;
  }
  switch(b)
  {
   case 1:
    {
     float m;
     cout<<" 数学(0-100): ";
     cin>>m;

     //如果输入成绩在数据域内,跳出循环并且赋值。
     //如果不在数据域内,一直循环到输入数据符合数据域为止
     while (m <0 || m>100)
     {
      cout<<" 数据有误!!重新输入.."<<endl<<endl;
      cout<<" 数学(0-100): ";
      cin>>m;
     }

     ob[p].math=m;break;
    } 
   case 2:
    {
     float e;
     cout<<" 英语(0-100): ";
     cin>>e;

     while (e <0 || e>100)
     { 
      cout<<" 数据有误!!重新输入.."<<endl<<endl;
      cout<<" 英语(0-100): ";
      cin>>e;
     }

     ob[p].eng=e; break;
    }
   case 3:
    {
     float co;
     cout<<" C++(0-100): ";
     cin>>co;

     while (co <0 || co>100)
     {
      cout<<" 数据有误!!重新输入.."<<endl<<endl;
      cout<<" C++(0-100): ";
      cin>>co;
     }

     ob[p].comp=co;
    }
  } 
  ob[p].totll=ob[p].math+ob[p].eng+ob[p].comp;
  ob[p].aver=(ob[p].math+ob[p].eng+ob[p].comp)/3;
  ofstream outfile;
  outfile.open("list.txt",ios::trunc);
  for(i=0; i <this->stulen; i++)
  {
   outfile <<ob[i].id <<" " <<ob[i].name <<" " <<ob[i].sex <<" " <<
   ob[i].math <<" " <<ob[i].eng <<" " <<ob[i].comp <<" " <<ob[i].totll <<" " <<ob[i].aver <<endl;
  }
  outfile.close();
  cout<<" 成绩修改成功!回车返回主界面...";
  _getch();
 }
}
//***************程序运行前先检查以前是否有数据存在*****************//
void student::check()
{
 int i;
 char b[20];
 ifstream infile;
 infile.open("list.txt",ios::in );
 if(!infile)
 {
  cout<<" 系统没有检测到以前输入的数据,此次操作将建立一个新的数据文件...";
  _getch();
 }
 else
 {
  ifstream infile1;
  infile1.open("stulen.txt",ios::in);
  infile1>>this->stulen ;
  infile1.close();
  for(i=0;i<this->stulen ;i++)
  {
   infile>>ob[i].id;
   ob[i].name =new char[strlen(b)+1];
   infile>>b;
   strcpy(ob[i].name,b);
   infile>>ob[i].sex ;
   infile>>ob[i].math ;
   infile>>ob[i].eng;
   infile>>ob[i].comp;
   infile>>ob[i].totll;
   infile>>ob[i].aver ;
  }
  infile.close ();
  //学生数据显示格式
  system("cls");
  cout<<" 系统检测到以前输入过数据,数据内容如下:/n/n";
  cout <<endl <<"----------------------------- 学生信息表 ------------------------------------" <<endl;
  cout <<endl <<"      学号     姓名    性别     数学    英语       C++       总分    平均分" <<endl;

  //通过循环输出所有学生数据。
  for(i=0; i<this->stulen; i++)
  { 
   ob[i].show();
  }
  cout<<"/n/n/n";
  cout<<" 原始数据是否覆盖?(Y/N)";
  char q;
  cin>>q;
  while(q!='y'&& q!='Y'&& q!='N'&& q!='n')
  {
   cout<<" 无效的命令,请重新输入../n";
   cout<<" 原始数据是否覆盖?(Y/N)";
   cin>>q;
  }
  if(q=='y'||q=='Y')
  {
   for(int i=0;i <100;i++)
   {
    ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0;
    ob[i].id =0;
    ob[i].sex =' ';
    ob[i].name =NULL;
   }
   this->stulen =0;
   ofstream outfile1;
   outfile1.open("stulen.txt",ios::trunc);
   outfile1<<this->stulen ;
   outfile1.close();
   system("del list.txt");
  }
 /* else*/
 }
}
//**************按照一定格式显示所要查询学生的信息。**************//
void menu()
{
 cout <<"/n/n";
 cout <<"------------------ 学生成绩系统 -----------------" <<endl <<endl;
 cout <<"/t1.录入与保存学生成绩:/n";
 cout <<"/t2.读取学生成绩:/n";
 cout <<"/t3.删除学生成绩:/n";
 cout <<"/t4.追加学生成绩:/n";
 cout <<"/t5.查询学生成绩:/n";
 cout <<"/t6.修改学生成绩:/n";
 cout <<"/t7.显示成绩名次./n";
 cout <<"/t8.退出系统....../n/n/n";
 cout <<"/t请选择要实现的功能: ";
}


//---------------------------------------------------------------------------------------
void main()
{
 student a;
 a.check();
 while(1)
 {
  int SEL;
  system("cls");
  menu();
  cin>>SEL;
  switch(SEL)
  {
   case 1:
    system("cls");
    a.input();
    cout <<endl;
    cout <<" 是否保存? (Y/N): ";
    char Y;
    cin>>Y;
    while(Y!='y'&& Y!='Y'&& Y!='N'&& Y!='n')
    {
     cout<<" 无效的命令,请重新输入../n";
     cout<<" 是否保存? (Y/N)";
     cin>>Y;
    }
    system("cls");
    if(Y=='y'||Y=='Y')
     a.save();
    else/* if(Y=='n'||Y=='N')*/
     a.clean();
    break;
   case 2:
    system("cls"); a.read(); break;
   case 3:
    system("cls"); a.del(); break;
   case 4:
    system("cls"); a.add();break;
   case 5:
    system("cls"); a.query();break;
   case 6:
    system("cls"); a.modify();break;
   case 7:
    system("cls"); a.order();break;
   case 8:
    /*cout <<endl <<"        按任意键退出.... ";
    _getch(); */
    exit(0);
   default:
    cout <<"        无效的命令!";
    _getch();
    break;
  }
 }
}

 

这段程序中个人感觉最重要的变量是stulen,一切程序的操作都离不开它,也希望有人可以提出更多的问题,让这个程序变得更完美。

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
vs2015+数据库,需要建的数据表如下: 1. “考试成绩管理系统用户登录”功能 具体要求: (1) 按照图示排列相应的控件,控件名称自定义,其中,界面中的图片可以不加; (2) 当输入正确的用户名和密码时,登录到主系统,如图所示,并且用户名或密码输入不正确时系统有所提示;当单击【取消】按钮时,用户名和密码被清空; (3) 程序中用到的数据库名为SCOREINFO,数据表名为userinfo,数据表结构如下图所示: (4) 数据表中的用户名和密码如下图。 2. 点击主窗体的“密码修改”菜单,完成“密码修改”功能,程序运行如下图所示: 具体要求: (1)此题必须使用数据库连接完成,原始密码必须为数据表里原有的数据,不使用数据库完成的为0分。 (2)需要建立数据库SCOREINFO及数据表userinfo,表的结构及数据第一部分的内容: (3)要有“原始密码输入错误”、“原始密码不能为空”及“两次输入密码不一致”的错误提示; (4)当单击【保存】按钮,新密码被更新到数据表中,不能更新的为0分; (5)单击【关闭】按钮,窗口关闭。 (6)3个Label;3个TextBox;2个Button 3. 完成“成绩查询”功能,程序运行如下图所示: 具体要求: (1) 按照图示排列相应的控件,界面下方是DataGridView控件; (2)程序用到的数据库名为SCOREINFO,数据表名为score,表结构如下: (3)完成的MainForm_Load事件处理程序:当加载窗体时,直接在窗体的dataGridView1控件中显示数据表的所有记录; (4)可以设查询条件:首先在组合框comboBox1中选择查询条件,并在textBox1中输入条件值(可以模糊查询,如按照姓名查询时,输入“王”,可以查所有姓王的同学的成绩),单击查询将结果显示在dataGridView1控件中。 (5)所需控件及属性:1个GroupBox,1个Label,Text为选择查询条件;1个ComboBox(Items:学号、姓名);1个TextBox;1个Button,Text为查询;1个DataGridView 4. 完成“课程信息修改”功能,程序运行如下图所示: 具体要求: (1)按照图示排列相应的控件,控件名称自定义,其中,程序刚开始运行时,“学分”和“课程编码”的文本框是只读的; (2)在数据库名为SCOREINFO中,创建数据表名为course,表结构如下: (3)当单击【查询】时,直接在窗体的dataGridView2控件中显示数据表的所有记录; (4)当选中DataGridView控件中的某一行记录时(DataGridView控件的Mouse_Click事件),“课程名字”、“学分”、“课程代码”文本框中分别显示该项对应的课程信息; (5)当选中某一行记录并单击【编辑】按钮时,【编辑】按钮变为【保存修改】,同时“学分”和“课程编码”的文本框恢复正常(ReadOnly属性为false);在文本框中修改相应的信息后单击【保存修改】,将修改后的数据更新到数据表中。 (6)所需控件及属性:1个GroupBox,3个Label;3个TextBox(textBox2属性ReadOnly为True,textBox3属性ReadOnly为True);2个Button;1个DataGridView 5. 完成“课程信息删除”功能,程序运行如下图所示: 具体要求: (1)按照图示排列相应的控件,控件名称自定义,其中,程序刚开始运行时,“学分”和“课程编码”的文本框是只读的; (2)数据表名为course,表结构同第4部分: (3)当单击【查询】时,直接在窗体的dataGridView控件中显示数据表的所有记录; (4)当选中DataGridView控件中的某一行记录时,“课程名字”、“学分”、“课程代码”文本框中分别显示该项对应的课程信息; (5)当选中某一行记录并单击【删除】按钮时,则该行从数据表中删除。 (6)所需控件:3个Label;3个TextBox(textBox2属性ReadOnly为True,textBox3属性ReadOnly为True);2个Button;1个DataGridView 6. 完成“课程信息添加”功能,程序运行如下图所示: 具体要求: (1)按照图示排列相应的控件,控件名称自定义; (2)程序用到的数据库和数据表名为course,表结构如下同第四部分: (3)当单击【查询】时,直接在窗体的dataGridView1控件中显示数据表的所有记 (4)当选中DataGridView控件中的某一行记录时,“课程名字”、“学分”、“课程代码”文本框中分别显示该项对应的课程信息; (5)当单击【添加】按钮时,在文本框中添加新的内容并将新内容添加到数据表中,并且在DataGridView控件中显示出新的课程信息 (6)所需控件:3个Label;3个TextBox;2个Button;1个DataGridView
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值