数据结构图书管理系统课程设计_数据结构用链表建立图书管理系统

数据结构图书管理系统课程设计_数据结构用链表建立图书管理系统《图书信息管理系统》的制作:例:全部代码如下(各部分已注释):#include “pch.h”#include<string>#include<fstream>#include <iomanip>#include <iostream>using namespace std;#define MAXSIZE 100struct…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

《图书信息管理系统》的制作:

在这里插入图片描述
全部代码如下(各部分已注释):

#include "pch.h"
#include<string>
#include<fstream>
#include <iomanip>
#include <iostream>

using namespace std;
#define MAXSIZE 100

struct Book
{ 
   
	string id;
	string name;
	double price;
};

//顺序表结构体
struct SqList
{ 
   
	Book *elem;		//线性表初始位置
	int length;		//线性表长度

};

//初始化线性表
void initSqList(SqList &L)
{ 
   
	L.elem = new Book[MAXSIZE];
	if (!L.elem)
	{ 
   
		exit(0);
	}
	L.length = 0;
}

//线性表的取值
int GetElem(SqList &L, int i, Book &e)
{ 
   
	if (i<1||i>L.length)
	{ 
   
		return -1;
	}

	e=L.elem[i - 1];
	return 0;
} 

//线性表的查找
int LocateElem(SqList &L,string e)
{ 
   
	for (int i = 0; i < L.length; i++)
	{ 
   
		if (L.elem[i].id==e)
		{ 
   
			cout << "所查找书籍信息为:";
			cout << L.elem[i].id << " ";
			cout << L.elem[i].name << " ";
			cout << L.elem[i].price << endl;
			cout << "书籍查找成功!!" << endl;
			return i + 1;
		}
	}
	cout << "查无此书!!" << endl;
	return 0;
}

//线性表的插入
int InsertSqList(SqList &L, int i, Book e)
{ 
   
	//是否超出线性表的区间范围
	if (i<1||i>L.length+1)
	{ 
   
		return -1;
	}
	//当前元素超过线性表长度则无法插入
	if (L.length==MAXSIZE)
	{ 
   
		return -1;
	}

	//
	for (int j = L.length-1; j>=i-1; j--)
	{ 
   
		L.elem[j + 1] = L.elem[j];
	}
	L.elem[i - 1] = e;
	++L.length;
	return 1;
}

//线性表的删除
int DeleteSqList(SqList &L, int i)
{ 
   
	//是否超出线性表的区间范围
	if (i<1 || i>L.length + 1)
	{ 
   
		return 0;
	}
	for (int j = i; j <=L.length; j++)
	{ 
   
		L.elem[j - 1] = L.elem[j];
	}
	--L.length;
	return 1;
}

int main()
{ 
   
	SqList L;
	int c;					//删除书籍位置
	int choice = -1;
	string str1, str2, str3;

	cout << "*****************************************" << endl;
	cout << "****** 图书管理系统 *****" << endl;
	cout << "*****************************************" << endl;
	cout << "****** 1.建立 2.录入 *****" << endl;
	cout << "****** 3.取值 4.查找 *****" << endl;
	cout << "****** 5.插入 6.删除 *****" << endl;
	cout << "****** 7.输出 0.退出 *****" << endl;
	cout << "*****************************************" << endl;

	while (choice != 0)
	{ 
   
		cout << "请输入操作指令【0-7】" << endl;

		cin >> choice;
		int i = 0;
		switch (choice)
		{ 
   
			
		case 1:
		{ 
   
			initSqList(L);
			cout << "顺序表创建成功" << endl;
			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;

			break;
		}
		case 2:
		{ 
   
			L.elem = new Book[MAXSIZE];
			if (!L.elem)
			{ 
   
				exit(0);
			}
			L.length = 0;

			fstream file;
			file.open("book.txt");

			file >> str1 >> str2 >> str3;

			while (!file.eof())
			{ 
   
				file >> L.elem[i].id >> L.elem[i].name >> L.elem[i].price;
				i++;
			}
			cout << "book书库书籍信息导入成功" << endl;

			L.length = i;
			file.close();
			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;

			break;

		}
		case 3:
		{ 
   
			cout << "请输入取值图书位置:";
			cin >> i;
			Book em;
			GetElem(L,i,em);
			cout << em.id << " ";
			cout << em.name << " ";
			cout << em.price << endl;
			cout << "书籍取值成功!" << endl;
			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;
			break;
		}
		case 4:
		{ 
   
			Book em;	
			cout << "请输入查找图书编号:";
			cin >>em.id;
			LocateElem(L, em.id);

			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;

			break;
		}
		case 5:
		{ 
   
			cout << "请输入所要插入的位置:";
			cin >> i;
			Book em;
			cout << "请输入所要插入书籍的ID,书名,价格:";
			cin >> em.id >> em.name >> em.price;
			InsertSqList(L, i, em);
			cout << "书籍插入成功!" << endl;
			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;

			break;
		}
		case 6:
		{ 
   
			cout << "请输入要删除书籍位置:";
			cin >> c;
			if (DeleteSqList(L, c))
			{ 
   
				cout << "书籍删除成功!" << endl;
			}
			else
			{ 
   
				cout << "书籍删除失败!" << endl;
			}
			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;

			break;
		}
		case 7:
		{ 
   
			cout << "当前图书管理系统的所有图书信息如下:" << endl;
			for (int i = 0; i < L.length; i++)
			{ 
   
				cout << L.elem[i].id << setw(25);
				cout << L.elem[i].name << setw(15);
				cout << L.elem[i].price << endl;
			}
			cout << endl;
			cout << "*****************************************" << endl;
			cout << "****** 图书管理系统 *****" << endl;
			cout << "*****************************************" << endl;
			cout << "****** 1.建立 2.录入 *****" << endl;
			cout << "****** 3.取值 4.查找 *****" << endl;
			cout << "****** 5.插入 6.删除 *****" << endl;
			cout << "****** 7.输出 0.退出 *****" << endl;
			cout << "*****************************************" << endl;

			break;
		}
		case 0:
		{ 
   
			break;
		}
		}
	}
	return 0;
}

