C++程序5

此程序为C++黑白界面上的学生信息管理系统

// student system.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
class student
{
public:
 char name[10];
 double score;
 int grade;
 class student *next;
};
student stu[30];


class password
{
public:
 char word[10];
};

password words[15]={"start","close","max","min","end","goon","appear","write","fzta","fatz","score","grade","name","open"};

int main()
{
 void snam();
 void max();
 void min();
 void za();
 void az();
 void score();
 void grade();
 void mulu();
 cout<<"a:start"<<endl;
 char a;
 cin>>a;
 if(a=='a')
 {
  mulu();
 }
 static int z=0;
 for(int i=0;i<999;i++)
 {
  char k[10];
  cin>>k;
  if(strcmp(k,words[0].word)==0 )
  {
   int i;
   int k;
         cout<<"the number of student: "<<endl;
   cin>>k;
   char p[10];
   cin>>p;
   if(strcmp(p,words[7].word)==0)
   {
    ofstream outfile("f1.dat",ios::in);
             if(!outfile)
    {
     cout<<"error";
    }
             cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
             for(i=0;i<k;i++)
             {
            z++;
            cin>>stu[i].name>>stu[i].score>>stu[i].grade;
            outfile<<stu[i].name<<" "<<stu[i].score<<" "<<stu[i].grade<<endl;
             }
   }
   else if(strcmp(p,words[13].word)==0)
   {
    ifstream infile("f1.dat",ios::in);
    if(!infile)
    {
     cout<<"error";
    }
             cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
             for(i=0;i<k;i++)
             {
               infile>>stu[i].name>>stu[i].score>>stu[i].grade;
               cout<<setw(8)<<stu[i].name<<setw(8)<<stu[i].score<<setw(8)<<stu[i].grade<<endl;
             }
   }
    
   else if(strcmp(p,words[6].word)==0)
   {
    cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
    for(int j=0;j<z;j++)
    {
     cout<<stu[j].name <<setw(8)<<stu[j].score <<setw(8)<<stu[j].grade <<endl;
    }
   }
   else if (strcmp(p,words[2].word)==0)
   {
    max();
    
   }
   else if (strcmp(p,words[8].word)==0)
   {
    za();
   }
   else if (strcmp(p,words[9].word)==0)
   {
    az();
   }
   else if (strcmp(p,words[11].word)==0)
   {
    grade();
   }
   else if (strcmp(p,words[10].word)==0)
   {
    score();
   }
   else if(strcmp(p,words[12].word)==0)
   {
    snam();
   }
   else if(strcmp(p,words[3].word)==0)
   {
    min();
   }
   else if(strcmp(p,words[5].word)==0)
   {
    continue;
   }
  }
  else if(strcmp(k,words[4].word)==0)
   break;
 }
 return 0;
}

void max()
{
 char name[10];
    double score,t;
    int grade;
    score=stu[0].score;
    strcpy(name,stu[0].name);
    grade=stu[0].grade ;
    cout<<"the number of students:";
    int k;
    int i;
    cin>>k;
    for(i=0;i<k;i++)
    {
     
      t=stu[i].score;
      if(score<t)
      {
       score=stu[i].score;
          strcpy(name,stu[i].name);
          grade=stu[i].grade ;
          }
     
    }
    cout<<"the max is:"<<endl;
    cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
    cout<<name<<setw(8)<<score<<setw(8)<<grade<<endl;
}

void min()
{
 char name[10];
    double score,t;
    int grade;
    int k;
    int i=0;
    score=stu[0].score;
    strcpy(name,stu[0].name);
    grade=stu[0].grade ;
    cout<<"the number of students:";
    cin>>k;
    for(i=0;i<k;i++)
    {
     t=stu[i].score;
     if(score>t)
     {
      score=stu[i].score;
      strcpy(name,stu[i].name);
      grade=stu[i].grade ;
     }
     
    }
    cout<<"the min is:"<<endl;
    cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
    cout<<name<<setw(8)<<score<<setw(8)<<grade<<endl;
}

