| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1442 人关注过本帖
标题:学生管理系统
只看楼主 加入收藏
wskiawv
Rank: 1
等 级:新手上路
帖 子:42
专家分:5
注 册:2008-6-28
结帖率:33.33%
收藏
 问题点数:0 回复次数:6 
学生管理系统
用一个Student类来封装学号,姓名,语文,数学,英语,总分,平均分.还包括input()输入私有数据成员的函数和输出数据的output()函数.以及返回学号的Getnum()的成员函数,完成的操作主要是通过主函数调用(2)InputData函数
实现学生数据的输入。
(3)OutputData函数
实现学生数据的输出。
(4)locate函数
实现学生数据的查询。
(5)modify函数
实现学生数据的修改。
(6)del函数
实现学生数据的删除。
学生数据保存到一个文件中.
请问各位是怎样返回私有数据学号的,还有是怎样清除对象的值,然后重给一个值,意思就是将一个学生的数据清除去,
请各位指导指导!!!!!!!!!!!!!
搜索更多相关主题的帖子: 管理 学生 系统 
2008-12-11 07:42
maoguoqing
Rank: 6Rank: 6
来 自:重庆
等 级:贵宾
威 望:28
帖 子:2980
专家分:19
注 册:2005-12-5
收藏
得分:0 
你要的功能都可以用类的成员函数来做到,你不知道类有成员函数吗

