Compare commits

...

35 Commits

Author SHA1 Message Date
孙英皓 811b2e2e24 Merge branch 'master' into 孙英皓
2 years ago
yangtengze 8c6dac2eb0 a
2 years ago
yangtengze 1788b2c28e a
2 years ago
刘彩月 32d254f390 Merge branch 'master' of https://bdgit.educoder.net/pkcs2aq9m/text1
2 years ago
刘彩月 16aea1a7c5 1
2 years ago
yangtengze f65abe7405 Merge branch '杨腾泽'
2 years ago
yangtengze 70d3bb5147 change 2
2 years ago
yangtengze 7fa09e96eb change 1
2 years ago
yangtengze 336c5361b7 ytz
2 years ago
yangtengze affd19d0a8 环境
2 years ago
pkcs2aq9m 8f57d59dbd ADD file via upload
2 years ago
pkcs2aq9m 5b33e7ca29 ADD file via upload
2 years ago
pkcs2aq9m e5af14f617 ADD file via upload
2 years ago
pkcs2aq9m 2222568065 Delete 'title.cpp'
2 years ago
pkcs2aq9m e25a10b353 Delete 'student.h'
2 years ago
pkcs2aq9m 2b479bc1af Delete 'student.cpp'
2 years ago
pkcs2aq9m 35d8fad89b Delete 'sqlist.h'
2 years ago
pkcs2aq9m 98291f4a11 Delete 'data.h'
2 years ago
pkcs2aq9m 452d8bece6 Delete 'book.cpp'
2 years ago
杨腾泽 50d9401d4c Merge branch '杨腾泽'
2 years ago
杨腾泽 2fcae1b27a 1
2 years ago
杨腾泽 d291aa2d44 teammates
2 years ago
李聪颖 30cec3be5d Me
2 years ago
李聪颖 a4a11127ea 2
2 years ago
李聪颖 849d74240d Me
2 years ago
p253vfkpe 40555f68eb Update xiaoming.md
2 years ago
刘彩月 f56e3e9a02 Merge branch 'b1'
2 years ago
刘彩月 7111b608c3 teammates
2 years ago
李聪颖 5c20a00822 Merge branch '李聪颖'
2 years ago
刘彩月 a879cff355 Merge branch 'b1'
2 years ago
李聪颖 cfe3cd3845 1
2 years ago
李聪颖 d6b7d47924 okk
2 years ago
刘彩月 a09b5b7aae teammates
2 years ago
李聪颖 03d161052f okok
2 years ago
liucaiyue 862c5ad321 teammates
2 years ago

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

@ -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;
}

237
data.h

@ -2,54 +2,221 @@
#define DATA_H_INCLUDED #define DATA_H_INCLUDED
#include <stdio.h> #include <stdio.h>
#include "sqlist.h"
struct Book {
int id; // 编号
string title; // 标题
int number; // 数量
};
SqList <Book> books;
// 函数声明 // 函数声明
void read_data(void); // 读取 bool bookempty(); // 书籍库判空
void save_data(void); // 保存 void input(Book& b); // 输入一本书的信息
void print_data(void); // 打印 void print(const Book& b);// 打印一本书的信息
void query_data(void); // 查询 int find(int id); // 根据 id 查找图书 || 若找到,返回元素的位序,找不到时返回 0
void add_data(void); // 添加
void update_data(void); // 修改 void DoAddBook(); // 添加图书
void delete_data(void); // 删除 void DoFindBook(); // 查找图书
void sort_data(void); // 排序 void DoDeleteBook(); // 删除图书
void make_chart(void); // 图表 void DoPrintBook(); // 打印所有图书
void DoRepaidBook(); // 归还图书
void DoBoorowBook(); // 借用图书
void read_data(void) void DoReviseBook(); // 修改图书
{ void DoSortBook(); // 排序图书
printf("读取\n");
}
void save_data(void) // 输入一本书的信息
{ void input(Book& b)
printf("保存\n"); {
} cout << "ID : ";
void print_data(void) cin >> b.id;
{ cin.ignore(1024, '\n'); // skip rest chars of the line
printf("打印\n"); 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 query_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 add_data(void) return 0; // not found
}
// 书籍库判空
bool bookempty()
{
int a=0;
for (int i=1;i<=books.length;i++)
{ {
puts("添加"); if (find(i)==0) a++;
} }
void update_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 delete_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("删除"); e = books.elem[find(id)];
print(e);
for (int i = find(id); i < books.length; i++)
{
books.elem[i] = books.elem[i + 1];
}
--books.length;
cout << "************************" << endl;
cout << "Deleted" << endl;
} }
void sort_data(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++;
} }
void make_chart(void) cout << "Total: ";
{ cout << flag;
puts("图表"); 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 #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,4 +0,0 @@
杨腾泽
孙英皓
刘彩月
李聪颖

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

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