基于C++语言的图书管理系统

概要

语言:c++

因为时间原因目前只写了 创建 排序 和输出的功能后续会有时间再继续完善!

例如:

图书馆管理系统为例,用顺序表和链表的实现相应的功能。

顺序表功能:顺序表的初始化、取值、查找、插入和删除。

链表功能:链表的取值、按值查找、插入、删除、尾插法建立单链表。

并给出以上算法的主函数。

整体架构流程

顺序表功能:顺序表的初始化、取值、查找、插入和删除。

链表功能:链表的取值、按值查找、插入、删除、尾插法建立单链表。

例如:
在语言模型中,编码器和解码器都是由一个个的 Transformer 组件拼接在一起形成的。

技术名词解释

编者懒不想添加

技术细节

毫无技术性可言只是自己练着玩
细节问题请直接阅读代码

#include<iostream>
#include<stdlib.h>
#include<stdbool.h>
#include <iomanip> 
#include <algorithm>
#include<cstring>
#define maxsize 50//图书库存最大数量
//函数结果状态代码 
#define OK 1
#define ERROR 0
using namespace std; 
typedef int  structs;
typedef struct{
	int id;
	char isbn[20];//isbn号 
	char authorName[30];//作者姓名 
	char bookName[50];//图书名字 
	char publisher[40];//出版社
	char publishYear[10];//出版年份
	float price;//图书价格 
}Book;//是对这个结构体类型的声明
//意味着你现在可以使用Book作为一个新的数据类型来创建变量
 
 typedef struct{
 Book *elem;//存储空间的基地地址 
 int length;//数据结构的长度 
 }SqList;
 SqList BookSystem;
 
 //初始化线性表
int InitList(SqList *BookSystem){
    //构造一个空的顺序表BookSystem
    BookSystem->elem =  (Book*)malloc(sizeof(Book)*maxsize);   //分配内存空间
    if(!BookSystem->elem)exit(-1);   //存储分配失败
    BookSystem->length = 0;  //当前长度为0
    return OK;
}

