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

数据结构图书管理系统课程设计_数据结构用链表建立图书管理系统《图书信息管理系统》的制作:例:全部代码如下(各部分已注释):#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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 最详细的APAP论文代码分析

    最详细的APAP论文代码分析最详细的APAP论文代码分析代码见:https://cs.adelaide.edu.au/~tjchin/apap/此次实验选用的代码是2013年的版本:由于文档中的代码块截图不一定清楚,需要的可以去上面的网址下载代码对照着看。一、代码1.1、加载文件在程序开始前调用close、clear等函数清除原先工作空间的操作,然后将此次实验所需的文件文件添加到环境中。1.2、编译Mex文件经过对代码块添加测试代码,证明了此处的代码块并未执行,在命令行仅仅输出了对文件的判断,而未输出if-end

    2025年12月8日
    2
  • 常见计算机病毒类型及原理「建议收藏」

    常见计算机病毒类型及原理「建议收藏」杀毒软件是根据什么来进行病毒判断并查杀得呢?病毒检测的方法在与病毒的对抗中,及早发现病毒很重要。早发现,早处置,可以减少损失。检测病毒方法有:特征代码法、校验和法、行为监测法、软件模拟法这些方法依据的原理不同,实现时所需开销不同,检测范围不同,各有所长。特征代码法特征代码法被早期应用于SCAN、CPAV等著名病毒检测工具中。国外专家认为特征代码法是检

    2022年6月5日
    44
  • MyBatis面试题(2020最新版)

    MyBatis面试题(2020最新版)整理好的MyBatis面试题库,史上最全的MyBatis面试题,MyBatis面试宝典,特此分享给大家MyBatis介绍MyBatis是一款优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射。MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。MyBatis可以使用简单的XML或注解来配置和映射原生类型、接口和Java的POJO(Plai…

    2022年6月14日
    30
  • Java volatile关键字最全总结:原理剖析与实例讲解(简单易懂)

    Java volatile关键字最全总结:原理剖析与实例讲解(简单易懂)一、简介volatile是Java提供的一种轻量级的同步机制。Java语言包含两种内在的同步机制:同步块(或方法)和volatile变量,相比于synchronized(synchronized通常称为重量级锁),volatile更轻量级,因为它不会引起线程上下文的切换和调度。但是volatile变量的同步性较差(有时它更简单并且开销更低),而且其使用也更容易出错。二、并发编程的3…

    2022年4月27日
    56
  • JQuery学习—JQuery的Validform学习

    JQuery的Validform学习

    2022年2月24日
    52
  • 几款.Net加密/加壳工具的比较

    几款.Net加密/加壳工具的比较前言  使用过.NET的程序员都知道,.NET是一个巨大的跨时代进步,它开发效率高、功能强、界面观、耐用、新的语言C#已经提交为行业规范、CLR共公运行库资源丰富,这所有的特点标志着它成为主流编程语言是必然的。     可是它也有一个缺点,那就是编译好的程序集可以完全反编译成源代码,这给一些不法份子提供了很好的机会,试想想,您辛苦的劳动成果就这样给了别人;所以如何保护我们的知识产

    2022年6月27日
    39

发表回复

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

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