综合作业:图书管理系统

图书信息管理系统

要求:设计一个程序来管理图书信息,能实现图书相关信息的具备数据的输入、查找、删除等功能,能实现。具体功能细节可以根据自己理解情况进行增加


#include "iostream"
#include "cstring"
using namespace std;
class user
{
private :
	char ming[20];//用户名
	char mima[20];//密码
public :
	//返回用户名
	char *getm()
	{
		return ming;
	}
	//返回密码
	char *getmima()
	{
		return mima;
	}
	//设置密码和用户名
	void set(char ming[20],char mima[20])
	{
		strcpy(this->ming,ming);
		strcpy(this->mima,mima);
	}
	
};
class tushuku1
{
private:
	char shu[20];//书名
	int ceshu;//册数
	char zuozhe[20];//作者
	char chuban[20];//出版单位
	bool b0;//该书是否存在
public :
	//设置图书信息
	void set(char shu[10],int ceshu,char zuozhe[20],char chuban[20],bool b0)
	{
		strcpy(this->shu,shu);
		this->ceshu=ceshu;
		strcpy(this->zuozhe,zuozhe);
		strcpy(this->chuban,chuban);
		this->b0=b0;
	}
	//输出图书信息
	void get(int i)
	{
		cout<<i<<": <<"<<shu<<">>\t"<<"\t";
		cout<<ceshu<<"\t";
		cout<<zuozhe<<"\t"<<"\t";
		cout<<chuban<<"\n";
	}
	//返回图书册数
	int getce()
	{
		return ceshu;
	}
	//借书时将图书册数减一
	void jiushu()
	{
		ceshu--;
	}
	//还书是将册数加一
	void huanshu()
	{
		ceshu++;
	}
	//设置书名
	void setshu(char shu[20])
	{
		strcpy(this->shu,shu);
	}
	//设置册数
	void setceshu(int ceshu)
	{
		this->ceshu=ceshu;
	}
	//设置作者
	void setzuo(char zuozhe[20])
	{
		strcpy(this->zuozhe,zuozhe);
	}
	//设置出版社
	void setchuban(char chuban[20])
	{
		strcpy(this->chuban,chuban);
	}
	//返回图书是否存在
	bool getbo()
	{
		return b0;
	}
	//设置图书是否存在
	void setbo(bool b0)
	{
		this->b0=b0;
	}
	//返回图书名称
	char* getshu()
	{
		return shu;
	}
};
tushuku1 t1,t2,t3,t4,t5;
user u1,u2,u3,u4;
//初始化图书信息
void init()
{
		t1.set("水浒传",5,"施耐庵","北京出版社",true);
		t2.set("三国演义",5,"罗贯中","湖南出版社",true);
		t3.set("西游记",5,"吴承恩","天津出版社",true);
		t4.set("红楼梦",5,"曹雪芹","南京出版社",true);
		t5.set("朝花夕拾",5,"鲁迅","河南出版社",true);
		//登录密码


		u1.set("201211632407","123456");
		u2.set("11111","11111");
		u3.set("22222","22222");
		u4.set("33333","33333");
}
//查看你输得用户名或密码是否正确
bool deng()
{
	bool b=false;
	char ming[20],mima[20];
	cout<<"                            登录图书管理系统"<<endl;
	cout<<"输入你的用户名:"<<endl;
	cin>>ming;
	cout<<"输入你的密码:"<<endl;
	cin>>mima;
	if(!strcmp(ming,u1.getm()) && !strcmp(mima,u1.getmima()))
		b=true;
	if(!strcmp(ming,u2.getm()) && !strcmp(mima,u2.getmima()))
		b=true;
	if(!strcmp(ming,u3.getm()) && !strcmp(mima,u3.getmima()))
		b=true;
	if(!strcmp(ming,u4.getm()) && !strcmp(mima,u4.getmima()))
		b=true;
	return b;
}
int main()
{
loop:
	init();
	if(deng())
	{
loop1:
		system("cls");
		cout<<"                            图书管理系统           "<<endl;
		cout<<endl;
		cout<<endl;
		cout<<"图书信息:"<<endl;
		cout<<"     "<<"书名"<<"\t"<<"\t"<<"册数"<<"\t"<<"作者"<<"\t\t"<<"出版单位"<<endl;
		if(t1.getbo())
		t1.get(1);
		if(t2.getbo())
		t2.get(2);
		if(t3.getbo())
		t3.get(3);
		if(t4.getbo())
		t4.get(4);
		if(t5.getbo())
		t5.get(5);
		cout<<endl;
		cout<<endl;
		cout<<endl;
		cout<<"选择你要实现的功能:"<<endl;
		cout<<"1:\t"<<"借书"<<endl;
		cout<<"2:\t"<<"还书"<<endl;
		cout<<"3:\t"<<"修改"<<endl;
		cout<<"4:\t"<<"删除"<<endl;
		cout<<"5:\t"<<"退出"<<endl;
		char c;
		cin>>c;
		//        借书
		if(c=='1')
		{
loop3:
			char str[20];
			cout<<"选择你要借书的序号或名称"<<endl;
			cin>>str;
			if(!strcmp(str,"1")||!strcmp(str,t1.getshu()))
			{
				system("cls");
				if(t1.getce()>0)
				{
					cout<<"\t\t你借了一本"<<t1.getshu()<<endl;
					cout<<"\t\t希望对你有帮助"<<endl;
					t1.jiushu();
				}
				else
				{
					cout<<"\t\t该图书已全部借完了,希望你下次来借!"<<endl;
				}
			}
			else if(!strcmp(str,"2")||!strcmp(str,t2.getshu()))
			{
				system("cls");
				if(t2.getce()>0)
				{
					cout<<"\t\t你借了一本"<<t2.getshu()<<endl;
					cout<<"\t\t希望对你有帮助"<<endl;
					t2.jiushu();
				}
				else
				{
					cout<<"\t\t该图书已全部借完了,希望你下次来借!"<<endl;
				}
			}
			else if(!strcmp(str,"3")||!strcmp(str,t3.getshu()))
			{
				system("cls");
				if(t3.getce()>0)
				{
					cout<<"\t\t你借了一本"<<t3.getshu()<<endl;
					cout<<"\t\t希望对你有帮助"<<endl;
					t3.jiushu();
				}
				else
				{
					cout<<"\t\t该图书已全部借完了,希望你下次来借!"<<endl;
				}
			}
			else if(!strcmp(str,"4")||!strcmp(str,t4.getshu()))
			{
				system("cls");
				if(t4.getce()>0)
				{
					cout<<"\t\t你借了一本"<<t4.getshu()<<endl;
					cout<<"\t\t希望对你有帮助"<<endl;
					t4.jiushu();
				}
				else
				{
					cout<<"\t\t该图书已全部借完了,希望你下次来借!"<<endl;
				}
			}
			else if(!strcmp(str,"5")||!strcmp(str,t5.getshu()))
			{
				system("cls");
				if(t5.getce()>0)
				{
					cout<<"\t\t你借了一本"<<t5.getshu()<<endl;
					cout<<"\t\t希望对你有帮助"<<endl;
					t5.jiushu();
				}
				else
				{
					cout<<"\t\t该图书已全部借完了,希望你下次来借!"<<endl;
				}
			}
			else
			{
				cout<<"输入错误,没有该图书"<<endl;
				goto loop3;
			}
			cout<<"\t\t是否返回主界面(  T/F  )"<<endl;
			char s;
			cin>>s;
			if(s=='t'||s=='T')
			goto loop1;
			else
			{
				exit(0);
			}
		}
		//            还书
		else if(c=='2')
		{
loop4:
			char str[20];
			cout<<"选择你要还书的序号或名称"<<endl;
			cin>>str;
			if(!strcmp(str,"1")||!strcmp(str,t1.getshu()))
			{
				system("cls");
				if(t1.getce()<5)
				{
					cout<<"\t\t你还了一本"<<t1.getshu()<<endl;
					cout<<"\t\t希望下次再来借书!"<<endl;
					t1.huanshu();
				}
				else
				{
					cout<<"\t\t该图书没有借出,你还错地方了吧"<<endl;
				}
			}
			else if(!strcmp(str,"2")||!strcmp(str,t2.getshu()))
			{
				system("cls");
				if(t2.getce()<5)
				{
					cout<<"\t\t你还了一本"<<t2.getshu()<<endl;
					cout<<"\t\t希望下次再来借书!"<<endl;
					t2.huanshu();
				}
				else
				{
					cout<<"\t\t该图书没有借出,你还错地方了吧"<<endl;
				}
			}
			else if(!strcmp(str,"3")||!strcmp(str,t3.getshu()))
			{
				system("cls");
				if(t3.getce()<5)
				{
					cout<<"\t\t你还了一本"<<t3.getshu()<<endl;
					cout<<"\t\t希望下次再来借书!"<<endl;
					t3.huanshu();
				}
				else
				{
					cout<<"\t\t该图书没有借出,你还错地方了吧"<<endl;
				}
			}
			else if(!strcmp(str,"4")||!strcmp(str,t4.getshu()))
			{
				system("cls");
				if(t4.getce()<5)
				{
					cout<<"\t\t你还了一本"<<t4.getshu()<<endl;
					cout<<"\t\t希望下次再来借书!"<<endl;
					t4.huanshu();
				}
				else
				{
					cout<<"\t\t该图书没有借出,你还错地方了吧"<<endl;
				}
			}
			else if(!strcmp(str,"5")||!strcmp(str,t5.getshu()))
			{
				system("cls");
				if(t5.getce()<5)
				{
					cout<<"\t\t你还了一本"<<t5.getshu()<<endl;
					cout<<"\t\t希望下次再来借书!"<<endl;
					t5.huanshu();
				}
				else
				{
					cout<<"\t\t该图书没有借出,你还错地方了吧"<<endl;
				}
			}
			else
			{
				cout<<"输入错误,没有该图书"<<endl;
				goto loop4;
			}
			cout<<"\t\t是否返回主界面(  T/F  )"<<endl;
			char s;
			cin>>s;
			if(s=='t'||s=='T')
			goto loop1;
			else
			{
				exit(0);
			}
		}
		//             修改图书
		else if(c=='3')
		{
loop5:
			char str[20];
			cout<<"选择你要修改书的序号或名称"<<endl;
			cin>>str;
			if(!strcmp(str,"1")||!strcmp(str,t1.getshu()))
			{
			}
			else if(!strcmp(str,"2")||!strcmp(str,t2.getshu()))
			{
			}
			else if(!strcmp(str,"3")||!strcmp(str,t3.getshu()))
			{
			}
			else if(!strcmp(str,"4")||!strcmp(str,t4.getshu()))
			{
			}
			else if(!strcmp(str,"5")||!strcmp(str,t5.getshu()))
			{
			}
			else
			{
				cout<<"输入错误,没有该图书"<<endl;
				goto loop5;
			}
			system("cls");
			char shu[20],zuozhe[20],chuban[20];
			int ceshu,i;

loop2:
			cout<<"             选择你要修改的序号"<<endl;
			cout<<"               1.修改书名"<<endl;
			cout<<"               2.修改册数"<<endl;
			cout<<"               3.修改作者"<<endl;
			cout<<"               4.修改出版社"<<endl;
			cin>>i;
			if(i==1)
			{
				cout<<"输入书名:"<<endl;
				cin>>shu;
			}
			else if(2==i)
			{
				cout<<"输入册数:"<<endl;
				cin>>ceshu;
			}
			else if(3==i)
			{
				cout<<"输入作者:"<<endl;
				cin>>zuozhe;
			}
			else if(4==i)
			{
				cout<<"输入出版社:"<<endl;
				cin>>chuban;
			}
			else
			{
				cout<<"输入错误,没有该序号"<<endl;
				goto loop2;
			}
			if(!strcmp(str,"1")||!strcmp(str,t1.getshu()))
			{
				if(i==1)
				{
					t1.setshu(shu);
				}
				if(i==2)
				{
					t1.setceshu(ceshu);
				}
				if(i==3)
				{
					t1.setzuo(zuozhe);
				}
				if(i==4)
				{
					t1.setchuban(chuban);
				}
			}
			else if(!strcmp(str,"2")||!strcmp(str,t2.getshu()))
			{
				if(i==1)
				{
					t2.setshu(shu);
				}
				if(i==2)
				{
					t2.setceshu(ceshu);
				}
				if(i==3)
				{
					t2.setzuo(zuozhe);
				}
				if(i==4)
				{
					t2.setchuban(chuban);
				}	
			}
			else if(!strcmp(str,"3")||!strcmp(str,t3.getshu()))
			{
				if(i==1)
				{
					t3.setshu(shu);
				}
				if(i==2)
				{
					t3.setceshu(ceshu);
				}
				if(i==3)
				{
					t3.setzuo(zuozhe);
				}
				if(i==4)
				{
					t3.setchuban(chuban);
				}
			}
			else if(!strcmp(str,"4")||!strcmp(str,t4.getshu()))
			{
				if(i==1)
				{
					t4.setshu(shu);
				}
				if(i==2)
				{
					t4.setceshu(ceshu);
				}
				if(i==3)
				{
					t4.setzuo(zuozhe);
				}
				if(i==4)
				{
					t4.setchuban(chuban);
				}
			}
			else if(!strcmp(str,"5")||!strcmp(str,t5.getshu()))
			{
				if(i==1)
				{
					t5.setshu(shu);
				}
				if(i==2)
				{
					t5.setceshu(ceshu);
				}
				if(i==3)
				{
					t5.setzuo(zuozhe);
				}
				if(i==4)
				{
					t5.setchuban(chuban);
				}
			}
			char s;
			cout<<"\t\t是否继续修改?(  T/F  )"<<endl;
			cin>>s;
			if(s=='t'||s=='T')
			goto loop2;
			cout<<"\t\t是否返回主界面(  T/F  )"<<endl;
			cin>>s;
			if(s=='t'||s=='T')
			goto loop1;
			else
			{
				exit(0);
			}
		}
		//            删除图书
		else if(c=='4')
		{
loop6:
			char str[20];
			cout<<"选择你要删除书的序号或名称"<<endl;
			cin>>str;
			if(!strcmp(str,"1")||!strcmp(str,t1.getshu()))
			{
			}
			else if(!strcmp(str,"2")||!strcmp(str,t2.getshu()))
			{
			}
			else if(!strcmp(str,"3")||!strcmp(str,t3.getshu()))
			{
			}
			else if(!strcmp(str,"4")||!strcmp(str,t4.getshu()))
			{
			}
			else if(!strcmp(str,"5")||!strcmp(str,t5.getshu()))
			{
			}
			else
			{
				cout<<"输入错误,没有该图书"<<endl;
				goto loop6;
			}
			system("cls");
			cout<<"你确认要删除这本书吗(  T/F  )"<<endl;
			char cha;
			cin>>cha;
			if(cha=='t'||cha=='T')
			{
				if(!strcmp(str,"1")||!strcmp(str,t1.getshu()))
				{
					t1.setbo(false);
					cout<<"你删除了"<<t1.getshu()<<"信息"<<endl;
				}
				else if(!strcmp(str,"2")||!strcmp(str,t2.getshu()))
				{
					cout<<"你删除了"<<t2.getshu()<<"信息"<<endl;
					t2.setbo(false);
				}
				else if(!strcmp(str,"3")||!strcmp(str,t3.getshu()))
				{
					cout<<"你删除了"<<t3.getshu()<<"信息"<<endl;
					t3.setbo(false);
				}
				else if(!strcmp(str,"4")||!strcmp(str,t4.getshu()))
				{
					cout<<"你删除了"<<t4.getshu()<<"信息"<<endl;
					t4.setbo(false);
				}
				else if(!strcmp(str,"5")||!strcmp(str,t5.getshu()))
				{
					cout<<"你删除了"<<t5.getshu()<<"信息"<<endl;
					t5.setbo(false);
				}
			}
			goto loop1;
		}
		//            退出
		else if(c=='5')
		{
			system("cls");
			cout<<"            退出图书管理系统"<<endl;
			exit(0);
		}
		else
		{
			cout<<"你输入错误,请重新输入。"<<endl;
			goto loop1;
		}
	}
	else
	{
		cout<<"你输入的用户名或密码错误,请重新输入。"<<endl;
		goto loop;
	}
	return 0;
}

调试结果:




评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值