//测试数据
 void insertBook(SqList *BookSystem){
    Book book[] = {{1,"5447395","余小华","《这么玩才赚钱》","人民邮电出版社","2017-01",49.50},
        {2,"4375152","达芙妮","《高情商心理学》","现代出版社","2016-11",20.00},
        {3,"6644188","郝言言","《悦己》","新华出版社","2007-04",25.00},
        {4,"0211267","路瑶","《平凡的世界》","北京文艺出版社","1986-12",30.00},
        {5,"6075642","张汝","《小时候》","海燕出版社","2013-06",33.00},
        {6,"1553645","陈果","《好的爱情》","人民日报出版社","2010-09",28.00}};
    int i = 0;  //循环变量
    for(i;i<6;i++){
        BookSystem->elem[i] = book[i];   //初始化图书
        BookSystem->length++;
    }
}
//图书管理系统操作的实现
 int showFunctions(){ 
    std::cout << std::setw(30) << std::setfill('*') << "" << "***************欢迎来到图书管理系统***************" << std::endl;  
    std::cout << std::setw(33) << std::setfill(' ') << "" << "1、创建系统\t2、输出图书\t3、图书排序" << std::endl;  
    std::cout << std::setw(33) << std::setfill(' ') << "" << "4、图书修改\t5、按名查找\t6、最贵图书" << std::endl;  
    std::cout << std::setw(33) << std::setfill(' ') << "" << "7、新书入库\t8、旧书出库\t9、退出系统" << std::endl;  
    std::cout << std::endl;  
    std::cout << std::setw(33) << std::setfill(' ') << "" << "请选择相关功能操作:" << std::endl;  
    int choice = -1; // 定义用户的选择并初始化  
    std::cin >> choice;  
    std::cout << std::setw(30) << std::setfill('*') << "" << "**************************************************" << std::endl;  
    return choice;   	
 } 
 //std::cout用于输出,std::cin用于输入。std::setw设置输出宽度,std::setfill设置填充字符。
 //这里使用iomanip库来实现此功能
  
 void creatBookSystem(SqList *BookSystem){
 	int i = 0;
 	std::cout << std::setw(30) << std::setfill(' ') <<""<<"系统:图书管理系统初始化中..."<<std::endl;
	  InitList(BookSystem);
	  insertBook(BookSystem);
	std::cout << std::setw(30) << std::setfill(' ') <<""<< "系统:图书管理系统初始化成功!"<<std::endl;
 } 
 //输出功能
 void showBook(SqList *BookSystem){
 	int j = 0;
 	for(j;j<115;j++){
 	std::cout<<"=";
	 }
 	std::cout<<std::endl;
 	std::cout<<" -id- ---ISBN--- --作者姓名-- ---图书名称--- -----出版社----- -出版年份- -图书价格-"<<std::endl;
	  if(BookSystem->length==0){
	std::cout<<std::setw(30)<<std::setfill(' ')<<""<<"系统:当前图书系统内无图书!"<<std::endl; 
	  }
	  int i=0;
	  for(i;i<BookSystem->length;i++){//打印图书信息 
	  	Book book = BookSystem->elem[i];
	  	printf("%-5s%-8d","",book.id);
        printf("%-15s",book.isbn);
        printf("%-13s",book.authorName);
        printf("%-23s",book.bookName);
        printf("%-24s",book.publisher);
        printf("%-14s",book.publishYear);
        printf("%.3f\n",book.price);
	  }
 	for(j=0;j<115;j++){
 		std::cout<<"=";
	 } 
 	std::cout<<std::endl;
 } 
 
 //排序
 void sortBook(SqList * BookSystem){
 	int i= 0;int j =0 ;int max_Index = -1;int choice = -1;Book temp;
 	printf("%-33s1、按名称排序\t2、按价格排序\t请选择:","");
 	cin>>choice;
 	if(choice==1){
 		for(i;i<BookSystem->length-1;i++){
 			max_Index = i;
 			for(j=i+1;j<BookSystem->length;j++){
 				if(strcmp(BookSystem->elem[max_Index].bookName,BookSystem->elem[j].bookName)>0){
 					max_Index=j;
				 }
			 }
			 temp=BookSystem->elem[i];
			 BookSystem->elem[i]=BookSystem->elem[max_Index];
			 BookSystem->elem[max_Index]=temp; 
		 }
	 }
 	if(choice=2){
 		for(i;i<BookSystem->length-1;i++){
 			max_Index=i;
 			for(j=i+1;j<BookSystem->length;j++){
 				if(BookSystem->elem[max_Index].price<BookSystem->elem[j].price){
 					max_Index=j;
				 }
			 }
 			temp=BookSystem ->elem[i];
 			
 			BookSystem->elem[i]=BookSystem->elem[max_Index];
 			BookSystem->elem[max_Index]=temp;

		 }
 		
 		
	 }
 	cout<<"排序完毕";
	 i=0;
	 for(i=0;i<BookSystem->length;i++){
	 	BookSystem->elem[i].id=i+1;
	 } 
 	
 	
 } 
 //修改 
 
 //主函数 
 int main(){
 	bool isCreated = false;
 	while(true){
 		int choice = showFunctions();//调用函数取得用户选择的功能
		 if(choice==1){
		 	creatBookSystem(&BookSystem);
			 	isCreated=true;
				 continue;	//跳出当前循环然后进行下一循环
		 }
 	if(choice == 2&&isCreated){
            system("cls");
            showBook(&BookSystem);
            continue;
        }
        if(choice==3&&isCreated){
            sortBook(&BookSystem);
            break;
	 }
}
 	return 0;
 } 

例如:
文心一言
Chat Gpt 3.5
Ctrl c v

小结

欢迎各位大佬批评指正!!!
在这里插入图片描述

提供先进的推理,复杂的指令,更多的创造力。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值