首页 > 其他分享 >图书管理系统

图书管理系统

时间:2023-01-17 12:33:31浏览次数:33  
标签:node struct 管理系统 int next book printf 图书

可能有点bug,没具体测试

期末作业写的很拉胯

#pragma once

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct book_info
{
	char* book_num;
	char* book_name;
	char* author_name;
	char* publisher;
	int year;
	int mon;
	int day;
	double price;
}infom;

typedef struct book_node
{
	infom book;
	struct book_node* next;
}book_node, * Llist;

//创建表头
struct book_node* createHead();

void menu();
//创建头结点
struct book_node* Create_book_Doc();
int IsRightDate(int year, int mon, int day);
int Mday(int year, int mon);
int IsLeapYear(int year);
//打印整个链表
void Print_All_booknode(struct book_node* head);
//打印某一节点
void Print_node(struct book_node* node);
//冒泡排序
void BubbleSortOfList(struct book_node* list);
//书名查找
void SearchNodePrintByName(struct book_node* list);
//书号查找删除
void SearchNodeDelByNum(struct book_node* list);
//书号查找修改
struct book_node* SearchNodeModifyByNum(struct book_node* list, struct book_node* L);
void ModifyInfom(struct book_node* node);

  

#define _CRT_SECURE_NO_WARNINGS 1

#include "book.h"

int main()
{
	//创建头结点
	struct book_node* List = createHead();
	//两个临时节点
	struct book_node* node = NULL, * p = NULL;

	char ch = 0;
	int flag = 1;

	do
	{
		menu();
		scanf("%c%*c", &ch);
		switch (ch)
		{
		case 'a':
		case 'A':
			 p = Create_book_Doc();
			 if (flag)
			 {
				 List->next = p;
				 flag = 0;
			 }
			 else
			 {
				 node->next = p;
			 }
			 node = p;
			break;
		case 'f':
		case 'F':
			SearchNodePrintByName(List);
			break;
		case 'r':
		case 'R':
			SearchNodeDelByNum(List);
			break;
		case 'm':
		case 'M':
			node = SearchNodeModifyByNum(List,node);
			break;
		case 's':
		case 'S':
			BubbleSortOfList(List);
			Print_All_booknode(List);
			break;
		case 'q':
		case 'Q':
			printf("Thank you! Goodbye!\n");
			ch = 0;
			break;
		default :
			printf("Incorrect choice!");
			break;
		}
	} while (ch);
	return 0;
}

  

#define _CRT_SECURE_NO_WARNINGS 1

#include "book.h"

void menu()
{
	printf("Append Find Remove Modify Show Quit > ");
}

struct book_node* createHead()
{
	struct book_node* headnode = (struct book_node*)malloc(sizeof(struct book_node));
	headnode->next = NULL;
	return headnode;
}

struct book_node* Create_book_Doc()
{
	//临时变量
	struct book_node* p ;
	char* book_num;
	char* book_name;
	char* author_name;
	char* publisher;

	//定义储存空间
	book_num = (char*)malloc(8);
	book_name = (char*)malloc(8);
	author_name = (char*)malloc(8);
	publisher = (char*)malloc(8);

	//定义临时变量,赋值给节点
	int year = -1;
	int mon = -1;
	int day = -1;
	double price;

	//计算结构体的大小
	int sz = sizeof(struct book_node);

	//输入储存数据
	printf("     ISBN: ");
	scanf("%s", book_num);
	printf("    Title: ");

	//读取'\n'
	getchar();
	gets(book_name);
	printf("   Author: ");
	gets(author_name);
	printf("Publisher: ");
	gets(publisher);
	printf(" Pub date: ");

	//判断日期是否正确
	//有点问题

	scanf("%d/%d/%d", &year, &mon, &day);

	while (!IsRightDate(year, mon, day))
	{
		printf("Incorrect date! Please reenter: ");
		scanf("%d/%d/%d", &year, &mon, &day);
	}

	printf("    Price: ");
	scanf("%lf", &price);

	//读取空格
	getchar();

	//赋值
	p = (struct book_node*)malloc(sz);
	p->book.book_num = book_num;
	p->book.book_name = book_name;
	p->book.author_name = author_name;
	p->book.publisher = publisher;
	p->book.day = day;
	p->book.mon = mon;
	p->book.year = year;
	p->book.price = price;
	p->next = NULL;

	return p;
}

int IsRightDate(int year, int mon, int day)
{
	if (year > 0)
	{
		if (mon > 0 && mon < 13)
		{
			if (day > 0 && day <= Mday(year, mon))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		else
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
}

int Mday(int year, int mon)
{
	int M = 0;
	if (year > 0)
	{
		switch (mon)
		{
		case 1: M = 31; break;
		case 2: M = 28 + IsLeapYear(year); break;
		case 3: M = 31; break;
		case 4: M = 30; break;
		case 5: M = 31; break;
		case 6: M = 30; break;
		case 7: M = 31; break;
		case 8: M = 31; break;
		case 9: M = 30; break;
		case 10: M = 31; break;
		case 11: M = 30; break;
		case 12: M = 31; break;
		}
	}
	return M;
}

int IsLeapYear(int year)
{
	return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
}

void Print_All_booknode(struct book_node* head)
{
	//如果头为空返回
	struct book_node* ptr;
	if (head == NULL)
	{
		return;
	}

	//循环打印
	printf("ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---\n");
	for (ptr = head ->next; ptr; ptr = ptr->next)
	{
		printf("%-13s ", ptr->book.book_num);
		printf("%-30s ", ptr->book.book_name);
		printf("%-20s ", ptr->book.author_name);
		printf("%-30s ", ptr->book.publisher);
		printf("%04d/%02d/%02d ", ptr->book.year, ptr->book.mon, ptr->book.day);
		printf("%8.2f ", ptr->book.price);
		printf("\n");
	}
}

void BubbleSortOfList(struct book_node* list)
{
	//临时变量
	infom tmp;
	struct book_node* prt = NULL;
	struct book_node* qrt = NULL;

	//冒泡排序 
	for (prt = list->next; prt; prt = prt->next)
	{
		for (qrt = list->next; qrt->next; qrt = qrt->next)
		{
			if (strcmp(qrt->book.book_num, qrt->next->book.book_num) > 0 )
			{
				tmp = qrt->book;
				qrt->book = qrt->next->book;
				qrt->next->book = tmp;
			}
		}
	}
}

void Print_node(struct book_node* node)
{
	struct book_node* ptr = NULL;
	ptr = node;
	printf("%-13s ", ptr->book.book_num);
	printf("%-30s ", ptr->book.book_name);
	printf("%-20s ", ptr->book.author_name);
	printf("%-30s ", ptr->book.publisher);
	printf("%04d/%02d/%02d ", ptr->book.year, ptr->book.mon, ptr->book.day);
	printf("%8.2f ", ptr->book.price);
	printf("\n");
}

void SearchNodePrintByName(struct book_node* list)
{
	//定义数组,储存输入字符串
	char temp[31] = { 0 };

	//L指针,便利链表
	struct book_node* L = list->next;

	//查看是否找到
	int flag = 0;

	printf("Title: ");
	gets(temp);

	int num = 1;
	//查找
	while (L)
	{
		if (strcmp(temp, L->book.book_name) == 0)
		{
			if (num)
			{
				printf("ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---\n");
				num = 0;
			}
			Print_node(L);
			flag = 1;
		}
		L = L->next;
	}

	//没找到
	if (flag == 0)
	{
		printf("Not found!\n");
	}
}

void SearchNodeDelByNum(struct book_node* list)
{
	//定义数组,储存字符串
	char temp[14] = { 0 };
	printf("ISBN: ");
	gets(temp);

	//指针寻找delete位置
	struct book_node* p = NULL;
	p = list;

	//看是否寻找到
	int flag = 0;

	while (p->next != NULL)
	{
		if (strcmp(temp, p->next->book.book_num) == 0)
		{
			printf("Remove(y/n)? ");

			//循环条件
			int ok = 1;

			//读取字符

			char ch = 0;
			scanf("%c%*c", &ch);

			while (ok)
			{
				if (ch == 'y' || ch == 'Y')
				{
					ok = 0;
					flag = 1;
					struct book_node* mid = NULL;
					mid = p->next;
					p->next = mid->next;
					free(mid);
					return;
				}
				else if (ch == 'n' || ch == 'N')
				{
					ok = 0;
					flag = 1;
					return;
				}
				else
				{
					printf("Incorrect answer!\n");
					printf("Remove(y/n)? ");
					scanf("%c%*c", &ch);
				}
			}
			return;
		}
		p = p->next;
	}

	//不存在,没找到
	if (flag == 0)
	{
		printf("Not found!\n");
	}
}

struct book_node* SearchNodeModifyByNum(struct book_node* list, struct book_node* L)
{
	char temp[14] = { 0 };
	printf("ISBN: ");
	gets(temp);

	struct book_node* p = NULL;
	p = list;

	//看是否寻找到
	int flag = 0;

	while (p->next)
	{
		if (strcmp(temp, p->next->book.book_num) == 0)
		{
			printf("Modify(y/n)? ");
			
			//循环条件
			int ok = 1;
			char ch = 0;
			scanf("%c%*c", &ch);

			while (ok)
			{
				if (ch == 'y' || ch == 'Y')
				{
					ok = 0;
					flag = 1;
					if (p->next->next != NULL) 
					{
						ModifyInfom(p);
					}
					else
					{
						struct book_node* newnode = NULL;
						struct book_node* mid = NULL;
						mid = p->next;
						newnode = Create_book_Doc();
						p->next = newnode;
						free(mid);
						L = p->next;
					}
				}
				else if (ch == 'n' || ch == 'N')
				{
					ok = 0;
					flag = 0;
				}
				else
				{
					printf("Incorrect answer!\n");
					printf("Modify(y/n)? ");
					scanf("%c%*c", &ch);
				}
			}
		}
		p = p->next;
	}

	//不存在,没找到
	if (flag == 0)
	{
		printf("Not found!\n");
	}
	return L;
}
void ModifyInfom(struct book_node* node)
{
	struct book_node* newnode = NULL;
	newnode = Create_book_Doc();
	newnode->next = node->next->next;
	node->next = newnode;
}

  

标签:node,struct,管理系统,int,next,book,printf,图书
From: https://www.cnblogs.com/Code-wangg/p/17057545.html

相关文章

  • NestJS 后台管理系统搭建、TypeOrm使用(一)
    前言技术千千万,学习永不断;虽然是咸鱼,也想努把力!!!这段时间一直很迷茫,做前端这行也有6年了,眼看马上奔三的人了,但依旧是个菜逼,整天代码写了不少,但总感觉缺少些什么,一直都没......
  • ASP.NET Core+Element+SQL Server开发校园图书管理系统(一)
    随着技术的进步,跨平台开发已经成为了标配,在此大背景下,ASP.NETCore也应运而生。本文主要基于ASP.NETCore+Element+SqlServer开发一个校园图书管理系统为例,简述基于MVC三......
  • C语言家庭日常消费记录管理系统
    C语言家庭日常消费记录管理系统题目:家庭日常消费记录管理系统一、功能需求说明(必须采用动态链表实现)1.消费记录存在文件fee.dat中格式如下:每一条记录包括一个消费......
  • C/C++学生成绩管理系统[2023-01-16]
    C/C++学生成绩管理系统[2023-01-16]《C\C++语言课程设计》指导书一、课程设计概要项目名称:学期评优方案设计适用学期:2022年秋季学期适用班级:07D229-07D22C班二、项目......
  • C语言学生宿舍管理系统[2023-01-16]
    C语言学生宿舍管理系统[2023-01-16]用C语言开发一个简单的学生宿舍管理系统。[数据结构]1、学生住宿数据文件。每名学生的住宿信息包括:宿舍号,床位数,姓名,学号电话,寝室长......
  • 【广州华锐互动】智慧楼宇管理系统解决方案公司
    据相关数据统计,人的一生中约有90%的时间是在楼宇当中度过的,因此,如何有效保证楼宇建筑设施的可持续发展,如何创造既舒适节能又健康智能的完美空间成为智能建筑行业的重要命题......
  • Python django 公寓管理系统
    Pythondjango公寓管理系统django公寓租房系统django酒店订购系统django公寓订购系统技术:Pythondjango数据库:MySQL前端:htmlcssjs涉及到的功能:登录、注册、......
  • Python django 会议室管理系统
    Pythondjango会议室管理系统django会议室申请系统django会议室系统技术:Pythondjango数据库:MySQL涉及功能:登录、注册、登出、管理员登录、管理用户信息等添加会......
  • Python django 图书馆管理系统
    Pythondjango图书馆管理系统技术:Python  django数据库:sqlite3(或MySQL)前段:html css  js 功能:注册,注销,改密码,添加图书,添加图书照片,查看图书,普通用户只能查看......
  • java核心技术之 ArrayList应用 【职员薪水管理系统】
    职员薪水管理系统需求如下:/***author:kevin*date:20110-7-15*function:useArrayListtobuildasystemofEmployeeSalaryMangement,*thesystemisusefulformana......