结果为:
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170975.html原文链接:https://javaforall.net

(0)
上一篇 2022年8月18日 上午9:16
下一篇 2022年8月18日 上午9:16


相关推荐

  • 一种基于HBase韵海量图片存储技术

    一种基于HBase韵海量图片存储技术针对海量图片存储,已有若干个基于Hadoop的方案被设计出来。这些方案在系统层小文件合并、全局名字空间以及通用性方面存在不足。本文基于HBase提出了一种海量图片存储技术,成功解决了上述问题。本文将介绍基于HBase海量图片存储技术方案,分析其原理及优势,该方案在城市交通监控中得到应用验证。   随着互联网、云计算及大数据等信息技术的发展,越来越多的应用依赖于对海量数据的存储和处理,如智

    2022年7月14日
    25
  • metasploit指令_msfconsole下载

    metasploit指令_msfconsole下载在MSF里面msfconsole可以说是最流行的一个接口程序。很多人一开始碰到msfconsole的时候就害怕了。那么多复杂的命令语句需要学习,但是msfconsole真的是一个强大的接口程序。Msfconsole提供了一个一体化的集中控制台。通过msfconsole,你可以访问和使用所有的metasploit的插件,payload,利用模块,post模块等等。Msfconsole还有第三方程序的…

    2025年9月30日
    7
  • AI 应用开发工程师(Agent方向):打造未来的智能体架构!

    AI 应用开发工程师(Agent方向):打造未来的智能体架构!

    2026年3月15日
    2
  • LeetCode报错:AddressSanitizer:DEADLYSIGNAL详细分析与解决

    LeetCode报错:AddressSanitizer:DEADLYSIGNAL详细分析与解决LeetCode报错:AddressSanitizer:DEADLYSIGNAL详细分析与解决问题描述问题分析实例分析更多总结见:C刷题:LeetCode刷题踩坑常见BUG总结问题描述报错:AddressSanitizer:DEADLYSIGNAL,详细如下===42====ERROR:AddressSanitizer:SEGVonunknownaddressxx.ThesignaliscausedbyaREADmemoryaccess.问题分析一般可能主要有

    2025年8月5日
    5
  • TDD与FDD

    TDD与FDDFDD和TDD主要区别就在于采用不同的双工方式,为频分双工(FDD)和时分双工(TDD)是两种不同的双工方式。FDD是在分离的两个对称频率信道上进行接收和发送,用保护频段来分离接收和发送信道。FDD的缺点就是必须采用成对的频率,依靠频率来区分上下行链路,其单方向的资源在时间上是连续的。FDD虽然在支持对称业务时,能充分利用上下行的频谱,但在支持非对称业务时,频谱利用率将大大降低。  …

    2022年6月13日
    40
  • 关于使用XLSTransformer.transformXLS导出Excel表格中遇到的问题

    关于使用XLSTransformer.transformXLS导出Excel表格中遇到的问题1.需求:最近拿到的一个任务,是将订单列表导出,按照订单列表导出(包括筛选条件)。背景:由于原本的订单列表查询代码太过繁重,里面夹杂的逻辑较多,再有一个是自己想尽快的熟悉公司的业务。于是决定,自己按照原本的样子重新写一个查询的逻辑。历程:原本以为这个功能会比较简单,用不了几天。原本打算用4天把这个需求搞定。结果,到今天结束用了10天。这大大的超出了我的预估。这也有开发系统故障的原因,导…

    2022年7月24日
    10

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号