| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 302 人关注过本帖
标题:修改下代码
只看楼主 加入收藏
爱海松涛
Rank: 3Rank: 3
来 自:安徽合肥
等 级:论坛游侠
帖 子:120
专家分:197
注 册:2011-2-25
结帖率:83.33%
收藏
 问题点数:0 回复次数:0 
修改下代码
我现在在做课程设计。写的一个小的C++程序有点问题,那位高手帮助小弟改正下,小弟十分感谢。。我的Q540915429。。


#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
#define max 100;

class student
{
public:
    student *next;
public:
    string name;//姓名
    string workUnit;//工作单位
    long number;                  //学号
    double Score1,Score2,Score3;     //实习单位评分 指导教师评分  实习答辩成绩
    double average;                    //平均分
    void play(){
        cout<<"姓名: "<<name<<"  学号: "<<number<<" 实习单位评分 :"<<Score1<<" 指导教师评分 :"<<Score2<<" 实习答辩成绩 :"<<Score3<<" 平均分 :"<<average<<endl;};
    student(string na,string w,long num,double score1,double score2,double score3,double av)
    {
        name=na;
        workUnit=w;
        number=num;
        Score1=score1;
        Score2=score2;
        Score3=score3;
        
    }
};
class cla
{
public:
    cla()                 //构造函数
    {
        stu=0;
        load();
    }
    ~cla()                //析构函数
    {
        student *p;

p=stu;
        while(p)
        {
            p=p->next;
            delete stu;
            stu=p;
        }
        stu=0;
    }
    void add();                    //添加
    void remove();                 //删除
    void amend();                  //修改
    void search();                 //查询
    void save();                   //保存
    void load();                   //读取
private:
    student *stu;                   //头接点
};


 


void cla::add()                     //添加
{
    student *q;
    string name1;
    string workunit;
    long number1;
    double Score11,Score22,Score33;
    system("cls");
    cout<<"\n **增加的学生** \n"<<endl;
    cout<<"请输入学生的(中间用空格间隔) "<<endl;
    cout<<"姓名 学号 工作单位 实习单位评分 指导教师评分  实习答辩成绩"<<endl;
    cin>>name1>>number1>>workunit>>Score11>>Score22>>Score33;
       q=new student(name1,number1,workunit,Score11,Score22,Score33);
    q->next=0;
    q->average=(Score22+Score33)*0.5;
    if(stu)
    {
        student *t;
        t=stu;
        if(t->number==number1)
        {
            cout<<"学号已存在,请重新输入"<<endl;
            return;
        }
        while(t->next)
        {
            if(t->number==number1)
            {
                cout<<"学号已存在,请重新输入"<<endl;
                return;
            }
            t=t->next;
        }
        t->next=q;
    }
    else
    {
        stu=q;
    }
    cout<<"输入完毕"<<endl;
}








void cla::remove()                          //删除
{
    system("cls");
    long number1;
    cout<<"\n** 删除学生信息 **\n";
    cout<<"请输入想要删除学生的学号:";
cin>>number1;                           //查找要删除的结点
    student *p1,*p2;
    p1=stu;
    while(p1)
    {
        if(p1->number==number1)
            break;
        else
        {
            p2=p1;
            p1=p1->next;
        }
    }                                     //删除结点
    if(p1!=NULL)                          //若找到结点,则删除
    {
        p1->play();
        cout<<"确定删除吗?[Y/N]"<<endl;
        char c;cin>>c;
        if(toupper(c)!='Y')
            return;
        if(p1==stu)                                //若要删除的结点是第一个结点
        {
            stu=p1->next;
            delete p1;
        }
        else                                      //若要删除的结点是后续结点
        {
            p2->next=p1->next;
            delete p1;
        }
        cout<<"找到学号为"<<number1<<"的学生,并删除\n";
    }
    else                                          //未找到结点
        cout<<"未找到想要删除的学生!\n";
}








 void cla::amend()                                   //修改
{
    system("cls");
    long number1;
    cout<<"\n** 修改学生信息 **\n";
    cout<<"输入要修改学生的学号";
    cin>>number1;                                     //查找要修改的结点
    student *p1,*p2;
    p1=stu;
    while(p1)
    {
        if(p1->number==number1)
            break;
        else
        {
            p2=p1;
            p1=p1->next;
        }
    }
    if(p1!=NULL)
    {
        cout<<"学号是"<<number1<<"的学生的信息:"<<endl;
        cout<<"姓名 "<<p1->name<<" 学号 "<<p1->number<<" 工作单位"<<p1->workUnit<<" 实习单位评分"<<p1->Score1<<" 指导教师评分 "<<p1->Score2<<" 实习答辩成绩 "<<p1->Score3<<endl;
        cout<<"请输入修改后的信息:姓名 学号 工作单位 实习单位评分 指导教师评分  实习答辩成绩"<<endl;
        cin>>p1->name>>p1->number>>p1->workUnit>>p1->Score1>>p1->Score2>>p1->Score3;
        p1->average=(p1->Score2+p1->Score3)*0.5;
        cout<<"修改成功"<<endl;
    }
    else                                              //未找到接点
        cout<<"未找到!\n";
}
 










