| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:这是一个简单学籍管理系统 编译没有问题,在执行时出错了,帮忙看看
只看楼主 加入收藏
qww
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-11-14
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
这是一个简单学籍管理系统 编译没有问题,在执行时出错了,帮忙看看
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
class Basic
{
public:
virtual int input(ifstream &its)=0;
virtual void input()=0;
virtual void display(ofstream &its)=0;
virtual void display()=0;
virtual void display_1(){}
friend  class College;
protected:
//把这些数放在这,方便调用
Basic *next;//指针
int number;//学号
char name[40];//姓名
int dom_number;//宿舍号
double mark; //综合成绩
int credit; //实得学分
};

class Student:virtual public Basic
{
public:
    int input(ifstream &its)//输入流
    {
        its>>number;           //its将number写入文件中
        if(number==-1)
            return 0;
        else
        {
            its>>name>>sex>>dom_number>>phone_number;
            return 1;
        }
    }
   
    void input()//输入
    {
        cout<<"学号:";
        cin>>number;
        cout<<" 姓名:";
        cin>>name;
        cout<<"性别:";
        cin>>sex;
        cout<<"宿舍号码:";
        cin>>dom_number;
        cout<<"电话号码:";
        cin>>phone_number;
    }
   
    void display(ofstream &its)//输出流
    {
        its<<number<<" "<<name<<" "<<sex<<" "<<dom_number<<" "<<phone_number<<endl;
    }
   
    void display()//输出
    {
        cout<<number<<setw(10)<<name<<setw(6)<<sex<<setw(10)<<dom_number<<setw(13)<<phone_number<<endl;
    }
   
private:
    char sex[5];//性别
    char phone_number[20];//电话号码
   
};

class Course:virtual public Basic
{
public:
    int input(ifstream &its)//输入流函数
    {
        its>>number;
        if(number==-1)
            return 0;
        else
        {
            its>>chass_number>>chass_name>>
                chass_mark>>peacetime_mark>>experiment_mark>>txt_mark;
            account();
            return 1;
        }
        
    }
   
    void input()//输入函数
    {
        
        cout<<"学号=";
        cin>>number;
        cout<<"课程编号=";
        cin>>chass_number;
        cout<<"课程名称=";
        cin>>chass_name;
        cout<<"学分=";
        cin>>chass_mark;
        cout<<"平时成绩=";
        cin>>peacetime_mark;
        cout<<"实验成绩=";
        cin>>experiment_mark;
        cout<<"卷面成绩=";
        cin>>txt_mark;
        account();
    }
   
    void account()//计算综合成绩和实得学分
    {
        int i;
        if(experiment_mark==-1)
            mark=peacetime_mark*0.15+experiment_mark*0.15+txt_mark*0.7;
        else mark=peacetime_mark=peacetime_mark*0.3+txt_mark*0.7;
        i=mark/10;
        switch(i)
        {
        case 10: credit=chass_mark;break;
        case 9: credit=chass_mark;break;
        case 8: credit=chass_mark*0.8;break;
        case 7: credit=chass_mark*0.7;break;
        case 6: credit=chass_mark*0.6;break;
        default:credit=0;break;
        }
    }
   
    void display(ofstream &its)//输出流函数
    {
        its<<number<<" "<<chass_number<<" "<<chass_name<<" "<<chass_mark<<" "<<
            peacetime_mark<<" "<<experiment_mark<<" "<<txt_mark<<endl;
    }
   
    void display()//输出函数
    {
        cout<<number<<setw(10)<<chass_number<<setw(11)<<chass_name<<setw(5)<<chass_mark<<setw(7)<<
            peacetime_mark<<setw(10)<<experiment_mark<<setw(10)<<txt_mark<<setw(10)<<mark<<setw(10)<<credit<<endl;
        
    }
   
    void display_1()
    {
         cout<<"课程编号:"<<chass_number<<"    "<<"课程名称:"<<chass_name
             <<"   "<<"综合成绩:"<<mark<<"   "<<"实得学分:"<<credit<<endl;
    }
private:
   
    char chass_number[30];//课程编号
    char chass_name[30];//课程名称
    int chass_mark; //学分
    int peacetime_mark;//平时成绩
    int experiment_mark;//实验成绩
    int txt_mark; //卷面成绩
   
};

