| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1491 人关注过本帖
标题:用C++编程学生成绩管理系统,大部分已经做出来了,还想加入一个计算每位学生 ...
只看楼主 加入收藏
柳叶随迁
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-5-8
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
用C++编程学生成绩管理系统,大部分已经做出来了,还想加入一个计算每位学生的平均成绩。应该怎么修改呢?
#include <iostream>
#include <fstream>
#include<cstring>
#include<conio.h>
#include <ctime>
using namespace std;
struct Class
{   int Chinese;
    int Math;
   
};
class Student{
public:
    Student();
    void Ofile(ofstream &of);                 
    void Infile(ifstream &f);               
    void Out();                                                
    void Set(char *name,int no,Class score);
    char *GetName();                        
    int  GetNo();                        
    Student *Next;                           
protected:
    char Name[20];                          
    int No;   
    Class Score ;
};
Student::Student():Next(0){}                  
char *Student::GetName(){return Name;}        
int Student::GetNo(){return No;}
void Student::Set(char *name,int no,Class score)
{    strcpy(Name,name);
    No=no;
    Score=score;
}
void Student::Infile(ifstream &f)
{    f>>Name>>No>>Score.Chinese>>Score.Math;    //将数据输入到文件                  
}
void Student::Ofile(ofstream &of)
{    of<<" "<<Name<<" "<<No<<" "<<Score.Chinese<<" "<<Score.Math;          //从文件中提取数据
}
void Student::Out()
{ cout<<Name<<"\t"<<No<<"\t"<<Score.Chinese<<"\t\t"<<Score.Math<<"\t"<<endl;
}
class Function                             //功能类                  
{public:
    Function();                            //构造函数
    ~Function();                          //析构函数
    void Menu();                          //菜单函数
    void Add();                           //录入学生成绩函数
    void Search();                        //查询学生成绩函数
    void Delete();                         //删除学生成绩函数
    void Modify();                         //修改学生成绩函数
    void Show();                           //显示学生成绩函数
private:
    Student *Student_First;                        
    void Read();                           //读取学生成绩函数
    void Save();                           //保存学生成绩信息函数
};
Function::Function()
{    Student_First=new Student;                             
    Read();
}  
Function::~Function()
{    delete Student_First;            
}
void Function::Add()                           //录入学生成绩信息函数
{    char name[20];
    int no;   
    Class score;
    char choose;                           
    Student *f1,*p,*f2;                        
    system("cls");
    f1=Student_First;
    f2=Student_First->Next;
    while(f1->Next)
        f1=f1->Next;                  
    do
    {  p=new Student;
        cout<<"请输入您要添加的学生成绩信息:"<<endl;
        cout<<"请输入学生姓名:";
        cin>>name;
        while(f2)
        {    if(strcmp(f2->GetName(),name)==0)
            {    cout<<"该学生已存在,请确定姓名!\n\n";
                cout<<"请输入姓名:";
               cin>>name;
                break;
            }
            f2=f2->Next;
        }
        cout<<"请输入学号:";
        cin>>no;                                      
        cout<<"请输入语文成绩:";
       cin>>score.Chinese;
        cout<<"请输入数学成绩:";
       cin>>score.Math;
        
        p->Set(name,no,score);
        f1->Next=p;                  
        p->Next=NULL;
        f1=f1->Next;
        cout<<"是否继续输入信息?(Y\\N) "<<endl;
        cin>>choose;
        }while(choose=='y'||choose=='Y');
    Save();
    cout<<"1.返回主菜单"<<endl;
    cin>>choose;
    while(choose!='1')
    {    cout<<"1.返回主菜单"<<endl;
        cin>>choose;
    }
    Menu();
}
void Function::Delete()           //删除信息函数
{     char name[20];               
    int no;
    char choose;
    Student *temp,*p;
    system("cls");
    p=temp=Student_First->Next;
    cout<<"请输入姓名:";
    cin>>name;
    cout<<"输入学号:";
    cin>>no;
    while(temp)
    { if(strcmp(temp->GetName(),name)==0&&temp->GetNo()==no)  //判断该学生信息是否存在
        {      cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
               temp->Out();
               cout<<"\n是否删除(Y/N)";
              cin>>choose;
            if(choose=='y'||choose=='Y')
            {    p->Next=temp->Next;
                delete temp;
                cout<<"删除成功:\n";
            }
               break;                    
        }
        p=temp;
        temp=temp->Next;
    }
    Save();                                    
    cout<<"1.返回主菜单\n2.继续删除"<<endl;
    cin>>choose;                              
    while(choose!='1'&&choose!='2')
    {    cout<<"1.返回主菜单\n2.继续删除"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();                              
    else if(choose=='2')
        Delete();                    
}
void Function::Modify()                 //修改学生信息函数
{    char choose,name[20];               
    Student *temp,*p;                           
    int no;
    Class score;
    system("cls");
    temp=p=Student_First;
    cout<<"请输入您要修改的学生姓名:";
    cin>>name;
    while(temp)
    {    if(strcmp(temp->GetName(),name)==0)         
        {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
            temp->Out();
            cout<<"请输入姓名:";
             cin>>name;                                   
            cout<<"请输入学号:";
            cin>>no;                                      
            cout<<"请输入语文成绩:";
            cin>>score.Chinese;                                       
            cout<<"请输入数学成绩:";
           cin>>score.Math;
            
           temp->Set(name,no,score);
            break;
        }
        temp=temp->Next;                           
    }
    Save();
    cout<<"修改成功!"<<endl;
    cout<<"1.返回主菜单\n2.继续修改"<<endl;
    cin>>choose;
    while(choose!='1'&&choose!='2')
    {     cout<<"1.返回主菜单\n2.继续修改"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();
    else if(choose=='2')
        Modify();
}
void Function::Read()                       //读取信息函数
{    Student *p,*p2;
    p=Student_First;                           
  long  t;
    ifstream is("Student.txt",ios::in);         
    if(!is)                             
    {   ofstream os("Student.txt",ios::out);     
        os.close();                        
        return ;
    }
    while(!is.eof())
    {   p2=new Student;                  
        p2->Infile(is);
        p->Next=p2;                     
        p2->Next=NULL;                  
         p=p->Next;
    }
}
void Function::Save()                                 //保存学生成绩信息函数
{    ofstream of("Student.txt",ios::out);         
    Student *p=Student_First->Next;                     
    while(p)
    {    p->Ofile(of);                       
        p=p->Next;                     
    }
    of.close();
}
void Function::Search()                       
{    int flag(0);                           
    char choose;                          
    char t1[20];
    int t2;
    system("cls");
    Student *temp=Student_First->Next;            
    do
    {   cout<<"输入查询方式:\n1.按姓名查询\n2.按学号查询\n";
        cin>>choose;
        if(choose=='1')
        {    cout<<"请输入您要查询的姓名:";
            cin>>t1;   
            while(temp)
            {    if(strcmp(t1,temp->GetName())==0)        
                {    flag=1;   
                    break;
                }
                temp=temp->Next;         
            }
            if(flag==0)
                cout<<"\n无该学生的信息\n"<<endl;
            else
            {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
                temp->Out();
            }
            break;
        }
        else if(choose=='2')
        {    cout<<"请输入您要查询的学号";
            cin>>t2;
            while(temp)
            {    if(t2==temp->GetNo())        
                {    flag=1;                    
                    break;
                }
                temp=temp->Next;         
            }
            if(flag==0)
                cout<<"\n无该学生的信息\n"<<endl;
            else
            {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
                temp->Out();
               }
            break;
        }
    }while(choose!='1'||choose!='2');
    cout<<"\n1.返回主菜单\n2.继续查询"<<endl;
    cin>>choose;
    while(choose!='1'&&choose!='2')
    {    cout<<"1.返回主菜单\n2.继续查询"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();               
    else if(choose=='2')
         Search();               
}
void Function::Show()        
{    char choose;
    Student *temp;
    system("cls");
    temp=Student_First->Next;         
    if(!temp)                  
    {    cout<<"文件无数据\n\n "<<endl;
        cout<<"1.返回主菜单"<<endl;
        cin>>choose;
         while(choose!='1')
         {      cout<<"1.返回主菜单"<<endl;
             cin>>choose;
         }
        Menu();           
    }
    else
    {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
        while(temp!=NULL)
        {     temp->Out();
            temp=temp->Next;                     
        }
    }
    cout<<"1.返回主菜单"<<endl;
    cin>>choose;
    while(choose!='1')
    {    cout<<"1.返回主菜单"<<endl;
        cin>>choose;
    }
    Menu();                     
}
void Function::Menu()
{   time_t t;
    time(&t);
    char choose;               
    system("cls");
    cout<<" ------------------------版权所有:张嘉铎-------------------------"<<endl;
    cout<<endl;
    cout<<"***********************************************************"<<endl;
    cout<<"              武汉工程大学                  "<<endl<<endl;
    cout<<"             学生成绩信息管理系统                     "<<endl<<endl;
    cout<<" 显示系统时间和日期:      "<<ctime(&t)<<endl;
    cout<<"*********************************************************"<<endl<<endl;
    cout<<"请选择您需要的操作,选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
    cout<<"\n";
      cout<<"        1 录入学生成绩信息:\n"<<endl;
    cout<<"        2 查询学生成绩信息:\n"<<endl;
    cout<<"        3 删除学生成绩信息:\n"<<endl;
    cout<<"        4 修改学生成绩信息:\n"<<endl;
    cout<<"        5 显示全部学生成绩信息:\n"<<endl;
    cout<<"        6 退出系统"<<endl;
    cout<<"\n";
    cin>>choose;
    switch(choose)
{    case '1': Add();break;                 
    case '2': Search();break;
    case '3': Delete();break;
    case '4': Modify();break;
    case '5': Show();break;
    case '6': exit(1);break;   
    default:
        {    cout<<"请按规定输入选择项!"<<endl;
            Menu();
        }
    }
}
void main()
{    Function function;          //定义功能接口
    function.Menu();            //调用主菜单
}
搜索更多相关主题的帖子: 管理系统 Chinese include public 
2015-05-08 16:26
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:20 
#include <iostream>
#include <fstream>
#include<cstring>
#include<conio.h>
#include <ctime>
#include<cstdlib>
using namespace std;
struct Class
{   int Chinese;
    int Math;
   
};
class Student{
public:
    Student();
    void Ofile(ofstream &of);                 
    void Infile(ifstream &f);               
    void Out();                                             
    void Set(char *name,int no,Class score);
    char *GetName();                        
    int  GetNo();   
    Class getScore(){
        return Score;
    }                    
    Student *Next;                           
protected:
    char Name[20];                          
    int No;   
    Class Score ;
};
Student::Student():Next(0){}                  
char *Student::GetName(){return Name;}        
int Student::GetNo(){return No;}
void Student::Set(char *name,int no,Class score)
{    strcpy(Name,name);
    No=no;
    Score=score;
}
void Student::Infile(ifstream &f)
{    f>>Name>>No>>Score.Chinese>>Score.Math;    //将数据输入到文件                  
}
void Student::Ofile(ofstream &of)
{    of<<" "<<Name<<" "<<No<<" "<<Score.Chinese<<" "<<Score.Math;          //从文件中提取数据
}
void Student::Out()
{ cout<<Name<<"\t"<<No<<"\t"<<Score.Chinese<<"\t\t"<<Score.Math<<"\t"<<endl;
}
class Function                             //功能类                  
{public:
    Function();                            //构造函数
    ~Function();                          //析构函数
    void Menu();                          //菜单函数
    void Add();                           //录入学生成绩函数
    void Stat();                          //统计平均成绩
    void Search();                        //查询学生成绩函数
    void Delete();                         //删除学生成绩函数
    void Modify();                         //修改学生成绩函数
    void Show();                           //显示学生成绩函数
private:
    Student *Student_First;                        
    void Read();                           //读取学生成绩函数
    void Save();                           //保存学生成绩信息函数
};
Function::Function()
{    Student_First=new Student;                             
    Read();
}  
Function::~Function()
{    delete Student_First;            
}
void Function::Add()                           //录入学生成绩信息函数
{    char name[20];
    int no;   
    Class score;
    char choose;                           
    Student *f1,*p,*f2;                        
    system("cls");
    f1=Student_First;
    f2=Student_First->Next;
    while(f1->Next)
        f1=f1->Next;                  
    do
    {  p=new Student;
        cout<<"请输入您要添加的学生成绩信息:"<<endl;
        cout<<"请输入学生姓名:";
        cin>>name;
        while(f2)
        {    if(strcmp(f2->GetName(),name)==0)
            {    cout<<"该学生已存在,请确定姓名!\n\n";
                cout<<"请输入姓名:";
               cin>>name;
                break;
            }
            f2=f2->Next;
        }
        cout<<"请输入学号:";
        cin>>no;                                      
        cout<<"请输入语文成绩:";
       cin>>score.Chinese;
        cout<<"请输入数学成绩:";
       cin>>score.Math;
        
        p->Set(name,no,score);
        f1->Next=p;                  
        p->Next=NULL;
        f1=f1->Next;
        cout<<"是否继续输入信息?(Y\\N) "<<endl;
        cin>>choose;
        }while(choose=='y'||choose=='Y');
    Save();
    cout<<"1.返回主菜单"<<endl;
    cin>>choose;
    while(choose!='1')
    {    cout<<"1.返回主菜单"<<endl;
        cin>>choose;
    }
    Menu();
}
void Function::Stat()                           //求平均成绩信息函数
{
    int flag(0);                           
    char choose;                          
    char t1[20];
    int t2;
    system("cls");
    Student *temp=Student_First->Next;            
    do
    {   cout<<"输入查询方式:\n1.按姓名查询\n2.按学号查询\n";
        cin>>choose;
        if(choose=='1')
        {    cout<<"请输入您要查询的姓名:";
            cin>>t1;   
            while(temp)
            {    if(strcmp(t1,temp->GetName())==0)        
                {    flag=1;   
                    break;
                }
                temp=temp->Next;         
            }
            if(flag==0)
                cout<<"\n无该学生的信息\n"<<endl;
            else
            {   
                cout<<temp->GetName()<<"的平均成绩:"<<((temp->getScore()).Chinese+(temp->getScore()).Math)/2<<"\n";
            }
            break;
        }
        else if(choose=='2')
        {    cout<<"请输入您要查询的学号";
            cin>>t2;
            while(temp)
            {    if(t2==temp->GetNo())        
                {    flag=1;                    
                    break;
                }
                temp=temp->Next;         
            }
            if(flag==0)
                cout<<"\n无该学生的信息\n"<<endl;
            else
            {   
                cout<<temp->GetName()<<"的平均成绩:"<<((temp->getScore()).Chinese+(temp->getScore()).Math)/2<<"\n";
            }
            break;
        }
    }while(choose!='1'||choose!='2');
    cout<<"\n1.返回主菜单\n2.继续查询"<<endl;
    cin>>choose;
    while(choose!='1'&&choose!='2')
    {    cout<<"1.返回主菜单\n2.继续查询"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();               
    else if(choose=='2')
         Search();   
}
void Function::Delete()           //删除信息函数
{     char name[20];               
    int no;
    char choose;
    Student *temp,*p;
    system("cls");
    p=temp=Student_First->Next;
    cout<<"请输入姓名:";
    cin>>name;
    cout<<"输入学号:";
    cin>>no;
    while(temp)
    { if(strcmp(temp->GetName(),name)==0&&temp->GetNo()==no)  //判断该学生信息是否存在
        {      cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
               temp->Out();
               cout<<"\n是否删除(Y/N)";
              cin>>choose;
            if(choose=='y'||choose=='Y')
            {    p->Next=temp->Next;
                delete temp;
                cout<<"删除成功:\n";
            }
               break;                    
        }
        p=temp;
        temp=temp->Next;
    }
    Save();                                    
    cout<<"1.返回主菜单\n2.继续删除"<<endl;
    cin>>choose;                              
    while(choose!='1'&&choose!='2')
    {    cout<<"1.返回主菜单\n2.继续删除"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();                              
    else if(choose=='2')
        Delete();                    
}
void Function::Modify()                 //修改学生信息函数
{    char choose,name[20];               
    Student *temp,*p;                           
    int no;
    Class score;
    system("cls");
    temp=p=Student_First;
    cout<<"请输入您要修改的学生姓名:";
    cin>>name;
    while(temp)
    {    if(strcmp(temp->GetName(),name)==0)         
        {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
            temp->Out();
            cout<<"请输入姓名:";
             cin>>name;                                   
            cout<<"请输入学号:";
            cin>>no;                                      
            cout<<"请输入语文成绩:";
            cin>>score.Chinese;                                       
            cout<<"请输入数学成绩:";
           cin>>score.Math;
            
           temp->Set(name,no,score);
            break;
        }
        temp=temp->Next;                           
    }
    Save();
    cout<<"修改成功!"<<endl;
    cout<<"1.返回主菜单\n2.继续修改"<<endl;
    cin>>choose;
    while(choose!='1'&&choose!='2')
    {     cout<<"1.返回主菜单\n2.继续修改"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();
    else if(choose=='2')
        Modify();
}
void Function::Read()                       //读取信息函数
{    Student *p,*p2;
    p=Student_First;                           
  long  t;
    ifstream is("Student.txt",ios::in);         
    if(!is)                             
    {   ofstream os("Student.txt",ios::out);     
        os.close();                        
        return ;
    }
    while(!is.eof())
    {   p2=new Student;                  
        p2->Infile(is);
        p->Next=p2;                     
        p2->Next=NULL;                  
         p=p->Next;
    }
}
void Function::Save()                                 //保存学生成绩信息函数
{    ofstream of("Student.txt",ios::out);         
    Student *p=Student_First->Next;                     
    while(p)
    {    p->Ofile(of);                       
        p=p->Next;                     
    }
    of.close();
}
void Function::Search()                       
{    int flag(0);                           
    char choose;                          
    char t1[20];
    int t2;
    system("cls");
    Student *temp=Student_First->Next;            
    do
    {   cout<<"输入查询方式:\n1.按姓名查询\n2.按学号查询\n";
        cin>>choose;
        if(choose=='1')
        {    cout<<"请输入您要查询的姓名:";
            cin>>t1;   
            while(temp)
            {    if(strcmp(t1,temp->GetName())==0)        
                {    flag=1;   
                    break;
                }
                temp=temp->Next;         
            }
            if(flag==0)
                cout<<"\n无该学生的信息\n"<<endl;
            else
            {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
                temp->Out();
            }
            break;
        }
        else if(choose=='2')
        {    cout<<"请输入您要查询的学号";
            cin>>t2;
            while(temp)
            {    if(t2==temp->GetNo())        
                {    flag=1;                    
                    break;
                }
                temp=temp->Next;         
            }
            if(flag==0)
                cout<<"\n无该学生的信息\n"<<endl;
            else
            {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
                temp->Out();
               }
            break;
        }
    }while(choose!='1'||choose!='2');
    cout<<"\n1.返回主菜单\n2.继续查询"<<endl;
    cin>>choose;
    while(choose!='1'&&choose!='2')
    {    cout<<"1.返回主菜单\n2.继续查询"<<endl;
        cin>>choose;
    }
    if(choose=='1')
        Menu();               
    else if(choose=='2')
         Search();               
}
void Function::Show()        
{    char choose;
    Student *temp;
    system("cls");
    temp=Student_First->Next;         
    if(!temp)                  
    {    cout<<"文件无数据\n\n "<<endl;
        cout<<"1.返回主菜单"<<endl;
        cin>>choose;
         while(choose!='1')
         {      cout<<"1.返回主菜单"<<endl;
             cin>>choose;
         }
        Menu();           
    }
    else
    {    cout<<"姓名\t学号\t语文成绩\t数学成绩\n";
        while(temp!=NULL)
        {     temp->Out();
            temp=temp->Next;                     
        }
    }
    cout<<"1.返回主菜单"<<endl;
    cin>>choose;
    while(choose!='1')
    {    cout<<"1.返回主菜单"<<endl;
        cin>>choose;
    }
    Menu();                     
}
void Function::Menu()
{   time_t t;
    time(&t);
    char choose;               
    system("cls");
    cout<<" ------------------------版权所有:张嘉铎-------------------------"<<endl;
    cout<<endl;
    cout<<"***********************************************************"<<endl;
    cout<<"              武汉工程大学                  "<<endl<<endl;
    cout<<"             学生成绩信息管理系统                     "<<endl<<endl;
    cout<<" 显示系统时间和日期:      "<<ctime(&t)<<endl;
    cout<<"*********************************************************"<<endl<<endl;
    cout<<"请选择您需要的操作,选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
    cout<<"\n";
      cout<<"        1 录入学生成绩信息:\n"<<endl;
    cout<<"        2 查询学生成绩信息:\n"<<endl;
    cout<<"        3 删除学生成绩信息:\n"<<endl;
    cout<<"        4 修改学生成绩信息:\n"<<endl;
    cout<<"        5 显示全部学生成绩信息:\n"<<endl;
    cout<<"        6 查询学生平均成绩信息\n"<<endl;
    cout<<"        7 退出系统"<<endl;
    cout<<"\n";
    cin>>choose;
    switch(choose)
{    case '1': Add();break;                 
    case '2': Search();break;
    case '3': Delete();break;
    case '4': Modify();break;
    case '5': Show();break;
    case '6': Stat();break;
    case '7': exit(1);break;   
    default:
        {    cout<<"请按规定输入选择项!"<<endl;
            Menu();
        }
    }
}
int main()
{    Function function;          //定义功能接口
    function.Menu();            //调用主菜单
}

剑栈风樯各苦辛,别时冰雪到时春
2015-05-08 19:03
柳叶随迁
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-5-8
收藏
得分:0 
回复 2楼 林月儿
谢谢你啊,正在运行
2015-05-12 14:20
闷闷豆儿
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-12-6
收藏
得分:0 
请问一下这个,如何运行啊,复制到VC++里面,说是无法运行,是不是少点什么东西?完全菜鸟,跪求解答,谢谢
2015-12-06 02:54
快速回复:用C++编程学生成绩管理系统,大部分已经做出来了,还想加入一个计算每 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026184 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved