实验一 图书信息管理系统的设计与实现
实验一代码如下:
#include<iostream>
#include<cstdio>
using namespace std;
#define getpch(type) (type*)malloc(sizeof(type))
typedef struct {
char no[14]; //13位书号
char name[41]; //20位书名
double price; //价格
}Book;
//链表的定义:
typedef struct LNode {
Book data; //数据域就放假
struct LNode* next; //指针域
}*LinkList;
void inputBook(LinkList Head, LinkList& Rear) {
//录入图书
LinkList test;
char ch;
int n = 1;
while (true) {
test = getpch(LNode);
cout << "请输入第" << n << "本书的书号:";
cin >> test->data.no;
cout << "请输入第" << n << "本书的书名:";
cin >> test->data.name;
cout << "请输入第" << n << "本书的价格:";
cin >> test->data.price;
test->next = NULL;
Rear->next = test;
Rear = test; //尾插法
n++;
cout << "是否继续录入?(是请输入y,否请按任意键。)";
cin >> ch;
if (ch != 'y')break;
}
}
void printBook(LinkList Head) {
//显示所有图书的信息
LinkList p = Head->next;
cout << "=====图书列表=====" << endl;
while (p != NULL) {
//遍历链表,输出数据
printf("%s%c%s%c%.2f%c", p->data.no, ' ', p->data.name, ' ', p->data.price, '\n');
p = p->next;
}
cout << "0 0 0" << endl;
}
void insetBook(LinkList Head, LinkList Rear) {
//插入图书
LinkList test, p = Head;
char ch;
int n, tag = 0;
bool t = true;
while (t) {
cout << "请输入插入的位置:";
cin >> n;