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

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


相关推荐

  • 字符串匹配的kmp算法_多字符串匹配

    字符串匹配的kmp算法_多字符串匹配一、背景  给定一个主串(以S代替)和模式串(以P代替),要求找出P在S中出现的位置,此即串的模式匹配问题。  Knuth-Morris-Pratt算法(简称KMP)是解决这一问题的常用算法之一,这个算法是由高德纳(DonaldErvinKnuth)和沃恩·普拉特在1974年构思,同年詹姆斯·H·莫里斯也独立地设计出该算法,最终三人于1977年联合发表。  在继…

    2022年8月21日
    8
  • 100999凑整到万位进一_速算方法 速算口诀[通俗易懂]

    100999凑整到万位进一_速算方法 速算口诀[通俗易懂]“估算法”毫无疑问是资料分析题当中的速算第一法,在所有计算进行之前必须考虑能否先行估算。所谓估算,是在精度要求并不太高的情况下,下面是出国留学网小编为大家整理的“速算方法”。本内容为大家提供参考。希望对您有所帮助。请关注出国留学网!!!速算方法一、▲“九几乘九几,左减右补数,后面空两格,写上补乘补。”9300-5005×7=880035=883500看作两个空格二、▲任意数乘25,等于此数…

    2022年6月15日
    72
  • EXTJS详细教程

    EXTJS详细教程布局和容器普通布局Ext.create(‘Ext.panel.Panel’,{renderTo:Ext.getBody(),width:400,height:300,title:’ContainerPanel’,items:[{xtype:’panel’,title:’ChildPanel1′,height:100,width:’75%’},{

    2022年6月18日
    33
  • 数字 和 大小写字母之间的转换 10进制和26进制之间的转换「建议收藏」

    数字 和 大小写字母之间的转换 10进制和26进制之间的转换「建议收藏」/**数字转大写字母(26进制)1-&gt;A2-&gt;B*@sinceJDK1.8*/publicstaticStringnumCovertLetter(intnum){if(num&lt;=0){thrownewRuntimeException("参数必须大于0");…

    2025年11月28日
    3
  • VBA listview控件「建议收藏」

    VBA listview控件「建议收藏」
    1、在Listview控件中,用ColumnHeaders对象来操作列,而添加新的列可以用ColumnHeaders对象的ADD方法。具体如下: 
    ListView1.ColumnHeaders.Add序号,唯一的字符串标识,列标显示文字,列宽,列的内容对齐方式,所使用的图标序号。
    对齐方式有:lvwColumnLeft 、 lvwColumnCenter、lvwColumnRight                                            

    2022年7月16日
    16
  • python语言中的多行注释符是_Pyhton 单行、多行注释符号使用方法及规范「建议收藏」

    python语言中的多行注释符是_Pyhton 单行、多行注释符号使用方法及规范「建议收藏」python中的注释有多种,有单行注释,多行注释,批量注释,中文注释也是常用的。python注释也有自己的规范,在文章中会介绍到。注释可以起到一个备注的作用,团队合作的时候,个人编写的代码经常会被多人调用,为了让别人能更容易理解代码的通途,使用注释是非常有效的。# 在学习python的朋友们,强烈推荐加入PythonQQ群。一、python单行注释符号(#)井号(#)常被用作单行注释符号,在代码…

    2025年5月24日
    1

发表回复

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

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