void cla::search()                                      //查询
{
    system("cls");
    cout<<"\n** 查询学生信息 **\n"<<endl;
    cout<<"请输入查询方式:"<<endl;
    cout<<"1.按学号查询"<<endl;
    cout<<"2.按姓名查询"<<endl;
    cout<<"3.返回"<<endl;
    char c; cin>>c;
    switch (c)
    {
    case '1':
        {
            long number1;
            cout<<"要查询的学号"<<endl;
            cin>>number1;                                //查找要查询的结点
            student *p1,*p2;
            p1=stu;
            while(p1)
            {
                if(p1->number==number1)
                    break;
                else
                {
                    p2=p1;
                    p1=p1->next;
                }
            }
    if(p1!=NULL)
    {
        cout<<"学号是"<<number1<<"的学生的信息"<<endl;
        cout<<"姓名:"<<p1->name<<" 学号:"<<p1->number<<" 实习单位:"<<p1->workUnit<<" 实习单位评分:"<<p1->Score1<<"指导老师评分"<<p1->Score2<<"实习答辩成绩"<<p1->Score3<<endl;
        cout<<"查询完毕...";
    }
    else                                               //未找到接点
        cout<<"未找到!\n";
    break;
        }
    case '2':
        {
            string name1;
            cout<<"要查询的学生姓名"<<endl;
            cin>>name1;                                   //查找要查询的结点
            student *p1,*p2;
            p1=stu;
            while(p1)
            {
                if(p1->name==name1)
                    break;
                else
                {
                    p2=p1;
                    p1=p1->next;
                }
            }
    if(p1!=NULL)
    {
        cout<<name1<<"的学生的信息"<<endl;
        cout<<"姓名:"<<p1->name<<" 学号:"<<p1->number<<" 实习单位:"<<p1->workUnit<<" 实习单位评分:"<<p1->Score1<<"指导老师评分"<<p1->Score2<<"实习答辩成绩"<<p1->Score3<<endl;
        cout<<"查询完毕...";
    }
    else                                                   //未找到接点
        cout<<"未找到!\n";
    break;
        }
    case '3': return;
    }
}










void cla::save()                                              //保存到文件
{
    system("cls");
    char c;
    cout<<"\n保存学生信息(将覆盖原文件),是否继续?[Y/N]:"; cin>>c;
    if(toupper(c)!='Y') return;
    ofstream tfile("date.txt",ios_base::binary);
    student *p=stu;
    while(p)                                                 // 写入文件
    {
        tfile<<p->name<<"\t"<<p->number<<"\t"<<p->workUnit<<"\t"<<p->Score1<<"\t"<<p->Score2<<"\t"<<p->Score3;
        tfile<<endl;
        p=p->next;
    }
    tfile.close();
    cout<<"保存完毕..."<<endl;
}










 void cla::load()                                               //读取
{
    student *p;
    p=stu;
    while(p)
    {
        stu=p->next;
        delete p;
        p=stu;
    }
    ifstream tfile("date.txt",ios_base::binary);
    string name1;
    string workunit;
    long number1;
    double Score11,Score22,Score33;
    tfile>>name1>>number1>>workunit>>Score11>>Score22>>Score33;
    while(tfile.good())
    {                                                      //创建学生接点
        student *s;
        s=stu;
        s=new student(name1,number1,workunit,Score11,Score22,Score33);
        s->next=0;
        s->average=(Score22+Score33)*0.5;
        if(stu)                                               //若已经存在结点
        {
            student *p2;
            p2=stu;
            while(p2->next)                                   //查找尾结点
            {
                p2=p2->next;
            }
            p2->next=s;                                       //连接
        }
        else                                                 //若不存在结点(表空)
        {
            stu=s;                                            //连接
        }
        tfile>>name1>>number1>>workunit>>Score11>>Score22>>Score33;
    }
    tfile.close();
    cout<<"\n欢迎使用学生成绩管理系统\n";
}

void main()
{
    char c;
    cla a;
    do
    {
        cout<<"*************************************\n";
 
        cout<<" 1……增加学生 \n";
        cout<<" 2……删除学生 \n";
        cout<<" 3……修改学生 \n";
        cout<<" 4……查询学生信息 \n";
        cout<<" 5……保存信息 \n";
        cout<<" 6……读取信息 \n";
        cout<<" 7……退出 \n";
        cout<<"*************************************\n";
        cout<<"请选择(1-8):";
        cin>>c;
        switch(c)
        {
        case '1': a.add();break;
        case '2': a.remove();break;
        case '3': a.amend();break;
        case '4': a.search();break;  
        case '5': a.save();break;
        case '6': a.load();break;
        }
    }while(c!='7');
}

 






 


[ 本帖最后由 爱海松涛 于 2011-6-29 19:47 编辑 ]
搜索更多相关主题的帖子: double average include public 
2011-06-29 19:44
快速回复:修改下代码
数据加载中...
 
   



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

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