刘彩月 2 years ago
commit 32d254f390

@ -0,0 +1,7 @@
{
"files.associations": {
"iostream": "cpp",
"ostream": "cpp",
"stdexcept": "cpp"
}
}

@ -4,6 +4,8 @@
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\mingw64\\bin\\g++.exe",
"label": "C/C++: g++.exe build active file",
"command": "C:\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
@ -22,6 +24,7 @@
"isDefault": true
},
"detail": "调试器生成的任务。"
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"

@ -1,170 +0,0 @@
#include <iostream>
using namespace std;
#include "sqlist.h" // 顺序表
// 图书信息
struct Book {
int id; // 编号
string title; // 标题
string author; // 作者
float price; // 价格
};
// 所有书的列表
SqList<Book> books;
int get_command(); // 读取命令
void DoAddBook(); // 添加图书
void DoFindBook(); // 查找图书
void DoDeleteBook(); // 删除图书
void DoPrintBook(); // 打印图书
int main()
{
bool finish = false;
InitList(books);
while (!finish) {
switch (get_command()) {
case 1: // Add book
DoAddBook();
break;
case 2: // Find book
DoFindBook();
break;
case 3: // Delete book
DoDeleteBook();
break;
case 4: // Print
DoPrintBook();
break;
case 0: // Exit
finish = true;
break;
default: // no command
cout << "Error command." << endl;
}
}
DestroyList(books);
return 0;
}
// 读取命令
int get_command()
{
int cmd;
cout << "Commands: (1) Add, (2) Find, (3) Delete, (4) Print, (0) Exit\n";
cout << "Enter your choice (0-4): ";
cin >> cmd;
return cmd;
}
// 输入一本书的信息
void read(Book& b)
{
cout << "ID : ";
cin >> b.id;
cin.ignore(1024, '\n'); // skip rest chars of the line
cout << "TITLE : ";
getline(cin, b.title);
cout << "AUTHOR: ";
getline(cin, b.author);
cout << "PRICE : ";
cin >> b.price;
}
// 打印一本书的信息
void print(const Book& b)
{
cout << "Book { id: " << b.id << ","
<< " title:\"" << b.title << "\","
<< " author: \"" << b.author << "\","
<< " price: " << b.price << " }"
<< endl;
}
// 根据 id 查找图书
// 若找到,返回元素的位序,找不到时返回 0
int find(int id)
{
for (int i = 1; i <= books.length; i++)
{
if (id == books.elem[i].id){
return i;
}
}
return 0; // not found
}
// 添加图书
void DoAddBook()
{
Book e;
read(e);
books.elem[books.length + 1] = e;
books.length++;
print(e);
cout << "Added" << endl;
}
// 查找图书
void DoFindBook()
{
int id;
cout << "Enter book ID: ";
cin >> id;
Book e;
if (find(id) == 0)
cout << "Not found" << endl;
else
{
e = books.elem[find(id)];
print(e);
cout << "Found" << endl;
}
}
// 删除图书
void DoDeleteBook()
{
int id;
cout << "Enter book ID: ";
cin >> id;
Book e;
int c = find(id);
if (find(id) == 0)
cout << "Not found" << endl;
else
{
e = books.elem[c];
print(e);
for (int i = c; i < books.length; i++)
{
books.elem[i] = books.elem[i + 1];
}
--books.length;
cout << "Deleted" << endl;
}
}
// 打印图书
void DoPrintBook()
{
int flag = 0;
for (int i = 0; i < books.length; i++)
{
Book e;
e = books.elem[i + 1];
print(e);
flag++;
}
cout << "Total: ";
cout << flag;
cout << " books" << endl;
}

233
data.h

