//第一段,测试book.h
/*
#include<iostream>
#include"book.h"
using namespace std;
int main()
{
book book1 = { "三国演义", "00001001", "罗贯中", "2012-08-06", 24.5, 30, true };
book1.show();
book1.set_author("小明");
book1.set_code("00010002");
book1.set_lend_time(10);
book1.set_name("笑话");
book1.set_price(22);
book1.set_time("2020-06-25");
book1.lend_or_return(false);
cout << book1.get_author() << endl;
cout << book1.get_available() << endl;
cout << book1.get_code() << endl;
cout << book1.get_lendtime() << endl;
cout << book1.get_name() << endl;
cout << book1.get_price() << endl;
cout << book1.get_time() << endl;
system("pause");
return 0;
}
*/
//第二段:测试user.h
/*
#include<iostream>
#include"user.h"
#include"book.h"
#include"Librarian.h"
using namespace std;
int book::book_num = 1;
int User::User_num = 1;
int main()
{
User u1 = { "小红", 215, "liutielong1111", Reader };
u1.show();
cout << u1.get_name()<<endl;
cout << u1.get_mode() << endl;
u1.change_mode(Librarian);
u1.change_name("刘一");
u1.change_pass();
u1.show();
system("pause");
return 0;
}
*/
//第三段:测试Librarian_User和从txt文件中读取数据到book数组
/*
#include<iostream>
#include"user.h"
#include"book.h"
#include"Librarian.h"
#include<Windows.h>
#include<sstream>
#include<vector>
using namespace std;
//用此文件初始化所有书籍
void initial_books(book* B)
{
//SetConsoleOutputCP(65001);
ifstream in("books.txt");
string line;
string line_info, input_result;
float b_p;
int b_le;
bool b_a;
if (in) // 有该文件
{
while (getline(in, line)) // line中不包括每行的换行符
{
stringstream input(line);
//cout << "line_info: " << line_info << endl;
input >> input_result;
B[book::book_num].set_name(input_result);
input >> input_result;
B[book::book_num].set_code(input_result);
input >> input_result;
B[book::book_num].set_author(input_result);
input >> input_result;
B[book::book_num].set_time(input_result);
input >> b_p;
B[book::book_num].set_price(b_p);
input >> b_le;
B[book::book_num].set_lend_time(b_le);
input >> b_a;
B[book::book_num].lend_or_return(b_a);
book::book_num++;
}
}
else // 没有该文件
{
cout << "no such file" << endl;
}
}
int book::book_num = 0;
int User::User_num = 1;
int main()
{
book B[100];
initial_books(B);
Librarian_user u1;
int mode;
SetConsoleOutputCP(936);
while (true)
{
cout << "请输入要操作的模式:" << endl;
cout << "0为添加图书;" << endl;
cout << "1为删除图书;" << endl;
cout << "2为修改图书;" << endl;
cout << "3为查询图书;" << endl;
cout << "4为统计所有图书。" << endl;
cin >> mode;
switch (mode)
{
case 0:
u1.Add_book(B);
break;
case 1:
u1.Delete_book(B);
break;
case 2:
u1.Change_book(B);
break;
case 3:
u1.Find_book(B);
break;
case 4:
u1.Addup_book(B);
break;
default:
cout << "您输入的命令不对!" << endl;
break;
}
}
system("pause");
return 0;
}
*/
//第四段,测试Reader_User
/*
//第四段,测试Reader类的功能
#include<iostream>
#include"user.h"
#include"book.h"
#include"Librarian.h"
#include<Windows.h>
#include<sstream>
#include<vector>
#include"Reader.h"
using namespace std;
//用此文件初始化所有书籍
void initial_books(book* B)
{
//SetConsoleOutputCP(65001);
ifstream in("books.txt");
string line;
string line_info, input_result;
float b_p;
int b_le;
bool b_a;
if (in) // 有该文件
{
while (getline(in, line)) // line中不包括每行的换行符
{
stringstream input(line);
//cout << "line_info: " << line_info << endl;
input >> input_result;
B[book::book_num].set_name(input_result);
input >> input_result;
B[book::book_num].set_code(input_result);
input >> input_result;
B[book::book_num].set_author(input_result);
input >> input_result;
B[book::book_num].set_time(input_result);
input >> b_p;
B[book::book_num].set_price(b_p);
input >> b_le;
B[book::book_num].set_lend_time(b_le);
input >> b_a;
B[book::book_num].lend_or_return(b_a);
book::book_num++;
}
}
else // 没有该文件
{
cout << "no such file" << endl;
}
}
int book::book_num = 0;
int User::User_num = 1;
int Reader_user::Reader_num = 1;
int main()
{
book B[100];
initial_books(B);
SetConsoleOutputCP(936);
Reader_user r1;
int mode;
while (true)
{
cout << "请输入要操作的模式:" << endl;
cout << "0为借阅图书;" << endl;
cout << "1为归还图书;" << endl;
cout << "2为查询已经借了的图书;" << endl;
cout << "3为查询所有图书;" << endl;
cin >> mode;
switch (mode)
{
case 0:
r1.lend_book(B);
break;
case 1:
r1.return_book(B);
break;
case 2:
r1.lend_show();
break;
case 3:
r1.book_show(B);
break;
default:
cout << "您输入的命令不对,请重新输入!" << endl;
break;
}
}
system("pause");
return 0;
}
*/
//第五段
//下面测试用户注册、登陆,登陆后应该能进行相应的操作
//我们需要提供一个程序入口界面
//还有很多其他的界面,为:注册界面,登陆界面,图书馆理员操作界面,读者操作界面,
//主要就是这5个界面之间相互调用
/*
#include<iostream>
#include"user.h"
#include"book.h"
#include"Librarian.h"
#include<Windows.h>
#include<sstream>
#include<vector>
#include"Reader.h"
using namespace std;
//定义一些全局变量
User us[100];
Reader_user ru[100]{ Reader_user("小刚", 103, "103", us), Reader_user("小强", 104, "104", us) };
Librarian_user lu[100]{ Librarian_user("小明", 101, "101", us), Librarian_user("小红", 102,"102", us) };
Log mylog; //用来进行登陆的
int book::book_num = 0;
int User::User_num = 0;
int Librarian_user::Librarian_num = 2;
int Reader_user::Reader_num = 2;
//从txt文件中读取图书信息并初始化到B中
void initial_books(book* B)
{
//SetConsoleOutputCP(65001);
ifstream in("books.txt");
string line;
string line_info, input_result;
float b_p;
int b_le;
bool b_a;
if (in) // 有该文件
{
while (getline(in, line)) // line中不包括每行的换行符
{
stringstream input(line);
input >> input_result;
B[book::book_num].set_name(input_result);
input >> input_result;
B[book::book_num].set_code(input_result);
input >> input_result;
B[book::book_num].set_author(input_result);
input >> input_result;
B[book::book_num].set_time(input_result);
input >> b_p;
B[book::book_num].set_price(b_p);
input >> b_le;
B[book::book_num].set_lend_time(b_le);
input >> b_a;
B[book::book_num].lend_or_return(b_a);
book::book_num++;
}
}
else // 没有该文件
{
cout << "no such file" << endl;
}
}
//将图书信息重新写入txt文件中
void summary_books(book* B)
{
ofstream out("books.txt");
out.clear();
for (int i = 0; i < book::book_num; i++)
{
out << B[i].get_name() << " "
<< B[i].get_code() << " "
<< B[i].get_author() << " "
<< B[i].get_time() << " "
<< B[i].get_price() << " "
<< B[i].get_lendtime() << " "
<< 1 << endl; //下次运行程序时,都可借
}
out.close();
}
//注册的界面
void zhuce(book* B)
{
cout << "-----------------------------------------------------------------------" << endl;
cout << "进入读者注册页面" << endl;
ru[Reader_user::Reader_num].zc(us, mylog, ru);
return;
}
//登陆的界面
void denglu(book* B)
{
cout << "-----------------------------------------------------------------------" << endl;
cout << "进入登陆页面" << endl;
mylog.login(us);
if (mylog.Log_success == 1)
{
if (mylog.us.get_mode() == Reader) //如果是读者登陆
{
int mode;
while (true)
{
cout << "请输入要操作的模式:" << endl;
cout << "0为借阅图书;" << endl;
cout << "1为归还图书;" << endl;
cout << "2为查询已经借了的图书;" << endl;
cout << "3为查询所有图书;" << endl;
cout << "4为退出登陆。" << endl;
cin >> mode;
switch (mode)
{
case 0:
ru[mylog.number].lend_book(B);
break;
case 1:
ru[mylog.number].return_book(B);
break;
case 2:
ru[mylog.number].lend_show();
break;
case 3:
ru[mylog.number].book_show(B);
break;
case 4:
return;
break;
default:
cout << "您输入的命令不对,请重新输入!" << endl;
break;
}
}
}
else if (mylog.us.get_mode() == Librarian)
{
int mode;
int doit = 1;
while (doit)
{
cout << "请输入要操作的模式:" << endl;
cout << "0为添加图书;" << endl;
cout << "1为删除图书;" << endl;
cout << "2为修改图书;" << endl;
cout << "3为查询图书;" << endl;
cout << "4为统计所有图书。" << endl;
cout << "5为退出登陆。" << endl;
cin >> mode;
switch (mode)
{
case 0:
lu[mylog.number].Add_book(B);
break;
case 1:
lu[mylog.number].Delete_book(B);
break;
case 2:
lu[mylog.number].Change_book(B);
break;
case 3:
lu[mylog.number].Find_book(B);
break;
case 4:
lu[mylog.number].Addup_book(B);
break;
case 5:
doit = 0;
break;
default:
cout << "您输入的命令不对!" << endl;
break;
}
}
}
}
}
//入口界面
void rukou(book* B)
{
cout << User::User_num << endl;
cout << "-------------------------------------------------------------------" << endl;
cout << "*****************欢迎进入图书管理系统!****************************" << endl;
cout << "您当前可以进行的操作为:" << endl;
cout << "注册(输入0)" << endl;
cout << "登陆(输入1)" << endl;
cout << "退出(输入2)" << endl;
cout << "-------------------------------------------------------------------" << endl;
cout << endl;
int mode;
cin >> mode;
switch (mode)
{
case 0:
zhuce(B); //注册后,可能会进行相应人员的操作
rukou(B); //不过应该还是能退回到入口界面
break;
case 1:
denglu(B); //登陆后,可能会进行相应人员的操作
rukou(B); //不过应该还是能退回到入口界面
break;
case 2:
return;
break; //这里就直接退出程序了
default:
cout << "您输入的信息有误,请重新输入!" << endl;
rukou(B);
break;
}
}
int main()
{
book B[100];
initial_books(B);
SetConsoleOutputCP(936);
rukou(B);
//最后将所有图书信息写入books.txt,以便下次打开程序时直接录入
summary_books(B);
//system("pause");
return 0;
}
*/
C++大作业测试文件
最新推荐文章于 2024-04-08 13:46:35 发布