标题:图书管理系统一个问题,求解
只看楼主
xieyajiang
Rank: 2
等 级:论坛游民
帖 子:24
专家分:65
注 册:2011-12-8
结帖率:0
 问题点数:0 回复次数:1 
图书管理系统一个问题,求解
#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)
{ strcpy(name,nname);
strcpy(company,ncompany);
strcpy(author,nauthor);
strcpy(sort,nsort);
num=nnum;
number=nnumber;                                 
price=nprice;
year=nyear;
month=nmonth;
day=nday;
}                                                                              
char* getname(Book &L){return L.name;}
char* getauthor(Book &L){return L.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()
{char *name,*company,*author,*sort;
int num,number,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(Book &L,char* str)
{int i=0;
for(i=0;i<sum;i++)
if(strcmp(p[i].getname(L),str)==0)
{cout<<"该图书信息如下:"<<endl;
//p[i].display();
}
}
//按作者查询
void search_author(Book &L,char* str)
{
int i=0;
cout<<"该作者所著图书信息如下:"<<endl;
for(i=0;i<sum;i++)
if(strcmp(p[i].getauthor(L),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)
{char *name,*company,*author,*sort;
int num,number,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;
}
搜索更多相关主题的帖子: 管理系统 include search public change 管理系统 include search public change 
2013-07-12 20:37
xieyajiang
Rank: 2
等 级:论坛游民
帖 子:24
专家分:65
注 册:2011-12-8
得分:0 
//我自己解决了  哈哈


#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)
{ strcpy(name,nname);
strcpy(company,ncompany);
strcpy(author,nauthor);
strcpy(sort,nsort);
num=nnum;
number=nnumber;                                 
price=nprice;
year=nyear;
month=nmonth;
day=nday;
}                                                                              
char* getname(Book &L){return L.name;}
char* getauthor(Book &L){return L.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()
{char *name,*company,*author,*sort;
int num,number,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 q(name,author,company,sort,num,number,price,year,month,day);
p[i]=q;
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(Book &L,char* str)
{int i=0;
for(i=0;i<sum;i++)
if(strcmp(p[i].getname(L),str)==0)
{cout<<"该图书信息如下:"<<endl;
//p[i].display();
}
}
//按作者查询
void search_author(Book &L,char* str)
{
int i=0;
cout<<"该作者所著图书信息如下:"<<endl;
for(i=0;i<sum;i++)
if(strcmp(p[i].getauthor(L),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)
{char *name,*company,*author,*sort;
int num,number,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 q(name,author,company,sort,num,number,price,year,month,day);
p[n]=q;
cout<<"图书信息已保存,继续修改请按Y或y"<<endl;
cin>>select;
if(select=='Y'||select=='y')
{
flag=1;
}
else flag=0;
}while(flag==1);
cout<<"按任意键返回"<<endl;
}





2013-07-12 20:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-417220-1-1.html




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

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