@ -2,54 +2,221 @@
#define DATA_H_INCLUDED
#include <stdio.h>
#include "sqlist.h"
struct Book {
int id; // 编号
string title; // 标题
int number; // 数量
};
SqList <Book> books;
// 函数声明
void read_data(void); // 读取
void save_data(void); // 保存
void print_data(void); // 打印
void query_data(void); // 查询
void add_data(void); // 添加
void update_data(void); // 修改
void delete_data(void); // 删除
void sort_data(void); // 排序
void make_chart(void); // 图表
void read_data(void)
{
printf("读取\n");
bool bookempty(); // 书籍库判空
void input(Book& b); // 输入一本书的信息
void print(const Book& b);// 打印一本书的信息
int find(int id); // 根据 id 查找图书 || 若找到,返回元素的位序,找不到时返回 0
void DoAddBook(); // 添加图书
void DoFindBook(); // 查找图书
void DoDeleteBook(); // 删除图书
void DoPrintBook(); // 打印所有图书
void DoRepaidBook(); // 归还图书
void DoBoorowBook(); // 借用图书
void DoReviseBook(); // 修改图书
void DoSortBook(); // 排序图书
// 输入一本书的信息
void input(Book& b)
{
cout << "ID : ";
cin >> b.id;
cin.ignore(1024, '\n'); // skip rest chars of the line
cout << "TITLE : ";
getline(cin, b.title);
cout << "Number : ";
while (1){
cin >> b.number;
if (b.number>0) break;
cout << "Number ERROR" << endl;
cout << "Input again" << endl;
}
void save_data(void)
}
// 打印一本书的信息
void print(const Book& b)
{
cout << "Book " << endl << endl
<<"**************** id: " << b.id << " ****************" << endl
<< "**** title: 《 " << b.title << " 》****" << endl
<< "************** Number: " << b.number << " **************" << endl << endl;
}
// 根据 id 查找图书
// 若找到,返回元素的位序,找不到时返回 0
int find(int id)
{
for (int i = 1; i <= books.length; i++)
{
printf("保存\n");
if (id == books.elem[i].id){
return i;
}
void print_data(void)
{
printf("打印\n");
}
void query_data(void)
return 0; // not found
}
// 书籍库判空
bool bookempty()
{
int a=0;
for (int i=1;i<=books.length;i++)
{
printf("查询\n");
if (find(i)==0) a++;
}
void add_data(void)
if (a==books.length) return true;
else return false;
}
// 添加图书
void DoAddBook()
{
cout << endl << "Add Book"<< endl<<endl;
Book book;
input(book); //输入图书
books.elem[books.length + 1] = book;
books.length++;
print(book);
cout << "*******Added********" << endl;
}
// 查找图书
void DoFindBook()
{
cout << endl << "Find Book" << endl <<endl;
int id;
cout << "Enter book ID: ";
cin >> id;
Book book;
if (find(id) == 0)
cout << "Not found" << endl;
else
{
puts("添加");
book = books.elem[find(id)];
cout << "Found" << endl;
cout << "************" << endl;
print(book);
}
void update_data(void)
}
// 删除图书
void DoDeleteBook()
{
cout << endl << "Delete Book" << endl << endl;
int id;
cout << "Which book you wanna delelet?"<<endl;
cout << "Enter book ID: ";
cin >> id;
Book e;
if (find(id) == 0)
cout << "Not found" << endl;
else
{
puts("修改");
}
void delete_data(void)
e = books.elem[find(id)];
print(e);
for (int i = find(id); i < books.length; i++)
{
puts("删除");
books.elem[i] = books.elem[i + 1];
}
void sort_data(void)
{
puts("排序");
--books.length;
cout << "************************" << endl;
cout << "Deleted" << endl;
}
void make_chart(void)
}
// 打印所有图书
void DoPrintBook()
{
cout << endl << "Print All Books" << endl <<endl;
int flag = 0;
for (int i = 0; i < books.length; i++)
{
puts("图表");
Book e;
e = books.elem[i + 1];
print(e);
flag++;
}
cout << "Total: ";
cout << flag;
cout << " books" << endl;
}
// 归还图书
void DoRepaidBook()
{
cout << endl << "Repaid Book" << endl<<endl;
int id;
cout << "Which book you wanna repaid ? " << endl;
cin >> id;
cout << endl;
if (find(id)){
Book e;
e = books.elem[find(id)];
++books.elem[find(id)].number;
}else{
DoAddBook();
}
}
// 借用图书
void DoBoorowBook()
{
cout << endl << "Boorow Book" << endl <<endl;
int id;
cout << "Which book you wanna boorow ? " << endl;
cin >> id;
cout << endl;
if (find(id)){
if (books.elem[find(id)].number>0) {
Book e;
e = books.elem[find(id)];
cout<< "*********"<< endl << "OK" << endl << "*********"<<endl;
--books.elem[find(id)].number;
}else cout << "***************************"<< endl
<< "Book empty" << endl << "***************************" << endl;
}else cout<< "NOT FOUND THIS BOOK"<<endl;
}
// 修改图书
void DoReviseBook()
{
cout <<endl<< "Revise Book" <<endl <<endl;
int id;
printf( "Which book you wanna revise ?\n" );
cin >> id;
if ( find(id)!=0 ) {
printf ( "Original book number : %d\n", books.elem[id].number );
printf ( "Revised number :" );
int xiugai;
scanf ( "%d", &xiugai );
books.elem[id].number+=xiugai;
cout << "**********************" << endl;
printf ( "Revise success \n" );
}
else printf ( "No such book\n");
}
// 排序图书
void DoSortBook()
{
cout << endl << "Sort Books" << endl << endl;
int a=0;
if (bookempty()) cout << "Book data empty"<< endl;
}
#endif // DATA_H_INCLUDED

@ -1,21 +0,0 @@
#include <iostream>
#include "student.h"
using namespace std;
struct student{
long int id[10]; ///十位学号
char name[15]; ///姓名
long int phonenumber[11]; //手机号
struct date; //日期
};
struct date{
int year;
int month;
int day;
};
int main()
{
}

@ -1,6 +0,0 @@
///////////////////
///student.cpp
///////////////////

@ -1,7 +0,0 @@
杨腾泽
孙英皓
刘彩月
李聪颖
hello world
goodbye
qwertyuiop

@ -1,30 +1,22 @@
///程序启动
///1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加
///6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出
///请选择: 0
///确定要退出吗?(Y/N): no
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#include "data.h"
#include "sqlist.h"
enum {
CMD_QUIT, // 退出
CMD_READ, // 读取
CMD_SAVE, // 保存
CMD_PRINT, // 打印
CMD_QUERY, // 查询
CMD_INSERT, // 添加
CMD_UPDATE, // 修改
CMD_DELETE, // 删除
CMD_SORT, // 排序
CMD_CHART, // 图表
CMD_QUIT, // 退出程序
CMD_QUERY, // 查书(数量)
CMD_BOOROW, // 借用书籍
CMD_REPAID, // 归还书籍
CMD_PRINT, // 打印书籍
CMD_INSERT, // 添加书籍
CMD_DELETE, // 删除书籍
CMD_UPDATE, // 修改书籍
CMD_SORT, // 排序书籍
};
@ -32,69 +24,83 @@
void init(void); // 程序启动
void quit(void); // 程序退出
void display_menu(void); // 显示命令菜单
int make_choice(void); // 选择命令
int confirm(const char* msg); // 确认
// 主函数
int main(void)
{
init(); // 程序启动
InitList(books);
for(;;) {
display_menu(); //
int c = make_choice();
switch(c) {
case CMD_READ:
read_data();
break;
case CMD_SAVE:
save_data();
break;
case CMD_PRINT:
print_data();
break;
case CMD_QUERY:
query_data();
break;
case CMD_INSERT:
add_data();
break;
case CMD_UPDATE:
update_data();
break;
case CMD_DELETE:
delete_data();
break;
case CMD_SORT:
sort_data();
break;
case CMD_CHART:
make_chart();
break;
case CMD_QUIT:
if (confirm("确定要退出吗?")) quit(); // 仅在确认后退出
break;
case CMD_REPAID:// 还书
{DoRepaidBook();
break;}
case CMD_BOOROW:// 借书
{DoBoorowBook();
break;}
case CMD_PRINT:// 打印所有书籍
{DoPrintBook();
break;}
case CMD_QUERY:// 查找书籍
{DoFindBook();
break;}
case CMD_INSERT:// 添加书籍
{DoAddBook();
break;}
case CMD_DELETE:// 删除书籍
{DoDeleteBook();
break;}
case CMD_UPDATE:// 修改书籍
{DoReviseBook();
break;}
case CMD_SORT: // 排序书籍
{DoSortBook();
break;}
case CMD_QUIT:// 退出程序
{if (confirm("确定要退出吗?")) quit(); // 仅在确认后退出
break;}
default:
puts("命令错误,请重新选择");
break;}
}
quit(); // 程序退出
DestroyList(books);
return 0;
}
// 函数定义
void init(void)
{
puts("程序启动");
puts("*******图书管理系统启动*******");
}
void quit(void)
{
puts("程序退出");
puts("系统退出");
exit(EXIT_SUCCESS);
}
void display_menu(void)
{
printf("\n%d 读取 | %d 保存 | %d 打印 | %d 查询 | %d 添加\n%d 修改 | %d 删除 | %d 排序 | %d 图表 | %d 退出\n\n",
CMD_READ,CMD_SAVE,CMD_PRINT,CMD_QUERY,CMD_INSERT,CMD_UPDATE,CMD_DELETE,CMD_SORT,CMD_CHART,CMD_QUIT);
cout << "————————————————————————————————————————————————————————————————"<<endl;
printf("| %d 查书 | %d 借书 | %d 还书 | %d 打印 | %d 添加 |\n| %d 删除 | %d 修改 | %d 排序 | %d 退出 |\n",
CMD_QUERY,CMD_BOOROW,CMD_REPAID,CMD_PRINT,CMD_INSERT,CMD_DELETE,CMD_UPDATE,CMD_SORT,CMD_QUIT);
cout << "————————————————————————————————————————————————————————————————"<<endl;
}
int make_choice(void)
{
@ -115,3 +121,6 @@
return c == 'y' || c == 'Y'; // 返回确认结果
}

@ -1,2 +0,0 @@
AAAA
AAAA
Loading…
Cancel
Save