class College//链表类
{
public:
    College(int i)//构造函数建立初链,i=0建立Student链表,i=1建立Course链表
    {
        ji=0;
        Basic *p;
        int  t;
        PL=i;
        if(PL==0)//根据PL,打开相应的文件
        {
            f.open("A.txt",ios::in);
            head=new Student;
            p=new Student;
        }
        else
        {
            f.open("B.txt",ios::in);
            head=new Course;
            p=new Course;
     }
        if(!f)//判断f是否打开文件
      {
            cout<<"错误"<<endl;
            abort();
        }
        t=head->input(f);
        head->next=p;
        p->next=NULL;
        for(;;)//读入文件数据,并将数据插入链表中
        {
            if(i==0)
                p=new Student;
            else p=new Course;
            t=p->input(f);
            if(t==0)
                break;
            head=Build(p);
        }
        f.close();//关闭文件
    }

    ~College()
    {
        save();
    }
   
    Basic *Build(Basic *p)//插入函数,将p有序的插入链表中
    {
        Basic *p1=head,*p2=head;
        int i;
        for(i=0;p1->next!=NULL;i++)
        {
            if(i==0&&p->number<p1->number)//处理头链
            {
                p->next=p1;
                head=p;
                ji++;
                break;
            }
            else if(p->number<p1->number)//处理中间
            {
                p2->next=p;
                p->next=p1;
                ji++;
                break;
            }
            else if(i==ji)//处理尾
            {
                p2=p1;
                p1=p1->next;
                p2->next=p;
                p->next=p1;
                ji++;
                break;
            }
            p2=p1;
            p1=p1->next;
        }
        return head;
    }
   
    void display()//输出链表信息
    {
        Basic *a=head;
        for(;a->next!=NULL;a=a->next)
            a->display();
    }
   
    void find_number()//查找学号(student)
    {
        int i;
        Basic *h=head;
        cout<<"请输入你想找的学号:";
        cin>>i;
        for(;h->next!=NULL;h=h->next)
        {
            if(h->number==i)
            {
                h->display();
                break;
            }
        }
    }
   
    void find_name()//查找姓名(student)
    {
        char i[40];
        Basic *h=head;
        cout<<"请输入你想找的姓名:";
        cin>>i;
        for(;h->next!=NULL;h=h->next)
        {
            if(strcmp(h->name,i)==0)
            {
                h->display();
                break;
            }
        }
    }
   
    void find_dom_number()//查找宿舍号码(student)
    {
        int i;
        Basic *h=head;
        cout<<"请输入你想找的宿舍号码:";
        cin>>i;
        for(;h->next!=NULL;h=h->next)
            if(h->dom_number==i)
                h->display();
    }
   
    Basic *get_head()
    {
        return head;
    }
   
    void find(Basic *a)//输入一个学号时,查询出此生的所有课程情况(Course)
    {
        int i;
        Basic *h=head;
        cout<<"请输入你想查的学号:";
        cin>>i;
        for(;a->next!=NULL;a=a->next)
        {
            if(a->number==i)
            {
                cout<<"学    号:"<<i<<"      ";
                cout<<"姓    名:"<<a->name<<endl;
                break;
            }
        }
        for(;h->next!=NULL;h=h->next)
            if(h->number==i)
                h->display_1();
    }
   
    void Delete(int j)//删除,j表示学号
    {
        Basic *p1=head,*p2=head;
        int i=0;
        for(;p1->next!=NULL;)
        {
            if(i==0&&p1->number==j)//处理头
            {
                head=p1->next;
                i=-1;//保证下次还可以删除头链
            }
            else if(p1->number==j)//处理尾
            {
                p2->next=p1->next;
            }
        p2=p1;
            p1=p1->next;
            i++;
        }
    }
   
    void delete_student(College &b)//当在A.TXT中删除一个学生时,自动地在B.TXT中删除此人所有信息(student)
    {
        int i;
        cout<<"请输入你想删除的学生的学号:";
        cin>>i;
        Delete(i);
        b.Delete(i);
    }
   