void az()
{
 double score;
 char name[10];
 int i,j,k,grade;
 cout<<"the number of student: ";
 cin>>k;
 for(j=0;j<k-1;j++)
  for(i=0;i<k-1-j;i++)
   if(stu[i].score >stu[i+1].score )
   {
    score=stu[i].score ;
    stu[i].score =stu[i+1].score ;
    stu[i+1].score =score;
    grade=stu[i].grade ;
    stu[i].grade =stu[i+1].grade ;
    stu[i+1].grade =grade;
    strcpy(name,stu[i].name );
    strcpy(stu[i].name,stu[i+1].name );
    strcpy(stu[i+1].name,name);
   }
   cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
   for(i=0;i<k;i++)
    cout<<stu[i].name <<setw(8)<<stu[i].score <<setw(8)<<stu[i].grade <<endl;
}

void za()
{
 double score;
 char name[10];
 int i,j,k,grade;
 cout<<"the number of student: ";
 cin>>k;
 for(j=0;j<k-1;j++)
  for(i=0;i<k-1-j;i++)
   if(stu[i].score <stu[i+1].score )
   {
    score=stu[i].score ;
    stu[i].score =stu[i+1].score ;
    stu[i+1].score =score;
    grade=stu[i].grade ;
    stu[i].grade =stu[i+1].grade ;
    stu[i+1].grade =grade;
    strcpy(name,stu[i].name );
    strcpy(stu[i].name,stu[i+1].name );
    strcpy(stu[i+1].name,name);
   }
   cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
   for(i=0;i<k;i++)
    cout<<stu[i].name <<setw(8)<<stu[i].score <<setw(8)<<stu[i].grade <<endl;
}

void score()
{
 int k,j,t=0;
 int grade;
 double score;
 char name[10];
 cout<<"enter the score you want to search: ";
 cin>>k;
 cout<<"enter the number of student: ";
 cin>>j;
 cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
 for(int i=0;i<j;i++)
 {
  if(k==stu[i].score )
   {
    
    t++;
    cout<<stu[i].name <<setw(8)<<stu[i].score <<setw(8)<<stu[i].grade <<endl;
    
  }
 }
 if(t==0)
 {
  cout<<"no found"<<endl;
 }
}

void grade()
{
 
 int k,j,t=0;
 int grade;
 double score;
 char name[10];
 cout<<"enter the grade you want to search: ";
 cin>>k;
 cout<<"enter the number of student: ";
 cin>>j;
 cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
 for(int i=0;i<j;i++)
 {
  if(k==stu[i].grade )
   {
    t++;
    
    cout<<stu[i].name <<setw(8)<<stu[i].score <<setw(8)<<stu[i].grade <<endl;
    
  }
 }
  if(t==0)
  {
   cout<<"no found"<<endl;
  }
 
}

void snam()
{
 int j,t=0;
 int grade;
 double score;
 char name[10];
 char min[10];
 cout<<"enter the name you want to search: ";
 cin>>min;
 cout<<"enter the number of student: ";
 cin>>j;
 cout<<"name"<<setw(8)<<"score"<<setw(8)<<"grade"<<endl;
 for(int i=0;i<j;i++)
 {
  if(strcmp(min,stu[i].name)==0 )
   {
    t++;
    
    cout<<stu[i].name <<setw(8)<<stu[i].score <<setw(8)<<stu[i].grade <<endl;
    
  }
 }
  if(t==0)
  {
   cout<<"no found"<<endl;
  }
 
}

void mulu()
{
 cout<<"open:open       *close:close        *max:max            *min:min"<<endl;
 cout<<"end:end         *goon:continue      *appear:appear      *writte:write"<<endl;
 cout<<"fzta:za         *fatz:az            *score:score search *grade:grade search"<<endl;
 cout<<"name:name search*start:start"<<endl;
}

 

你可能感兴趣的:(C++程序5)