图书管理系统C++

这是一个使用C++编写的图书管理系统,包括图书的添加、查询、修改、删除和销售等功能。用户可以通过ISBN号、书名、作者或出版社进行查询,系统会检查ISBN号的唯一性,并在销售时验证库存量。此外,还提供了统计展示图书信息的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图书管理系统(C++课程设计)

程序描述:
该程序运用C++标准语言进行设计(#include),编辑一个通过操作台进行控制运行的图书管理系统;选用主函数外编写子函数进行套用,通俗易懂,可以为课程设计提供思路方法与语言知废话不多说,下面是详细题目,流程图与源代码!

“图书管理系统设计”
1、问题描述
定义图书类,属性有:书名、出版社、ISBN号、作者、库存量、价格等信息和相关的对属性做操作的行为。
主要完成对图书的销售、统计和图书的简单管理。
2、功能要求
(1)销售功能。购买书籍时,输入相应的ISBN号,并在书库中查找该书的相关信息。如果有库存量,输入购买的册数,进行相应计算。如果库存量不够,给出提示信息,结束购买。
(2)图书简单管理功能。
添加功能:主要完成图书信息的添加,要求ISBN号唯一。当添加了重复的编号时,则提示数据添加重复并取消添加。
查询功能:可按书名、ISBN号、作者、出版社进行查询。若存在相应信息,输出所查询的信息,若不存在该记录,则提示“该标题不存在!”。
修改功能:可根据查询结果对相应的记录进行修改,修改时注意ISBN号的唯一性。
删除功能:主要完成图书信息的删除。输入要删除的ISBN号,根据编号删除该物品的记录,如果该编号不在物品库中,则提示“”。
(3)统计功能。
输出当前书库中所有图书的总数及详细信息;可按书的价格、库存量、作者、出版社进行统计,输出统计信息

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
struct book//定义结构体变量
{
	char name[31];
	char chubanshe[27];
	double ABSN;
	char zuozhe[31];
	int kc;
	double price;
};
book books[100];
void title(const char menu[30]) //显示标题函数 
{
	cout << "               ******************************************************************"<< endl;
	cout << "               ***                                                                                    ***" << endl;
	cout << "               ***                          欢迎使用图书管理系统                      ***" << endl;
	cout << "               ***                                                                                    ***" << endl;
	cout << "               ******************************************************************" << endl;
	cout << endl;
	cout << menu << endl;
}
void menushow()
{
	cout << "   ------------------------------------------" << endl;
	cout << "   |      1>添加新书   |   2>查询图书信息   |" << endl;
	cout << "   ------------------------------------------" << endl;
	cout << "   |      3>修改图书   |   4>删除图书       |" << endl;
	cout << "   ------------------------------------------" << endl;
	cout << "   |      5>销售图书   |   6>统计展示图书   |" << endl;
	cout << "   ------------------------------------------" << endl;
	cout << "   |           **** 7>退出系统 ****         |" << endl;
	cout << "   ------------------------------------------" << endl;
	cout << endl;
	cout << "请输入数字键实现功能  :";
}
void retuen() //返回函数 
{
	cout << "请按任意键返回";
	getchar();
}
void book_add()//指向添加新书的函数
{
	int i, n;
	system("cls");
	cout << "请输入要添加多少种书(请输入大于零的整数)" << endl;
biepi:
	cin >> n;
	if (n == 0)
	{
		cout << "你输入的数不合规定,请重新输入" << endl;
		goto biepi;
	}
	system("cls");//使用清屏函数
	title("请输入书本信息");//引用标题函数 
	for (i = 0; i < n; i++)
	{
	cxtj:
		cout << "书名:";
		cin >> books[i].name;
		cout << "出版社:";
		cin >> books[i].chubanshe;
		cout << "ABSN码(请勿输入重复的ABSN码,ABSN码为double型,且首数字不可为0或-1)" << endl;
		cin >> books[i].ABSN;
		for (int n = -1; n < i; n++)
		{
			if (books[i].ABSN == books[n].ABSN || books[i].ABSN == 0 || books[i].ABSN == -1)
			{
				cout << "数据添加不符合规定或添加重复,已取消添加,请重新添加" << endl;
				goto cxtj;
			}
		}
		cout << "作者:";
		cin >> books[i].zuozhe;
		cout << "库存:";
		cin >> books[i].kc;
		cout << "价格:";
		cin >> books[i].price;
		cout << endl;
	}
	retuen();
	getchar();
}
void book_show()//指向统计展示图书的函数
{
	system("cls");
	title("统计展示结果显示");
	int shubencz = 0;
	for (int i = 0; i < 100; i++)
	{
		if (books[i].kc != 0)
		{
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			shubencz = 1;
		}
	}
	if (shubencz == 0)
	{
		cout << endl;
		cout << "       *************************************************" << endl;
		cout << "       *******         --库内暂无图书--          *******" << endl;
		cout << "       *************************************************" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void book_queryzi2()//在用指向查询信息的函数时用的子函数
{
	double a;
	cin >> a;
	int a1 = 0;
	for (int i = 0; i < 100; i++)
	{
		if (books[i].ABSN == a)
		{
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			a1 = 1;
		}
	}
	if (a1 == 0)
	{
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void  book_queryzi1()//在用指向查询信息的函数时用的子函数
{
	char a[30];
	cin >> a;
	int a1 = 0;
	for (int i = 0; i < 100; i++)
	{
		if (strcmp(books[i].name, a) == 0)
		{
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			a1 = 1;
		}
	}
	if (a1 == 0)
	{
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void  book_queryzi3()//在用指向查询信息的函数时用的子函数
{
	char a[30];
	cin >> a;
	int a1 = 0;
	for (int i = 0; i < 100; i++)
	{
		if (strcmp(books[i].chubanshe, a) == 0)
		{
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			a1 = 1;
		}
	}
	if (a1 == 0)
	{
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void  book_queryzi4()//在用指向查询信息的函数时用的子函数
{
	char a[30];
	cin >> a;
	int a1 = 0;
	for (int i = 0; i < 100; i++)
	{
		if (strcmp(books[i].zuozhe, a) == 0)
		{
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			a1 = 1;
		}
	}
	if (a1 == 0)
	{
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void book_query()//指向查询信息的函数
{
	system("cls");
	title("查询图书信息");
	cout << "可以查询的书本信息(1.书名、2.ASBN号、3.出版社、4.作者)" << endl;
	cout << "若有相同信息的图书,则系统默认依次修改" << endl;
	cout << "请选择用哪种书本信息查询(输入数字):::::";
	int shuzixx;
	cin >> shuzixx;
	if (shuzixx == 1)
	{
		system("cls");
		cout << "请输入您所查询的书本的书本信息" << endl;
		book_queryzi1();
	}
	if (shuzixx == 2)
	{
		system("cls");
		cout << "请输入您所查询的书本的书本信息" << endl;
		book_queryzi2();
	}
	if (shuzixx == 3)
	{
		system("cls");
		cout << "请输入您所查询的书本的书本信息" << endl;
		book_queryzi3();
	}
	if (shuzixx == 4)
	{
		system("cls");
		cout << "请输入您所查询的书本的书本信息" << endl;
		book_queryzi4();
	}
	if (shuzixx != 1 && shuzixx != 2 && shuzixx != 3 && shuzixx != 4)
	{

		system("cls");
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
		retuen();
		getchar();
	}
}
void  book_queryzxgzi134()//信息修改函数中用到的子函数
{
	char a[30];
	cin >> a;
	system("cls");
	int a1 = 0;
	int i = 0;
	for (; i < 100; i++)
	{
		if (strcmp(books[i].name, a) == 0 || strcmp(books[i].chubanshe, a) == 0 || strcmp(books[i].zuozhe, a) == 0)
		{
			cout << "查询结果为;" << endl;
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			a1 = 1;
			int j;
			cout << "选择要修改的数据(请输入数字--1.书名、2.ASBN号、3.出版社、4.作者、5.库存、6.价格)" << endl;
			cin >> j;
			if (j != 1 && j != 2 && j != 3 && j != 4 && j != 5 && j != 6)
			{
				cout << "该编号标题不存在,请重新输入!" << endl;
				cin >> j;
			}
			if (j == 1)
			{
				cout << "请输入您要将" << books[i].name << "修改为:" << endl;
				cin >> books[i].name;
			}
			if (j == 2)
			{
				cout << "请输入您要将" << books[i].ABSN << "修改为:" << endl;
				cin >> books[i].ABSN;
			}
			if (j == 3)
			{
				cout << "请输入您要将" << books[i].chubanshe << "修改为:" << endl;
				cin >> books[i].chubanshe;
			}
			if (j == 4)
			{
				cout << "请输入您要将" << books[i].zuozhe << "修改为:" << endl;
				cin >> books[i].zuozhe;
			}
			if (j == 5)
			{
				cout << "请输入您要将" << books[i].kc << "修改为:" << endl;
				cin >> books[i].kc;
			}
			if (j == 6)
			{
				cout << "请输入您要将" << books[i].price << "修改为:" << endl;
				cin >> books[i].price;
			}
			cout << "修改后的内容为:" << endl;
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
		}
	}
	if (a1 == 0)
	{
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void book_queryzxgzi2()//信息修改函数中用到的子函数
{
	double a;
	cin >> a;
	system("cls");
	int a1 = 0;
	int i = 0;
	for (; i < 100; i++)
	{
		if (books[i].ABSN == a)
		{
			cout << "查询结果为;" << endl;
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			a1 = 1;
			int j;
			cout << "选择要修改的数据(请输入数字--1.书名、2.ASBN号、3.出版社、4.作者、5.库存、6.价格)" << endl;
			cin >> j;
			if (j != 1 && j != 2 && j != 3 && j != 4 && j != 5 && j!= 6)
			{
				cout << "该编号标题不存在,请重新输入!" << endl;
				cin >> j;
			}
			if (j == 1)
			{
				cout << "请输入您要将" << books[i].name << "修改为:" << endl;
				cin >> books[i].name;
			}
			if (j == 2)
			{
				cout << "请输入您要将" << books[i].ABSN << "修改为:" << endl;
				cin >> books[i].ABSN;
			}
			if (j == 3)
			{
				cout << "请输入您要将" << books[i].chubanshe << "修改为:" << endl;
				cin >> books[i].chubanshe;
			}
			if (j == 4)
			{
				cout << "请输入您要将" << books[i].zuozhe << "修改为:" << endl;
				cin >> books[i].zuozhe;
			}
			if (j == 5)
			{
				cout << "请输入您要将" << books[i].kc<< "修改为:" << endl;
				cin >> books[i].kc;
			}
			if (j == 6)
			{
				cout << "请输入您要将" << books[i].price << "修改为:" << endl;
				cin >> books[i].price;
			}
			cout << "修改后的内容为:" << endl;
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
		}
	}
	if (a1 == 0)
	{
		cout << endl;
		cout << "该标题不存在!" << endl;
		cout << endl;
	}
	retuen();
	getchar();
}
void book_xiugai()//信息修改函数(查询函数的变化)
{
	system("cls");
	title("查询图书信息并修改");
	cout << "用于查询的书本信息(1.书名、2.ASBN号、3.出版社、4.作者 )" << endl;
	cout << "请选择用哪种书本信息进行查询并修改(输入数字):::::";
	int shuzixx;
	cin >> shuzixx;
	if (shuzixx == 1 || shuzixx == 3 || shuzixx == 4)
	{
		cout << "请输入您要查询并修改的书本的书本信息(所选数字对应的图书信息)" << endl;
		book_queryzxgzi134();
	}

	if (shuzixx == 2)
	{
		cout << "请输入您所查询后修改的书本的书本信息(所选数字对应的图书信息)" << endl;
		book_queryzxgzi2();
	}
	if (shuzixx != 1 && shuzixx != 2 && shuzixx != 3 && shuzixx != 4)
	{

		system("cls");
		cout << endl;
		cout << "该标题不存在!!!" << endl;
		cout << endl;
		retuen();
		getchar();
	}
}
void book_shanchu()//图书删除函数
{
	int i, j;
	system("cls");
	title("删除图书");
	cout << endl;
	cout << "请输入需要删除的书的ABSN码:" << endl;
	double a;
	cin >> a;
	for (i = 0; i < 100; i++)
	{
		if (books[i].ABSN == a)
		{
			for (j = i; j < 100; j++)
			{
				books[j].ABSN = books[j + 1].ABSN;
				strcpy_s(books[j].name, books[j + 1].chubanshe);
				strcpy_s(books[j].chubanshe, books[j + 1].chubanshe);
				strcpy_s(books[j].zuozhe, books[j + 1].zuozhe);
				books[j].kc = books[j + 1].kc;
				books[j].price = books[j + 1].price;
			}
			cout << "该图书已删除" << endl;
			goto  zhijieliu;
		}
	}
	cout << "该编号不存在 !" << endl;
	cout << endl;
zhijieliu:
	retuen();
	getchar();
}
void book_goumai()//图书购买函数
{
	int i, j, k;
	double a, m;
	system("cls");
	title("图书销售");
	cout << endl;
	cout << "*请输入想要购买的图书的ABSN码,若不知道ABSN码请输入-1跳转至主界面用查询功能进行查询" << endl;
	cout << "请输入ABSN码或-1:" << endl;
	cin >> a;
	if (a == -1)
		goto baibai;
	for (i = 0; i < 100; i++)
	{
		if (books[i].ABSN == a)
		{
			cout << "该图书目前库存信息如下;" << endl;
			cout << "  书名:" << books[i].name;
			cout << "  出版社:" << books[i].chubanshe;
			cout << "  ABSN码:" << books[i].ABSN;
			cout << "  作者:" << books[i].zuozhe;
			cout << "  库存:" << books[i].kc;
			cout << "  价格:" << books[i].price << endl;
			cout << "请输入您要购买的数量:" << endl;
			cin >> k;
			if (k > books[i].kc)
			{
				cout << "库存不够,请重新输入购买数量!!!" << endl;
				cin >> k;
			}
			else
			{
				cout << "您需要支付的价格为;" << endl;
				m = k * books[i].price;
				books[i].kc = books[i].kc - k;
				cout << m << endl;
			}
		}
	}
	cout << "该编号不存在 !" << endl;
		cout << endl;
baibai:
	retuen();
	getchar();
}
int main()
{
huilai:
	system("cls");
	title("操作选项---");
	cout << endl;
	menushow();
	switch (getchar())//布尔型函数应用
	{
	case'1': book_add(); break;
	case'2': book_query(); break;
	case'3': book_xiugai(); break;
	case'4': book_shanchu(); break;
	case'5': book_goumai(); break;
	case'6': book_show(); break;
	case'7':exit(0); break;//退出函数
	}
	goto huilai;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

入门的小白白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值