    void taxis_mark()//综合成绩排序(Course)
    {
        Basic *a=head;
        Basic *m[90],*t;
        int i,j,k,b;
        cout<<"升序-1  降序-2"<<endl;
        cin>>b;
        if(b==1)//升序
        {
            for(i=0;a->next!=NULL;i++)
            {
                m[i]=a;
                a=a->next;
            }
            for(j=0;j<i;j++)
                for(k=j;k<i;k++)
                {
                    if(m[j]->mark>m[k]->mark)
                    {
                        t=m[j];
                        m[j]=m[k];
                        m[k]=t;
                    }
                }
                cout<<"按综合成绩升序排序为"<<endl;
                for(j=0;j<i;j++)
                    m[j]->display();
        }
        else if(b==2)//降序
        {
            for(i=0;a->next!=NULL;i++)
            {
                m[i]=a;
                a=a->next;
            }
            for(j=0;j<i;j++)
                for(k=j;k<i;k++)
                {
                    if(m[j]->mark<m[k]->mark)
                    {
                        t=m[j];
                        m[j]=m[k];
                        m[k]=t;
                    }
                }
                cout<<"按综合成绩降序排序为"<<endl;
                for(j=0;j<i;j++)
                    m[j]->display();
        }
    }
    void taxis_credit()//学分排序(Course)
    {
        Basic *a=head;
        Basic *m[90],*t;
        int i,j,k,b;
        cout<<"升序-1  降序-2"<<endl;
        cin>>b;
        if(b==1)//升序
        {
            for(i=0;a->next!=NULL;i++)
            {
                m[i]=a;
                a=a->next;
            }
            for(j=0;j<i;j++)
                for(k=j;k<i;k++)
                {
                    if(m[j]->credit>m[k]->credit)
                    {
                        t=m[j];
                        m[j]=m[k];
                        m[k]=t;
                    }
                }
                cout<<"按学分升序排序为"<<endl;
                for(j=0;j<i;j++)
                    m[j]->display();
        }
        else if(b==2)//降序
        {
            for(i=0;a->next!=NULL;i++)
            {
                m[i]=a;
                a=a->next;
            }
            for(j=0;j<i;j++)
                for(k=j;k<i;k++)
                {
                    if(m[j]->credit<m[k]->credit)
                    {
                        t=m[j];
                        m[j]=m[k];
                        m[k]=t;
                    }
                }
                cout<<"按学分降序排序为"<<endl;
                for(j=0;j<i;j++)
                    m[j]->display();
        }
    }
    void save() //保存函数
    {
        Basic *h=head;
        int i=-1;
       if(PL==0)
         s.open("A.txt",ios::out);
       else if(PL==1)
          s.open("B.txt",ios::out);
        for(;h->next!=NULL;h=h->next)
            h->display(s);
        s<<i<<endl;
        s.close();
    }
private:
    ifstream f;
    ofstream s;
    Basic *head;//链表的头指针
    int ji;//计算插入的数
    int PL;//判断建立怎样的链表
};
int main()
{
    int i,k[10];
    Course *c;
    College a(0),b(1);
    cout<<"           *************************  欢迎进入! **********************"<<endl;
    cout<<"           *************************学籍管理系统**********************"<<endl;
    cout<<"           ********                                           ********"<<endl;
    cout<<"           ********                                           ********"<<endl;
 to:cout<<"           ******** <1> 录入       <2> 查询       <3> 删除    ********"<<endl;
    cout<<"           ********                                           ********"<<endl;
    cout<<"           ******** <4> 排序       <5> 全部输出   <其他> 结束 ********"<<endl;
    cout<<"           ********                                           ********"<<endl;
    cout<<"      ********                                           ********"<<endl;
    cout<<"      ***********************************************************"<<endl;
    cin>>i;
    if(i==1)
    {
        c=new Course;
        c->input();
        b.Build(c);
        goto to;
    }
    else if(i==2)
    {
        cout<<"1-学生基本情况查询   2-成绩查询"<<endl;
        cin>>k[0];
        if(k[0]==1)
        {
            cout<<"1-学号查询  2-姓名查询  3-宿舍号码查询"<<endl;
            cin>>k[1];
            if(k[1]==1)
                a.find_number();
            else if(k[1]==2)
                a.find_name();
            else if(k[1]==3)
                a.find_dom_number();
            goto to;
        }
        else if(k[0]==2)
           b.find(a.get_head());
        goto to;
    }
    else if(i==3)
    {
        a.delete_student(b);
        goto to;
    }
    else if(i==4)
    {
        cout<<"1-综合成绩排序  2-实得学分排序"<<endl;
        cin>>k[2];
        if(k[2]==2)
          b.taxis_credit();
           b.taxis_mark();
        goto to;
    }
    else if(i==5)
    {
        cout<<"学号   姓名   性别    宿舍号码  电话号码"<<endl;
        a.display();
        cout<<endl;
        cout<<"学号 课程编号 课程名称  学分 平时成绩  实验成绩   卷面成绩   综合成绩  实得学分"<<endl;
        b.display();
        goto to;
    }
    return 0;
}
搜索更多相关主题的帖子: 学籍管理 display include public double 
2014-06-09 23:20
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:10 
单步调试了

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2014-06-13 06:39
疯狂的图灵机
Rank: 2
等 级:论坛游民
威 望:2
帖 子:5
专家分:40
注 册:2014-6-15
收藏
得分:10 
哪里有问题?
2014-06-15 08:37
快速回复:这是一个简单学籍管理系统 编译没有问题,在执行时出错了,帮忙看看
数据加载中...
 
   



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

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