天行健,君子以自强不息!!QQ:68660681
2008-12-11 18:18
wskiawv
Rank: 1
等 级:新手上路
帖 子:42
专家分:5
注 册:2008-6-28
收藏
得分:0 
没有办法啊,老师要求这么做,要不然我也不那么做了
2008-12-11 19:21
wskiawv
Rank: 1
等 级:新手上路
帖 子:42
专家分:5
注 册:2008-6-28
收藏
得分:0 
请高手帮帮忙,!!!!
2008-12-11 19:22
wskiawv
Rank: 1
等 级:新手上路
帖 子:42
专家分:5
注 册:2008-6-28
收藏
得分:0 
这是类部份
class student
{
private:
    char num[6],name[16];
    double chi,math,eng,sum,avg;
public:
    student(double c=0,double m=0,double e=0)
    {
        chi=c;
        math=m;
        eng=e;
    }
   void input()
   {
       cout<<"请输入学号,姓名和语文,数学,英语成绩(请按所提示的顺序输入):"<<endl;
       cin>>num>>name;
       cin>>chi;
       while(cin.fail())
       {
           cout<<"你输入的不是数字!"<<endl;
           cin.clear();
           cin.sync();
           cin>>chi;
       }
       cin>>math;
       while(cin.fail())
       {
           cout<<"你输入的不是数字!"<<endl;
           cin.clear();
           cin.sync();
           cin>>math;
       }
       cin>>eng;
       while(cin.fail())
       {
           cout<<"你输入的不是数字!"<<endl;
           cin.clear();
           cin.sync();
           cin>>eng;
       }
       sum=chi+math+eng;
       avg=sum/3;       
   }
   void ouput()
   {
       cout<<"--------------------------------------------------------------------------------"<<endl;
       cout<<"学号:"<<num<<"  姓名:"<<name<<"  成绩:  ";
       cout<<"语文:"<<chi<<"数学:"<<math<<"英语:"<<eng;
       cout<<"总分:"<<sum<<"平均分:"<<avg<<endl;
       cout<<"------------------------------------------------------------------------------"<<endl;
       cout<<endl;
   }
  char *GetNum()
   {
      return num;
   }
};
下面的是主函数和其他函数:
#include<iostream>
using namespace std;
#include"stu.h"
#include<cstdlib>
#include<fstream>
#include<cstring>
#include<conio.h>
//函数声明
void InputData();
void OutputData();
void locate();
void modify();
void del();
int i;// 循环变量
int y;//用来统计循环变量的次数
char n[6];//学号
student s1;//对象数组
int main()
{
    char x;
    while(true)
    {
        system("cls");
        cout<<"                 ***********************************************"<<endl;
        cout<<"                              学生成绩管理系统"<<endl;
        cout<<"                 ***********************************************"<<endl;
        cout<<endl;
        cout<<"                               1--数据输入"<<endl;
        cout<<"                               2--数据输出"<<endl;
        cout<<"                               3--数据查询"<<endl;
        cout<<"                               4--数据修改"<<endl;
        cout<<"                               5--删除学生"<<endl;
        cout<<"                               0--退出"<<endl;    
        cout<<"请从(0--5)选择:"<<endl;    
        cin>>x;    
        if(x=='0'||x=='1'||x=='2'||x=='3'||x=='4'||x=='5')
        {
            if(x=='1')
                InputData();
            if(x=='2')
                OutputData();
            if(x=='3')
                locate();
            if(x=='4')
                modify();
            if(x=='5')
                del();
            if(x=='0')
            {
                cout<<"退出!"<<endl;
                exit(1);
            }
        }
        else
            cout<<"你输入有误请重新选择!"<<endl;
        getch();
    }
    return 0;
}
void InputData()//输入数据函数
{
    char x;
    ofstream outf;//输出流对象
    outf.open("D:\\grade.dat",ios::out|ios::binary|ios::app);
    if(outf.fail())
    {
        cout<<"打开文件失败!"<<endl;
    }
    for(i=0;i<100;i++){
        y++;
    s1.input();
    outf.write((char *)&s1,sizeof(s1));
    cout<<"是否(Y|N)还有其他学生信息的输入?"<<endl;
    cin>>x;
    if(x=='N'||x=='n')
        break;
    }
    cout<<endl;
    outf.close();
}
void OutputData()//输出数据函数
{
    ifstream inf;//输入流对象
    inf.open("D:\\grade.dat",ios::in|ios::binary);
    if(!inf)
    {
        cout<<"打开文件失败!"<<endl;
    }
    else{
        for(i=0;i<y;i++){
            inf.read((char *)&s1,sizeof(s1));
            s1.ouput();
        }
    }
    inf.close();
}
void locate()//查询函数
{
    ifstream inf;//输入流对象
    inf.open("D:\\grade.dat",ios::in|ios::binary);
    if(!inf)
        cout<<"打开文件失败!"<<endl;
    else
        do{
    cout<<"请输入学号查询:";
    cin>>n;
    inf.read((char *)&s1,sizeof(s1));
    if(strcmp(n,s1.GetNum())==0)
    {        
        s1.ouput();        
    }
    else
        cout<<"无此学生!"<<endl;
    }while(!inf.eof());
    inf.close();
}
void modify()//修改数据函数
{
    fstream file_io;//输入输出流对象
    file_io.open("D:\\grade.dat",ios::in|ios::out|ios::binary|ios::app);
    if(file_io.fail())
        cout<<"打开文件失败!"<<endl;
    else
        do{
            cout<<"请输入要修改学生的学号:"<<endl;
            cin>>n;
            if(strcmp(n,s1.GetNum())==0)
            {
                file_io.clear();
                s1.input();
            }
            else{
                cout<<"此学生不存在!"<<endl;
                break;
            }
        }while(!file_io.eof());
        file_io.close();
}
void del()//删除数据函数
{}
请各位高手帮小弟改改!小弟不胜感激!
2008-12-13 12:01
wskiawv
Rank: 1
等 级:新手上路
帖 子:42
专家分:5
注 册:2008-6-28
收藏
得分:0 
这是类部份
class student
{
private:
    char num[6],name[16];
    double chi,math,eng,sum,avg;
public:
    student(double c=0,double m=0,double e=0)
    {
        chi=c;
        math=m;
        eng=e;
    }
   void input()
   {
       cout<<"请输入学号,姓名和语文,数学,英语成绩(请按所提示的顺序输入):"<<endl;
       cin>>num>>name;
       cin>>chi;
       while(cin.fail())
       {
           cout<<"你输入的不是数字!"<<endl;
           cin.clear();
           cin.sync();
           cin>>chi;
       }
       cin>>math;
       while(cin.fail())
       {
           cout<<"你输入的不是数字!"<<endl;
           cin.clear();
           cin.sync();
           cin>>math;
       }
       cin>>eng;
       while(cin.fail())
       {
           cout<<"你输入的不是数字!"<<endl;
           cin.clear();
           cin.sync();
           cin>>eng;
       }
       sum=chi+math+eng;
       avg=sum/3;       
   }
   void ouput()
   {
       cout<<"--------------------------------------------------------------------------------"<<endl;
       cout<<"学号:"<<num<<"  姓名:"<<name<<"  成绩:  ";
       cout<<"语文:"<<chi<<"数学:"<<math<<"英语:"<<eng;
       cout<<"总分:"<<sum<<"平均分:"<<avg<<endl;
       cout<<"------------------------------------------------------------------------------"<<endl;
       cout<<endl;
   }
  char *GetNum()
   {
      return num;
   }
};
下面的是主函数和其他函数:
#include<iostream>
using namespace std;
#include"stu.h"
#include<cstdlib>
#include<fstream>
#include<cstring>
#include<conio.h>
//函数声明
void InputData();
void OutputData();
void locate();
void modify();
void del();
int i;// 循环变量
int y;//用来统计循环变量的次数
char n[6];//学号
student s1;//对象数组
int main()
{
    char x;
    while(true)
    {
        system("cls");
        cout<<"                 ***********************************************"<<endl;
        cout<<"                              学生成绩管理系统"<<endl;
        cout<<"                 ***********************************************"<<endl;
        cout<<endl;
        cout<<"                               1--数据输入"<<endl;
        cout<<"                               2--数据输出"<<endl;
        cout<<"                               3--数据查询"<<endl;
        cout<<"                               4--数据修改"<<endl;
        cout<<"                               5--删除学生"<<endl;
        cout<<"                               0--退出"<<endl;    
        cout<<"请从(0--5)选择:"<<endl;    
        cin>>x;    
        if(x=='0'||x=='1'||x=='2'||x=='3'||x=='4'||x=='5')
        {
            if(x=='1')
                InputData();
            if(x=='2')
                OutputData();
            if(x=='3')
                locate();
            if(x=='4')
                modify();
            if(x=='5')
                del();
            if(x=='0')
            {
                cout<<"退出!"<<endl;
                exit(1);
            }
        }
        else
            cout<<"你输入有误请重新选择!"<<endl;
        getch();
    }
    return 0;
}
void InputData()//输入数据函数
{
    char x;
    ofstream outf;//输出流对象
    outf.open("D:\\grade.dat",ios::out|ios::binary|ios::app);
    if(outf.fail())
    {
        cout<<"打开文件失败!"<<endl;
    }
    for(i=0;i<100;i++){
        y++;
    s1.input();
    outf.write((char *)&s1,sizeof(s1));
    cout<<"是否(Y|N)还有其他学生信息的输入?"<<endl;
    cin>>x;
    if(x=='N'||x=='n')
        break;
    }
    cout<<endl;
    outf.close();
}
void OutputData()//输出数据函数
{
    ifstream inf;//输入流对象
    inf.open("D:\\grade.dat",ios::in|ios::binary);
    if(!inf)
    {
        cout<<"打开文件失败!"<<endl;
    }
    else{
        for(i=0;i<y;i++){
            inf.read((char *)&s1,sizeof(s1));
            s1.ouput();
        }
    }
    inf.close();
}
void locate()//查询函数
{
    ifstream inf;//输入流对象
    inf.open("D:\\grade.dat",ios::in|ios::binary);
    if(!inf)
        cout<<"打开文件失败!"<<endl;
    else
        do{
    cout<<"请输入学号查询:";
    cin>>n;
    inf.read((char *)&s1,sizeof(s1));
    if(strcmp(n,s1.GetNum())==0)
    {        
        s1.ouput();        
    }
    else
        cout<<"无此学生!"<<endl;
    }while(!inf.eof());
    inf.close();
}
void modify()//修改数据函数
{
    fstream file_io;//输入输出流对象
    file_io.open("D:\\grade.dat",ios::in|ios::out|ios::binary|ios::app);
    if(file_io.fail())
        cout<<"打开文件失败!"<<endl;
    else
        do{
            cout<<"请输入要修改学生的学号:"<<endl;
            cin>>n;
            if(strcmp(n,s1.GetNum())==0)
            {
                file_io.clear();
                s1.input();
            }
            else{
                cout<<"此学生不存在!"<<endl;
                break;
            }
        }while(!file_io.eof());
        file_io.close();
}
void del()//删除数据函数
{}
请各位高手帮小弟改改!小弟不胜感激!
2008-12-13 12:40
快速回复:学生管理系统
数据加载中...
 
   



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

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