| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 982 人关注过本帖
标题:关于list.h的困惑
只看楼主 加入收藏
zhanghang123
Rank: 2
等 级:论坛游民
帖 子:39
专家分:24
注 册:2010-3-20
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
关于list.h的困惑
程序代码:
#include<iostream.h>
#include<iomanip.h>
#include<fstream.h>
#include<list.h>
//学生类声明
class Student
{
protected:
    int tag;
    int no;
    char name[20];
public:
    Student() {tag=0;}
    Student(int,char []);
    void addstudent(int,char []);
    char *getname();
    int gettag();
    int getno();
    void setname(char sname[]);
    void delstudent();
    void sdisp();
};
//学生类实现
Student::Student(int sid,char sname[])
{
    addstudent(sid,sname);
}
void Student::addstudent(int sid,char sname[])
{
    tag=0;
    no=sid;
    strcpy(name,sname);
}
char *Student::getname()
{
    return name;
}
int Student::gettag()
{
    return tag;
}
int Student::getno()
{
    return no;
}
void Student::setname(char sname[])
{
    strcpy(name,sname);
}
void Student::delstudent()
{
    tag=1;
}
void Student::sdisp()
{
    cout<<setw(6)<<no<<setw(20)<<name<<endl;
}
//学生库类声明
class SDatabase
{
    list<Student> stud;
public:
    SDatebase();
    ~SDatebase();
    void clear;
    int addstudent(int,char []);
    Student *query(int);//按学号查找
    void sdispalol();
    void studentdata();
};
//学生库类实现
SDatabase::SDatebase()
{
    Student s;
    fstrem file;
    file.open("student.dat",ios::init);
    while(1)
    {
        file.read((char *)&s,sizeof(s);
        if(!file) break;
        stud.push_back(s);//插入一个学生记录
    }
    file.close();
}
SDatabase::~SDatabase()
{
    list<Student>::iterator iter;
    fstream file;
    for (iter=std.begin();iter!=stud.end();iter++)
        if (iter->gettag()==0)
            file.write((char *)&(* iter),sizeof(Student));
        file.close();
}
void SDatabase::clear()
{
    stud.clear();
}
int SDatabase::addstudent(int std,char sname[])
{
    Student *p=query(sid);
    if(p==NULL)
    {
        Student s(sid,sname);
        stud.push_back(s);
        return 1;
    }
    return 0;
}
Student *SDatabase::query(int sid)
{
    list<Student>::iterator iter;
    for (iter=stud.begin();iter!=stud.end();iter++)
        if(iter->getno()==sid && iter->gettag()==0)
            return &(*iter);
        return NULL;
}
void SDatabase::sdispalol()
{
    list<Student>::iterator iter;
    cout<<"  学号           姓名"<<endl;
    for(iter=stud.begin();iter!=stud.end();iter++)
        if(iter->gettag()==0)
            iter->sdisp();
}
void SDatabase::studentdata()
{
    int chioxe=1;
    char sname[20];
    int sid;
    Student *p;
    while(chioce!=0)
    {
        cout<<"  学生管理 1:新增  2:更改  3:删除  4:查找  5:显示  6:全删  0:退出=>";
        cin>> choice;
        switch(choice)
        {
        case 1:
            cout<<"    输入学号:";
            cin>>sid;
            cout<<"    输入学生姓名:";
            cin>>sname;
            addstudent(sid,sname);
            break;
        case 2:
            cout<<"    输入学号:";
            cin>>sid;
            p=query(sid);
            if(p==NULL)
            {
                cout<<"    提示:该学生不存在"<<endl;
                break;
            }
            cout<<"    输入新的姓名:";
            cin>>sname;
            p->setname(sname);
            break;
        case 3:
            cout<<"    输入学号:";
            cin>>sid;
            p=query(sid);
            if(p==NULL)
            {
                cout<<"    提示:该学生不存在"<<endl;
                break;
            }
            p->delstudent();
            break;
        case 4:
            cout<<"    输入学号:";
            cin>>sid;
            p=query(sid);
            if(p==NULL)
            {
                cout<<"    提示:该学生不存在"<<endl;
                break;
            }
            p->sdisp();
            break;
        case 5:
            sdispalol();//cuowu
            break;
        case 6:
            clear();
            cout<<"    提示:记录已全删除"<<endl;
            break;
        }
    }
}
//课程类声明
class Course
{
    int tag;
    int no;
    char name[20];
public:
    Course()  {};
    Course (int,char[]);
    char *getname();
    int getno();
    int gettag();
    void setname(char[]);
    void delcourse();
    void addcourse(int,char[]);
    void cdisp();
};
//课程类实现

Course::Course(int cid,char cname[])
{
    addcourse(cid,cname);
}
char *Course::getname()
{
    return name;
}
int Course::getno()
{
    return no;
}
int Course::gettag()
{
    return tag;
}
void Course::setname(char cname[])
{
    strcpy(name,cname);
}
void Course::delcourse()
{
    tag=1;
}
void Course::addcourse(int cid,char cname[])
{
    tag=0;
    no=cid;
    strcpy(name,cname);
}
void Course::cdisp()
{
    cout<< setw(6)<<  no  << setw(20)  << name << endl;
}
//课程库类声明

class CDatabase
{
    list<Course>course;
public:
    CDatabase();
    ~CDatabase();
    void clear();
    void addcourse(int,char []);
    Course *query(int);
    void coursedata();
    void cdispall();
};
//课程库类实现

CDatabase::CDatabase()
{
    Course b;
    fstream file("course.dat",ios::in);
    while (1)
    {
        file.reawd((char *)&b,sizeof(b));
        if(!file)break;
        course.push_back(b);
    }
    file.close();
}
CDatabase::~CDatabase()
{
    fstream file("course.dat",ios::out|ios::trunc);
    list<Course>::iterator iter;
    for (iter=course.begin();iter!=course.end();iter++)
        if(iter->gettag()==0)
            file.write((char *)&(*iter),sizeof(Course));
        file.close();
}
void CDatabase::clear()
{
    course.clear();
}
void CDatabase::addcourse(int cid,char cname[])
{
    Course b(cid,cname);
    if (p==NULL)
    {
        Course b(cid,cname);
        course.push_back(b);
    }
    else
        cout<<"该课程已存在,不能增加"<<endl;
}

Course *CDatabase::query(int cid)
{
    list<Course>::iterator iter;
    for (iter=course.begin();iter!=course.end();iter++)
        if(iter->getno()==cid&&iter->gettag()==0)
            return &(*iter);
        return NULL;
}
void CDatabase::cdispall()
{
    list<Course>::iterator iter;
    cout<<"  课程编号           课程名"<<endl;
    for(iter=course.begin();iter!=course.end();iter++)
        if(iter->gettag()==0)
            iter->cdisp();
}
void CDatabase::coursedata()
{
    int choice=1;
    char cname[40];
    int cid;
    Course *b;
    while (choice!=0)
    {
        cout<<"课程管理1:新增2:更改3:删除:查找5:显示6:全删:退出=>";
        cin>>choice;
        switch (choice)
        {
        case 1:       //新增课程记录
            cout<<"   输入课程编号:";
            cin>>cid;
            cout<<"   输入课程名称:";
            cin>>cname;
            addcourse(cid,cname);
            break;
        case 2:       //更改课程记录
            cout<< " 输入课程编号:";
            cin>>cid;
            b=query(cid);
            if (b==NULL)
            {
                cout<<"  提示:该课程不存在"<<endl;
                break;
            }
            cout<<"   输入新课程名:";
            cin>>cname;
            b->setname(cname);
            break;
        case 3:      //删除课程记录
            cout<<"   输入课程编号:";
            cin>>cid;
            b=query(cid);
            if (b==NULL;
            {
                cout<<"   提示:该课程不存在"<<endl;
                break;
            }
            b->delcourse();
            break;
        case 4:     //查找课程记录
            cout<<"   输入课程编号:";
            cin>>cid;
            b=query(cid);
            if (b==NULL)
            {
                cout<<"   提示:该课程不存在"<<endl;
                break;
            }
            b->cdisp();
            break;
        case 5:     //显示所有课程记录
            cdlspall();
            break;
        case 6:
            clear();
            cout<<"   提示:记录已全删除"<<endl;
            break;
        }
    }
}
//成绩类声明
class Grade
{
    int tag;
    int sno;
    int cno;
    double degree;
public:
    Grade()  {}
    Grade(int,int,double);
    void setdegree(double);
    void delgrade();
    int gettag();
    int getsno();
    int getcno();
    double getgrade();
    void dispgrade();
    void adddegree(int,int,double);
};
//成绩类实现
Grade::Grade(int snol,int cnol,double gradel)
{
    adddegree(snol,cnol,gradel);
}
void Grade::setdegree(double gradel)
{
    degrdee==gradel;
}
void Grade::delgrade()
{
    tag=1;
}
int Grade::gettag()
{
    return tag;
}
int Grade::getcno()
{
    return cno;
}
double Grade::dispgrade()
{
    return degree;
}
void Grade::disgrade()
{
    cout<< sno << "," << cno << "," << degree <<endl;
}
void Grade::adddegree(int snol,int cnol,double degreel)
{
    tag=0;
    sno=snol;
    cno=cnol;
    degree=degreel;
}
//成绩库类声明
class GDatebase
{
    list<Grade>degree;   //成绩表容器
public:
    GDatabase();            //构造函数,从grade.dat=>degree
    ~GDatebase();           //析构函数,degree=>grade.dat
    void clear();          //全删
    void addegree(int,int,double);      //增加一个成绩记录
    Grade *query(int,int);              //查找某学生某课程成绩记录
     void querygrade();
    void querycourse();
    void gdispall();
    void gradedata();
};
//成绩库类实现
GDatabase::GDatabase()
{
    Grade b;
    fstream file("grade.dat",ios::in);
    while(1)
    {
        file.read((char *)&b,sizeof(b));
        if (!file) break;
        degree.push_back(b);
    }
    file.close();
}
GDatabase::~GDatabase()    //析构函数,degree=>grade.dat
{
    fstream file("grade.dat",ios::out|ios::trunc);
    list<Grade>::iterator iter;  //迭代器
    for (iter=degree.begin();iter!=degree.end();iter++)
        if (iter->gettag()==0)
            file.write((char *)&(*iter),sizeof(Grade));
        file.close();
}
void GDatabase::clear()
{
    degree.chear();
}
void GDatabase::clear()
{
    degree.clear();
}
void GDatabase::addegree(int sid,int cid,double degree) //增加一个成绩记录
{
    Grade *p=query(sid,cid);
    if (p==NULL)
    {
        Grade f(sid,cid,degreel);
        degree.push_back(f);
    }
    else
        cout<<"该学生的这门课成绩已存在,不能增加"<<endl;
}
Grade *GDatabase::query(int sid,int cid)
{
    list<Grade>::iterator iter;
    for(iter=degree.begin();iter!=degree.end();iter++)
        if(iter->getsno()==sid&&iter->getcno()==cid&&iter->gettag()==0)
            return NULL;
}
void GDatabase::querygrade()
{
    int sid;
    list<Grade>::iterator iter;
    cout <<"   输入学号:";
    cin>>sid;
    cout<<"    成绩列表:";
    for (iter=degree.begin();iter!=degree.end();iter++)
        if(iter->getsno()==sid && iter->gettag()==0)
            cout << iter->getcno() <<"("<< iter->getgrade() <<")"<<" ";
}
void GDatabase::querycourse()
{
    int cid;
    list<Grade>::iterator iter;
    cout<<"    输入课程编号:";
    cin>> cid;
    cout << "    成绩列表";
    for (iter=degree.begin();iter!=degree.end();iter++)
        if (iter->getcno()==cid && iter->gettag()==0)
            cout<< iter->getsno() <<"("<< iter->getgrade() <<")"<<" ";
        cout<< endl;
}
void GDatabase::gdispall()
{
    list<Grade>::iterator iter;
    cout<<"\t 学号      课程编号   分数"<<endl;
    for (iter=degree.begin();iter!=degree.end();iter++)
        if (iter->gettag()==0)
            cout << "\t" << iter->getsno() <<"\t\t"<< iter->getcno()
            <<"\t"<< iter->getgrade() <<endl;
}
void GDatabase::gradedata()
{
    int choice=1;
    int sid;
    int cid;
    double grade1;
    Grade *p;
    while (choice!=0)
    {
        cout << "  成绩管理 1:新增 2:更改 3:删除 4:查找 5:显示 6:全删 0:退出=>";
        cin>>choice;
        switch (choice)
        {
        case 1:
            cout<<"   输入学生学号:";
            cin>>sid;
            cout<<"   输入课程编号: ";
            cin>>sid;
            cout<<"   输入分数: ";
            cin>> gradel;
            addegree(sid,cid,grade1);
            break;
        case 2:
            cout<<"   输入学生学号:";
            cin>>sid;
            cout<<"   输入课程编号: ";
            cin>>sid;
            p=query(sid,cid);
            if(p==NULL)
            {
                cout <<"  提示:该学生成家不存在"<<endl;
                break;
            }
            cout << "   输入新的分数:";
            cin >> grade1;
            p->setdegree(grade1);
            break;
        case 3:
            cout<<"   输入学生学号:";
            cin>>sid;
            cout<<"   输入课程编号: ";
            cin>>sid;
            p=query(sid,cid);
            if(p==NULL)
            {
                cout <<"  提示:该学生成家不存在"<<endl;
                break;
            }
            p->delgrade();
            break;
        case 4:
            cout<<"   输入学生学号:";
            cin>>sid;
            cout<<"   输入课程编号: ";
            cin>>sid;
            p=query(sid,cid);
            if(p==NULL)
            {
                cout <<"  提示:该学生成家不存在"<<endl;
                break;
            }
            p->dispgrade();
            break;
        case 5:
            gdispall();
            break;
        case 6:
            clear();
            cout << "   提示:记录仪全删除"<<endl;
        }
    }
}



void main()
{
    int choice1=1,choice2;
    SDatabase StudentDB;
    CDatabase CourseDB;
    GDatabase GradeDB;
    while(choice1!=0)
    {
        cout<<"主菜单 1:成绩管理  2:成绩查询  3:课程管理  4:学生管理  0:离开=>";
        cin>>choice1;
        switch(choice1)
        {
        case 1:
            GradeDB.gradedate();
            break;
        case 2:
            choise2=1;
            while(choice2!=0)
            {
                cout>>"    成绩查询:1.查找某学生所有成绩  2.查找某课程成绩记录  0:返回=>";
                cin>>choice2;
                switch(choice2)
                {
                case 1:
                    GradeDB.quergrade();
                    break;
                case 2:
                    GradeDB.querycourse();
                    break;
                }
            }
            break;
        case 3:
            CourseDB.coursedata();
            break;
        case 4:
            StudentDB.studentdata();
            break;
        default:
            break;
        }
    }
}
做的该系统中,运行时显示vc98\include\list.h错误,
--------------------Configuration: 123 - Win32 Debug--------------------
Compiling...
123.cpp
e:\vc98\include\list.h(37) : error C2146: syntax error : missing ';' before identifier 'Length'
e:\vc98\include\list.h(37) : error C2501: 'DWORD' : missing storage-class or type specifiers
e:\vc98\include\list.h(37) : error C2501: 'Length' : missing storage-class or type specifiers
e:\vc98\include\list.h(53) : error C2146: syntax error : missing ';' before identifier 'GetPrevLink'
e:\vc98\include\list.h(53) : error C2433: 'WINAPI' : 'inline' not permitted on data declarations
e:\vc98\include\list.h(53) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
该如何更改,请高手赐教!!!
2011-01-04 22:26
megadeath
Rank: 4
等 级:业余侠客
帖 子:24
专家分:260
注 册:2008-8-29
收藏
得分:5 
应该不是list.h的问题,LZ再检查下自己的代码,有不少拼写错误,例如 类SDatabase中的构造函数是SDatebase,拼写就不一致。
2011-01-04 23:12
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
收藏
得分:15 
你好,请楼主仔细查看你的代码。我看过你的代码了,其中的错误99.99999999999999999999999999999999999999999999999%的是你的输入错误。仔细查看是不是多字符或是少字符了,或是输错了?还有,如果仔细检查后还是有错误,尝试一下把#include中的那些头文件中的.h去掉
2011-01-05 00:31
zhanghang123
Rank: 2
等 级:论坛游民
帖 子:39
专家分:24
注 册:2010-3-20
收藏
得分:0 
回复 3楼 八画小子
谢谢
2011-01-05 14:29
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
好长的代码~
2011-01-05 23:27
快速回复:关于list.h的困惑
数据加载中...
 
   



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

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