图书管理系统C++代码,用Dev c++ 5.11运行,出现的错误,怎么改?
#include<iostream>#include<iomanip>
#include<windows.h>
#include<conio.h>
#include<string>
using namespace std;
const int Maxbor=10;//每位读者最多借10本书
class Reader//读者类
{
int tag;
int num;
char mima;
char name;
int borbook;
public:
Reader();
int getnum();
int gettag();
char*getname();
char* getmima();
void setname(char na[]);
void delreader();
void addreader(int n,char*na,char*mi);
void borrowbook(int bookid);
int retbook(int bookid);
void disp();
};
Reader::Reader(){
char*Reader::getname(){return name; }
int Reader::gettag(){return tag;}//获取删除符号
int Reader::getnum(){return num;}//获取读者编号
char*Reader::getmima(){return mima;}//获取读者的密码
void Reader::setname(char na[])//设置姓名
{
strcpy(name,na);
}
void Reader::delreader (){teg=1;}//删除读者
void Reader::addreader(int n,char*na,char*mi)//增加读者
{
tag=0;
num=n;
strcpy(name,na);
strcpy(mima,mi);
for(int i=0;i<Maxbor;i++)
borbook=0;
}
void Reader::borrowbook(int bookid)//借书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook==bookid)
{
borbook=0;
return;
}
}
}
int Reader::retbook(int bookid)//还书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook==bookid)
{
borbook=0;
return 1;
}
}
return 0;
}
void Reader::disp();//输出读者信息
{
cout<<endl;
cout<<setw(12)<<num<<"借书编号:[";
for(int i=0;i<Maxbor;i++)
if(borbook!=0)
cout<<borbook<<";";
cout<<"]"<<endl;
}
classBook//图书类
{
int tag;
int num;
char name;
char writer;
char concern;
char Time;
float price;
int onshelf;
public:
Book();
char*getname();
int getnum();
int getonshelf();
char*getwriter();
char*gettime();
char*getconcern();
float getprice();
int gettag();
void getTime(char time[]);
void setname(cher na[]);
void delbook();
void addbook()(int n,char*wri,char*con,char*tm,float pr);//增加图书
int borrowbook();//借书操作
void retbook();//还书操作
void disp();//输出图书
} ;Book::Book(){}
char*Book::getname(){return name;}//获取姓名
int Book::getonshelf(){return onshelf;}
int Book::getnum(){return num; }//获取图书编号
char*Book::getwriter(){return writer;} //获取书籍作者
char*Book::getconcern(){return concern;}//获取书籍出版社
char*Book::gettime(){return Time;}
float Book::getprice(){return price;}//获取书籍价格
int Book::gettag(){return tag; } //获取删除标记
void Book::setname(char na[]) //设置书名
{
strcpy(name,na);
}
void Book::getTime(char time[])
{
strcpy(Time,time);
}
void Book::delbook(){tag=1;}//删除图书
void Book::addbook(int n,char*na,char*wri,char*con,char*tm,float pr)//增加图书
{
tag=0;
num=n;
strcpy(name,na);
strcpy(writer,wri);
strcpy(concern,con);
strcpy(Time,tm);
price=pr;
onshelf=l;
}
int Book::borrowbook()//借书操作
{
if(onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void Book::retbook()//还书操作
{
onshelf=1;
}
void Book::disp()//输出图书
{
cout << setw(6) << num << setw(12) << name << setw(15) << concern << setw(10) << writer << setw(12) << Time<<setw(6)<<(onshelf==1?"在架";"已借")<<endl;
}
class BDatabase//图书库类
{
int top;
Book book;
public:
BDatabase();
void clear();
int addbook(int n,char*na,char*wri,char*con,char*tm,float pr);
Book *query(int bookid);
int BDatabase::qname(char*nm);
Book BDatabase::Qname(char*nm);
int qzuozhe(char *wr);
Book*Qzuozhe(char*wr);
int qchuban(char*cb);
Book*Qchuban(char*cb);
void bookdata();
~BDatabase();
void disp();
} ;
BDatabase::BDatabase()//构造函数将book.txt读到book[]中
{
Book b;
top=1;
fstream file("d:\\book.txt",ios::in);
while(1)
{
file.read((char*)&b,sizeof(b));
if(!file)break;
top++;
book=b;
}
file.close;
}
void BDatabase::clear()//全删
{
top=-1;
}
int BDatabase::addbook(int n,char*na,char*wri,char*con,char*tm,float pr)//增加图书
{
Book *p=query(n);
if(p==NULL)
{
top++;
book.addbook(n,na,wri,con,tm,pr);
return 1;
}
return 0;
}
Book*BDatabase::query(int bookid)//查找图书
{
for(int i=0;i<=top;i++)
if(book.getnum()==bookid&&book.gettag()=0)
return &book;
return NULL;
}
int BDatabase::qname(char*nm)
{
int j=0;
for(int i=0;i<=top;i++)
if((strcmp(book.getname().nm)==0)&&book.gettag()==0)
j++;
if(j==0)
return 0;
else
return j;
}
Book*BDatabase::Qname(char*nm)
{
int j=0;
Book b;
for (int i=0;i<=top;i++)
if((strcmp(book.getname().nm)==0)&&book.gettag()==0)
b=book;
if(j==0)
return NULL;
else
return b;
}
int BDatabase::qzuozhe(char *wr)
{
int e=0;
for(int i=0:i<=top;i++)
if((strcmp(book.getwriter().wr)==0)&&book.gettag()=0)
e++;
if(e==0)
return 0;
else
return b;
}
Book*BDatabase::Qzuozhe(char *wr)
{
int f=0;
Book b;
for(int i=0:i<=top;i++)
if((strcmp(book.getwriter().wr)==0)&&book.gettag()=0)
b=book;
if(f==0)
return NULL;
else
return b;
}
int BDatabase::qchuban(char *cb)
{
int g=0;
for(int i=0:i<=top;i++)
if((strcmp(book.getconcern().wr)==0)&&book.gettag()=0)
g++;
if(g==0)
return 0;
else
return g;
}
Book*BDatabase::Qchuban(char *cb)
{
int h=0;
Book b;
for(int i=0:i<=top;i++)
if((strcmp(book.getconcern().wr)==0)&&book.gettag()=0)
b=book;
if(h==0)
return NULL;
else
return b;
}
void BDatabase::bookdata()//图书库维护
{
int choice=1;
char bname;
int bookid;
char bwrite;
char bconcern;
char btime;
float bprice;
Book *b;
int r=0;
while(choice!=0)
{
cout<<endl<<endl<<endl<<endl;
cout<<" --------------------------------- "<<endl;
cout<<" -- 图书维护 --"<<endl;
cout<<" -- 1.新增 --"<<endl;
cout<<" -- 2.删除 --"<<endl;
cout<<" -- 3.查找 --"<<endl;
cout<<" -- 4.显示 --"<<endl;
cout<<" -- 5.全删 --"<<endl;
cout<<" -- 0.退出 --"<<endl;
cout<<" ----------------------------------"<<endl;
cout<<"请选择您将进行的操作:";
cin>>choice;
switch(choice)
{
case1:
cout<<"图书编号:";
cin>>bookid;
do
{
if(r!=0)
{
cout<<"该编号错误,请重新输入:";
cin>>bookid;
}
r++;
if(r==3)
break;
}
while(query(bookid)!=NULL);
if(r==3)
{
system("cls");
break;
}
cout<<"图书书名:";
cin<<bname;
cout<<"图书作者:";
cin>>bwriter;
cout<<"图书出版社:";
cin>>bconcern;
cout<<"图书出版时间:";
cin>>btime;
cout<<"图书价格";
cin>>bprice;
cout<<"图书添加成功"<<endl;
Sleep(1000);
system("cls");
addbook(bookid,bname,bwriter,bconcern,btime,bprice);
break;
case2:
cout<<"图书编号:";
cin>>bookid;
b=query(bookid);
if(b==NULL)
{
cout<<"该图书不在"<<endl;
Sleep(1000);
system("cls");
break;
}
cout<<"已删除"<<endl;
Sleep(1000);
system("cls");
b->delbook();
break;
case3:
cout<<"图书编号:";
cin>>bookid;
b=query(bookid);
if(b==NULL)
{
cout<<"该图书不在"<<endl;
Sleep(1000);
system("cls");
break;
}
system("cls");
cout<<"所查信息如下:"<<endl;
b->disp();
break;
case4:
system("cls");
cout<<"所有图书信息如下:"<<endl;
b->disp();
break;
case5:
clear();
cout<<"所有图书已删除"<<endl;
Sleep(1000);
system("cls");
break:
}
}
system("cls");
}
void BDatabase::disp()
{
Book temp;
for(int i=0;i<=top&&(book.gettag()==0);i++)
for(int j=i+1;j<=top;&&(book.gettag()==0);j++)
if(strcmp(book.gettime(),book.gettime())<0)
{
temp=book;
book=book;
book=temp;
}
for(int x=0;x<=top;&&(book.gettag()==0);x++)
book.disp();
}
BDatebase::~BDatabase()//析构函数,将book[]写入book .txt文件中
{
fstream file(d:\\book.txt",ios::out);
for(int i=0;i<=top;i++)
if(book.gettag()=0)
file.write((char*)&book,sizeof(book));
file.close();
}
class Rdatebase //读者库类
{
int top;
Reader read;//读者记录
public:
Rdatebase();
void disp();
void clear();
void addreader(int n,char*na,char*mi);
Reader *query(int readerid);
~Rdatebase();
void readerdata();
} ;
Rdatebase::Rdatebase()//构造函数,将reader.txt读到read[]中
{
Reader s;
top=-1;
fstream file("d:\\reader.txt",ios::in);
while(1)
{
file.read((char*)&s,sizeof(s));
if(!file)break;
top++;
read=s;
}
file.close();
}
void Rdatebase::disp();
{
for(int i=0;i<=top;i++)
if(read,gettag()==0)
read.disp();
}
void Rdatebase::clear()
{
top=-1;
}
void Rdatebase::addreader(int n,char*na,char*mi)
{
top++;
read.addreader(n,na,mi);
}
Reader*Rdatebase::query(int readerid)
{
for(int i=0;i<=top;i++)
if(read.getnum()==readerid&&read.gettag()==0)
return &read;
return NULL;
}
Rdatebase::~Rdatebase()//析构函数,将red[]写入read.txt文件中
{
fstream file("d:\\reader.txt",ios::out);
for(int i=0;i<=top;i++)
if(read.gettag()=0)
file.write((char*)&read,sizeof(read));
file.close();
}
void Rdarebase::readerdata()//读者库维护
{
int choice;
char rname;
int readerid;
char rmima;
Reader *r;
while (choice!=0)
{
cout<<"--------------------------------------"<<endl;
cout<<"-- 读者维护 --"<<endl;
cout<<"-- 1、新增 --"<<endl;
cout<<"-- 2、更改 --"<<endl;
cout<<"-- 3、删除 --"<<endl;
cout<<"-- 4、查找 --"<<endl;
cout<<"-- 5、显示 --"<<endl;
cout<<"-- 6、全删 --"<<endl;
cout<<"-- 0.退出 --"<<endl;
cout<<"--------------------------------------"<<endl;
cout<<"请选择"<<endl;
cin>>choice;
int a=0;
int i=0;
switch(choice)
{
case 0:
system("cls");
break;
case 1:
cout<<"读者编号:";
cin>>readerid;
do
{
if(a!=0)
{
cout<<"已存在,请重新输入:";
cin>>readerid;
}
a++;
}
while(query(reader)!=NULL);
cout<<"输入读者密码:";
for(i;i<6;i++)
{
rmima=getch();
putch("-");
}
cout<<endl<<"输入读者姓名:";
cin>>rname;
cout<<"添加成功"<<endl;
addreader(readerid,rname,rmima);
Sleep(1000);
system("cls");
break;
case2:
cout<<"读者编号:";
cin>>readerid;
r=query(readerid);
if(r==NULL)
{
cout<<"该读者不存在"<<endl;
Sleep(1000);
system("cls");
break;
}
cout<<"输入新的读者姓名:";
cin>>rname;
cout<<"读者更改成功"<<endl;
Sleep(1000);
system("cls");
r->setname(rname);
break;
case3:
cout<<"读者编号:";
cin>>readerid;
r=query(readerid);
if(r==NULL)
{
cout<<"该读者不存在"<<endl;
Sleep(1000);
system("cls");
break;
}
cout<<"读者删除成功"<<endl;
Sleep(1000);
system("cls");
r->delreader();
break;
case4:
cout<<"读入读者编号:";
cin>>readerid;
r=query(readerid);
if(r==NULL)
{
cout<<"该读者不存在"<<endl;
Sleep(1000);
system("cls");
break;
}
system("cls");
cout<<"您所查找的读者信息如下"<<endl;
r->disp();
break;
case 5:
system("cls");
cout<<"所有读者信息如下"<<endl;
disp();
break;
case 6:
clear();
cout<<"所有读者已删除"<<endl ;
Sleep(1000);
system("cls");
break;
}
}
} 错误在哪? 行列单元信息66CAUsers\DELL\Documents\代码C\实验报告.cppstray'\243'in programCAUsers\DELL\Documents\代码C\实验报告.cppstray'\273'inprogram6CA\Users\DELL\Documents\代码C\实验报告.cppstray"\243'inprogram67CA\Users\DELL\Documents\代码C\实验报告.cppstray‘\241'inprogram415CAUsers\DELL\Documents\代码C\实验报告.cppstray’\'inprogram4157CAUsers\DELL\Documents\代码C\实验报告.cppstray'\'inprogram41537CA\Users\DELL\Documents\代码C\实验报告.cppmissing terminating"character415CAUsersl DELL\Documents\代码C\实验报告.cpp515missing terminating"characterCAUsers\DELL\Documents\代码C\实验报告.cppstray"\243'inprogram515CAUsers\DELL\Documents\代码C\实验报告.cppstray"\273'inprogram1414CAUsers\DELL\Documents\代码C\实验报告.cpp'Marbor'was not declered in this scopeCAWsers\DELL\Documents\代码C\实验报告.cpp In constructor'Rea3er=Reader0':)CAUsers\DELL\Documents\代码C\实验报告.cpp CAUsers\DELL\Documents\代码C\实验报告.cppqualified-id in declaration before’("tokenqualified-id in declaration before’(’token21CNUsers\DELL\Documents\代码C\实验报告.cppqualified-id in declaration before'("tokenCAUsers\DELL\Documents\代码C\实验报告.cppqualified-id in declaration before'('tokenCAUsers\DELL\Documents\代码C\实验报告.cppqualified-id in declaration before'(’token27C\Users\DELL\Documents\代码C\实验报告.cpp39C\Users\DELL\Documents\代码C\实验报告.cppqualified-id in declaration before'("token49CAUsers\DELL\Documents\代码C\实验报告.cppqualified-id in declaration before'("token5989qualified-id in declaration before’(tokenCAUsers\DELL\Documents\代码C\实验报告.cppexpected'Y at end of input
编译单个文件...
--------
- 文件名: C:\Users\DELL\Documents\代码C\实验报告.cpp
- 编译器名: TDM-GCC 4.9.2 64-bit Release
处理 C++ 源文件...
--------
- C++ 编译器: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe
- 命令: g++.exe "C:\Users\DELL\Documents\代码C\实验报告.cpp" -o "C:\Users\DELL\Documents\代码C\实验报告.exe"-I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc
C:\Users\DELL\Documents\代码C\实验报告.cpp:159:6: error: stray '\243' in program
cout << setw(6) << num << setw(12) << name << setw(15) << concern << setw(10) << writer << setw(12) << Time<<setw(6)<<(onshelf==1?"在架";"已借")<<endl;
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:159:6: error: stray '\273' in program
C:\Users\DELL\Documents\代码C\实验报告.cpp:298:6: error: stray '\243' in program
while(choice!=0)
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:298:6: error: stray '\241' in program
C:\Users\DELL\Documents\代码C\实验报告.cpp:415:7: error: stray '\' in program
fstream file(d:\\book.txt",ios::out);
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:415:7: error: stray '\' in program
C:\Users\DELL\Documents\代码C\实验报告.cpp:415:32: warning: missing terminating " character
fstream file(d:\\book.txt",ios::out);
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:415:7: error: missing terminating " character
fstream file(d:\\book.txt",ios::out);
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:515:14: error: stray '\243' in program
cout<<"已存在,请重新输入:";
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:515:14: error: stray '\273' in program
C:\Users\DELL\Documents\代码C\实验报告.cpp:14:14: error: 'Marbor' was not declared in this scope
int borbook;
^
C:\Users\DELL\Documents\代码C\实验报告.cpp: In constructor 'Reader::Reader()':
C:\Users\DELL\Documents\代码C\实验报告.cpp:30:23: error: qualified-id in declaration before '(' token
char*Reader::getname(){return name; }
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:31:21: error: qualified-id in declaration before '(' token
int Reader::gettag(){return tag;}//获取删除符号
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:32:21: error: qualified-id in declaration before '(' token
int Reader::getnum(){return num;}//获取读者编号
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:33:23: error: qualified-id in declaration before '(' token
char*Reader::getmima(){return mima;}//获取读者的密码
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:34:23: error: qualified-id in declaration before '(' token
void Reader::setname(char na[])//设置姓名
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:38:27: error: qualified-id in declaration before '(' token
void Reader::delreader (){teg=1;}//删除读者
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:39:24: error: qualified-id in declaration before '(' token
void Reader::addreader(int n,char*na,char*mi)//增加读者
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:49:26: error: qualified-id in declaration before '(' token
void Reader::borrowbook(int bookid)//借书操作
^
C:\Users\DELL\Documents\代码C\实验报告.cpp:598:9: error: expected '}' at end of input
}
^
编译结果...
--------
- 错误: 19
- 警告: 1
- 编译时间: 1.48s
Hello. 发表于 2020-6-27 21:45
错误在哪?
放到 VS 里,一下子出来 133 个 ERROR{:10_247:} 159 7 C:\Users\DELL\Documents\代码C\实验报告.cpp stray '\243' in program
159 7 C:\Users\DELL\Documents\代码C\实验报告.cpp stray '\273' in program
515 14 C:\Users\DELL\Documents\代码C\实验报告.cpp stray '\243' in program
515 14 C:\Users\DELL\Documents\代码C\实验报告.cpp stray '\273' in program
29 17 C:\Users\DELL\Documents\代码C\实验报告.cpp no 'int Reader::reader()' member function declared in class 'Reader' 这是修改后的代码,但还是有5个bug
#include<iostream>
#include<iomanip>
#include<windows.h>
#include<conio.h>
#include<string>
using namespace std;
const int Maxbor=10;//每位读者最多借10本书
class Reader//读者类
{
int tag;
int num;
char mima;
char name;
int borbook;
public:
Reader();
int getnum();
int gettag();
char*getname();
char* getmima();
void setname(char na[]);
void delreader();
void addreader(int n,char*na,char*mi);
void borrowbook(int bookid);
int retbook(int bookid);
void disp();
};
Reader::reader(){
char*Reader::getname(){return name; }
int Reader::gettag(){return tag;}//获取删除符号
int Reader::getnum(){return num;}//获取读者编号
char*Reader::getmima(){return mima;}//获取读者的密码
void Reader::setname(char na[])//设置姓名
{
strcpy(name,na);
}
void Reader::delreader (){teg=1;}//删除读者
void Reader::addreader(int n,char*na,char*mi)//增加读者
{
tag=0;
num=n;
strcpy(name,na);
strcpy(mima,mi);
for(int i=0;i<Maxbor;i++)
borbook=0;
}
void Reader::borrowbook(int bookid)//借书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook==bookid)
{
borbook=0;
return;
}
}
}
int Reader::retbook(int bookid)//还书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook==bookid)
{
borbook=0;
return 1;
}
}
return 0;
}
void Reader::disp();//输出读者信息
{
cout<<endl;
cout<<setw(12)<<num<<"借书编号:[";
for(int i=0;i<Maxbor;i++)
if(borbook!=0)
cout<<borbook<<";";
cout<<"]"<<endl;
}
class Book//图书类
{
int tag;
int num;
char name;
char writer;
char concern;
char Time;
float price;
int onshelf;
public:
Book();
char*getname();
int getnum();
int getonshelf();
char*getwriter();
char*gettime();
char*getconcern();
float getprice();
int gettag();
void getTime(char time[]);
void setname(cher na[]);
void delbook();
void addbook()(int n,char*wri,char*con,char*tm,float pr);//增加图书
int borrowbook();//借书操作
void retbook();//还书操作
void disp();//输出图书
} ;Book::Book(){}
char*Book::getname(){return name;}//获取姓名
int Book::getonshelf(){return onshelf;}
int Book::getnum(){return num; }//获取图书编号
char*Book::getwriter(){return writer;} //获取书籍作者
char*Book::getconcern(){return concern;}//获取书籍出版社
char*Book::gettime(){return Time;}
float Book::getprice(){return price;}//获取书籍价格
int Book::gettag(){return tag; } //获取删除标记
void Book::setname(char na[]) //设置书名
{
strcpy(name,na);
}
void Book::getTime(char time[])
{
strcpy(Time,time);
}
void Book::delbook(){tag=1;}//删除图书
void Book::addbook(int n,char*na,char*wri,char*con,char*tm,float pr)//增加图书
{
tag=0;
num=n;
strcpy(name,na);
strcpy(writer,wri);
strcpy(concern,con);
strcpy(Time,tm);
price=pr;
onshelf=l;
}
int Book::borrowbook()//借书操作
{
if(onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void Book::retbook()//还书操作
{
onshelf=1;
}
void Book::disp()//输出图书
{
cout << setw(6) << num << setw(12) << name << setw(15) << concern << setw(10) << writer << setw(12) << Time<<setw(6)<<(onshelf==1?"在架";"已借")<<endl;
}
class BDatabase//图书库类
{
int top;
Book book;
public:
BDatabase();
void clear();
int addbook(int n,char*na,char*wri,char*con,char*tm,float pr);
Book *query(int bookid);
int BDatabase::qname(char*nm);
Book BDatabase::Qname(char*nm);
int qzuozhe(char *wr);
Book*Qzuozhe(char*wr);
int qchuban(char*cb);
Book*Qchuban(char*cb);
void bookdata();
~BDatabase();
void disp();
} ;
BDatabase::BDatabase()//构造函数将book.txt读到book[]中
{
Book b;
top=1;
fstream file("book.txt",ios::in);
while(1)
{
file.read((char*)&b,sizeof(b));
if(!file)break;
top++;
book=b;
}
file.close;
}
void BDatabase::clear()//全删
{
top=-1;
}
int BDatabase::addbook(int n,char*na,char*wri,char*con,char*tm,float pr)//增加图书
{
Book *p=query(n);
if(p==NULL)
{
top++;
book.addbook(n,na,wri,con,tm,pr);
return 1;
}
return 0;
}
Book*BDatabase::query(int bookid)//查找图书
{
for(int i=0;i<=top;i++)
if(book.getnum()==bookid&&book.gettag()=0)
return &book;
return NULL;
}
int BDatabase::qname(char*nm)
{
int j=0;
for(int i=0;i<=top;i++)
if((strcmp(book.getname().nm)==0)&&book.gettag()==0)
j++;
if(j==0)
return 0;
else
return j;
}
Book*BDatabase::Qname(char*nm)
{
int j=0;
Book b;
for (int i=0;i<=top;i++)
if((strcmp(book.getname().nm)==0)&&book.gettag()==0)
b=book;
if(j==0)
return NULL;
else
return b;
}
int BDatabase::qzuozhe(char *wr)
{
int e=0;
for(int i=0:i<=top;i++)
if((strcmp(book.getwriter().wr)==0)&&book.gettag()=0)
e++;
if(e==0)
return 0;
else
return b;
}
Book*BDatabase::Qzuozhe(char *wr)
{
int f=0;
Book b;
for(int i=0:i<=top;i++)
if((strcmp(book.getwriter().wr)==0)&&book.gettag()=0)
b=book;
if(f==0)
return NULL;
else
return b;
}
int BDatabase::qchuban(char *cb)
{
int g=0;
for(int i=0:i<=top;i++)
if((strcmp(book.getconcern().wr)==0)&&book.gettag()=0)
g++;
if(g==0)
return 0;
else
return g;
}
Book*BDatabase::Qchuban(char *cb)
{
int h=0;
Book b;
for(int i=0:i<=top;i++)
if((strcmp(book.getconcern().wr)==0)&&book.gettag()=0)
b=book;
if(h==0)
return NULL;
else
return b;
}
void BDatabase::bookdata()//图书库维护
{
int choice=1;
char bname;
int bookid;
char bwrite;
char bconcern;
char btime;
float bprice;
Book *b;
int r=0;
while(choice!=0)
{
cout<<endl<<endl<<endl<<endl;
cout<<" --------------------------------- "<<endl;
cout<<" -- 图书维护 --"<<endl;
cout<<" -- 1.新增 --"<<endl;
cout<<" -- 2.删除 --"<<endl;
cout<<" -- 3.查找 --"<<endl;
cout<<" -- 4.显示 --"<<endl;
cout<<" -- 5.全删 --"<<endl;
cout<<" -- 0.退出 --"<<endl;
cout<<" ----------------------------------"<<endl;
cout<<"请选择您将进行的操作:";
cin>>choice;
switch(choice)
{
case1:
cout<<"图书编号:";
cin>>bookid;
do
{
if(r!=0)
{
cout<<"该编号错误,请重新输入:";
cin>>bookid;
}
r++;
if(r==3)
break;
}
while(query(bookid)!=NULL);
if(r==3)
{
system("cls");
break;
}
cout<<"图书书名:";
cin<<bname;
cout<<"图书作者:";
cin>>bwriter;
cout<<"图书出版社:";
cin>>bconcern;
cout<<"图书出版时间:";
cin>>btime;
cout<<"图书价格";
cin>>bprice;
cout<<"图书添加成功"<<endl;
Sleep(1000);
system("cls");
addbook(bookid,bname,bwriter,bconcern,btime,bprice);
break;
case2:
cout<<"图书编号:";
cin>>bookid;
b=query(bookid);
if(b==NULL)
{
cout<<"该图书不在"<<endl;
Sleep(1000);
system("cls");
break;
}
cout<<"已删除"<<endl;
Sleep(1000);
system("cls");
b->delbook();
break;
case3:
cout<<"图书编号:";
cin>>bookid;
b=query(bookid);
if(b==NULL)
{
cout<<"该图书不在"<<endl;
Sleep(1000);
system("cls");
break;
}
system("cls");
cout<<"所查信息如下:"<<endl;
b->disp();
break;
case4:
system("cls");
cout<<"所有图书信息如下:"<<endl;
b->disp();
break;
case5:
clear();
cout<<"所有图书已删除"<<endl;
Sleep(1000);
system("cls");
break:
}
}
system("cls");
}
void BDatabase::disp()
{
Book temp;
for(int i=0;i<=top&&(book.gettag()==0);i++)
for(int j=i+1;j<=top;&&(book.gettag()==0);j++)
if(strcmp(book.gettime(),book.gettime())<0)
{
temp=book;
book=book;
book=temp;
}
for(int x=0;x<=top;&&(book.gettag()==0);x++)
book.disp();
}
BDatebase::~BDatabase()//析构函数,将book[]写入book .txt文件中
{
fstream file("book.txt",ios::out);
for(int i=0;i<=top;i++)
if(book.gettag()=0)
file.write((char*)&book,sizeof(book));
file.close();
}
class Rdatebase //读者库类
{
int top;
Reader read;//读者记录
public:
Rdatebase();
void disp();
void clear();
void addreader(int n,char*na,char*mi);
Reader *query(int readerid);
~Rdatebase();
void readerdata();
} ;
Rdatebase::Rdatebase()//构造函数,将reader.txt读到read[]中
{
Reader s;
top=-1;
fstream file("reader.txt",ios::in);
while(1)
{
file.read((char*)&s,sizeof(s));
if(!file)break;
top++;
read=s;
}
file.close();
}
void Rdatebase::disp();
{
for(int i=0;i<=top;i++)
if(read,gettag()==0)
read.disp();
}
void Rdatebase::clear()
{
top=-1;
}
void Rdatebase::addreader(int n,char*na,char*mi)
{
top++;
read.addreader(n,na,mi);
}
Reader*Rdatebase::query(int readerid)
{
for(int i=0;i<=top;i++)
if(read.getnum()==readerid&&read.gettag()==0)
return &read;
return NULL;
}
Rdatebase::~Rdatebase()//析构函数,将red[]写入read.txt文件中
{
fstream file("d:\\reader.txt",ios::out);
for(int i=0;i<=top;i++)
if(read.gettag()=0)
file.write((char*)&read,sizeof(read));
file.close();
}
void Rdarebase::readerdata()//读者库维护
{
int choice;
char rname;
int readerid;
char rmima;
Reader *r;
while (choice!=0)
{
cout<<"--------------------------------------"<<endl;
cout<<"-- 读者维护 --"<<endl;
cout<<"-- 1、新增 --"<<endl;
cout<<"-- 2、更改 --"<<endl;
cout<<"-- 3、删除 --"<<endl;
cout<<"-- 4、查找 --"<<endl;
cout<<"-- 5、显示 --"<<endl;
cout<<"-- 6、全删 --"<<endl;
cout<<"-- 0.退出 --"<<endl;
cout<<"--------------------------------------"<<endl;
cout<<"请选择"<<endl;
cin>>choice;
int a=0;
int i=0;
switch(choice)
{
case 0:
system("cls");
break;
case 1:
cout<<"读者编号:";
cin>>readerid;
do
{
if(a!=0)
{
cout<<"已存在,请重新输入:";
cin>>readerid;
}
a++;
}
while(query(reader)!=NULL);
cout<<"输入读者密码:";
for(i;i<6;i++)
{
rmima=getch();
putch("-");
}
cout<<endl<<"输入读者姓名:";
cin>>rname;
cout<<"添加成功"<<endl;
addreader(readerid,rname,rmima);
Sleep(1000);
system("cls");
break;
case2:
cout<<"读者编号:";
cin>>readerid;
r=query(readerid);
if(r==NULL)
{
cout<<"该读者不存在"<<endl;
Sleep(1000);
system("cls");
break;
}
cout<<"输入新的读者姓名:";
cin>>rname;
cout<<"读者更改成功"<<endl;
Sleep(1000);
system("cls");
r->setname(rname);
break;
case3:
cout<<"读者编号:";
cin>>readerid;
r=query(readerid);
if(r==NULL)
{
cout<<"该读者不存在"<<endl;
Sleep(1000);
system("cls");
break;
}
cout<<"读者删除成功"<<endl;
Sleep(1000);
system("cls");
r->delreader();
break;
case4:
cout<<"读入读者编号:";
cin>>readerid;
r=query(readerid);
if(r==NULL)
{
cout<<"该读者不存在"<<endl;
Sleep(1000);
system("cls");
break;
}
system("cls");
cout<<"您所查找的读者信息如下"<<endl;
r->disp();
break;
case 5:
system("cls");
cout<<"所有读者信息如下"<<endl;
disp();
break;
case 6:
clear();
cout<<"所有读者已删除"<<endl ;
Sleep(1000);
system("cls");
break;
}
}
} 编码问题,vs里边改成utf-8+bom试试
页:
[1]