#2
baiyangjiyi2013-07-11 17:45
|
#include<iostream.h>
#include<string>
#include<cstdlib>
int del();//删除图书信息
int insert();//添加图书信息
class Book;//book类前置声明
void change();//图书信息修改
void disp();//图书信息显示
void search_name();//按图书名称查询
void search_author();//按作者查询
void search();//图书信息查询
void menu();//主菜单
int sum;
const int N=50;
//以下是图书类
class Book
{ public:
Book(){};
Book(char nname[],char nauthor[],char ncompany[],char nsort[],int nnum,int nnumber,int nprice,int nyear,int nmonth,int nday)
{ name=nname;
company=ncompany;
author=nauthor;
sort=nsort;
num=nnum;
number=nnumber;
price=nprice;
year=nyear;
month=nmonth;
day=nday;
}
void display()
{
cout<<name<<"\t"<<num<<"\t"<<number<<"\t"<<sort<<"\t"<<author<<"\t"<<price<<"\t"<<year<<"-"<<month<<"-"<<day<<"\t"<<company<<endl;
}
char getname(){return name;}
char getauthor(){return author;}
int getnum(){return num;}
private:
char name[10];
char author[10];
char company[10];
char sort[10];
int num;
int number;
int price;
int year;
int month;
int day;
}
Book p[N];
int main()
{
Book a;
menu();
return 0;
}
//以下是主菜单
void menu()
{int select;
do{cout<<"************欢迎使用本系统!本系统功能如下:***********"<<endl;
cout<<" 1.图书信息输出"<<endl;
cout<<" 2.图书信息输入"<<endl;
cout<<" 3.图书信息查询"<<endl;
cout<<" 4.图书信息修改"<<endl;
cout<<" 5.图书信息删除"<<endl;
cout<<" 0.退出本系统"<<endl;
cout<<"*************************************"<<endl;
cout<<" 请输入您的选择: "<<endl;
do{ cin>>select;
if(select>5||select<0)
cout<<"您的选择有误!请重新输入:";
}while(select>5||select<0);
switch(select)
{case 0:break;
case 1:disp();break;
case 2:insert();break;
case 3:search();break;
case 4:change();break;
case 5:del();break;
}
}while(select!=0);
cout<<"文件已保存!!按任意键退出!再见!"<<endl;
}
//创建新图书
int insert()
{string name,company,author,sort;
int num,bumber,year,month,day,price;
int i=0,flag=1;
char select;
cout<<"请按向导输入要添加的图书信息!"<<endl;
do{
cout<<"图书编号:";
cin>>num;
cout<<"\n";
cout<<"图书名:";
cin>>name;
cout<<"\n";
cout<<"登录号:";
cin>>number;
cout<<"\n";
cout<<"作者名:";
cin>>author;
cout<<"\n";
cout<<"分类:";
cin>>sort;
cout<<"\n";
cout<<"价格:";
cin>>price;
cout<<"\n";
cout<<"出版单位:";
cin>>company;
cout<<"\n";
cout<<"出版时间(格式:XX-XX-XX):";
cin>>year>>"-">>month>>"-">>day;
cout<<"\n";
Book p[i](name,author,company,sort,num,number,price,year,month,day);
cout<<"图书信息已保存,继续添加请按Y或y"<<endl;
cin>>select;
if(select=='Y'||select=='y')
{flag=1;
i++;
}
else flag=0;
}while(flag==1);
sum=i;
return sum;
}
//删除图书信息
int del()
{int i,n,k;
cout<<"请输入您要删除的图书编号:"endl;
cin>>n;
for(i=0;i<=sum;i++)
{ if(p[i].getnum==n)
for(k=i,k<sum,k++)
p[i]=p[i+1];
}
cout<<"信息已删除!按任意键返回"<<endl;
sum-=1;
return sum;
}
//按图书名查询
void search_name(string str)
{i=0;
for(i=0;i<sum;i++)
if(strcmp(p[i].getname(),str)==0)
{cout<<"该图书信息如下:"<<endl;
p[i].display();
}
}
//按作者查询
void search_author(string str)
{i=0;
cout<<"该作者所著图书信息如下:"<<endl;
for(i=0;i<sum;i++)
if(strcmp(p[i].getauthor(),str)==0)
{
p[i].display();
}
}
//图书查询
void search()
{int select;
cout<<"**********本系统提供以下两种查询方式**********"<<endl;
cout<<" 1.按图书名称查询 "<<endl;
cout<<" 2.按作者姓名查询 "<<endl;
cout<<" 0.返回主菜单 "<<endl;
cout<<"***********************************************<<endl;
cout<<" 请输入您的选择:";
do{cin>>select;
if(select>2||select<0)
cout<<"您的选择有误,请重新输入:";
}while(select>2||select<0);
switch(select)
{case 0:menu();
case 1:search_name();
case 2:search_author();
}
}
void change(int n)
{string name,company,author,sort;
int num,bumber,year,month,day,price;
int flag=1,select;
do{ cout<<"请输入要更改的图书编号:";
cin>>n;
cout<<"请按向导输入新的图书信息!"<<endl;
cout<<"新的图书编号:";
cin>>num;
cout<<"\n";
cout<<"新的图书名:";
cin>>name;
cout<<"\n";
cout<<"新的登录号:";
cin>>number;
cout<<"\n";
cout<<"新的作者名:";
cin>>author;
cout<<"\n";
cout<<"新的分类:";
cin>>sort;
cout<<"\n";
cout<<"新的价格:";
cin>>price;
cout<<"\n";
cout<<"新的出版单位:";
cin>>company;
cout<<"\n";
cout<<"新的出版时间(格式:XX-XX-XX):";
cin>>year>>"-">>month>>"-">>day;
cout<<"\n";
Book p[n](name,author,company,sort,num,number,price,year,month,day);
cout<<"图书信息已保存,继续修改请按Y或y"<<endl;
cin>>select;
if(select=='Y'||select=='y')
{
flag=1;
}
else flag=0;
}while(flag==1);
cout<<"按任意键返回"<<endl;
}
错误:g:\c++\c++编译器\microsoft visual studio\myprojects\sds\sf.cpp(50) : error C2146: syntax error : missing ';' before identifier 'p'
g:\c++\c++编译器\microsoft visual studio\myprojects\sds\sf.cpp(50) : fatal error C1004: unexpected end of file found