archieve-projects/书店-图书-CPP/期末大作业.cpp

151 lines
4.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <cstring>
#include <fstream>
#include "Books.h"
using namespace std;
//全局变量
string ID_Value; //存储新建账户名
string ID[5]; //存储ID列表
int ID_flag; //存储ID操作序号
fstream file; //文件对象
void launch(); //声明RUNTIME函数
void ID_OUT()
{
file.open("ID.txt", ios::out);
if (!file)
{
cerr << "未检测到账户列表文件ID.txt保存失败。" << endl;
exit(1);
}
for (int i = 0; i < 5; i++)
file << ID[i] << endl;
file.close();
}
void ID_IN()
{
file.open("ID.txt", ios::in);
if (!file)
{
cerr << "未检测到预置账户列表文件ID.txt请查看源代码末端的注释现已使用默认测试账户登录。" << endl;
ID_Value = "超级管理员";
launch();
}
for (int i = 0; i < 5; i++)
file >> ID[i];
file.close();
}
void ID_Switch()
{
ID_IN();
for (int i = 0; i < 5; i++)
cout << i + 1 << "\t" << ID[i] << endl;
cout << "请选择要登录的账户:"; cin >> ID_flag;
if (ID_flag == 5 && ID[ID_flag-1] == "选此项以新建账户")
{
string tmp;
cout << "请输入新账户的ID"; cin >> tmp;
ID[4] = ID_Value = tmp;
cout << "新建账户成功并已写入账户列表!您现在拥有所有权限。" << endl;
ID_OUT();
}
else if (ID_flag < 1 || ID_flag>5)
{
cerr << "该账户不存在!程序将退出。" << endl;
abort();
}
else ID_Value = ID[ID_flag - 1];
cout << "-----------------------------------------------" << endl;
}
void fileOut()
{
file.open("书籍.txt", ios::out);
file<<"ISBN\t\t" << setw(25) << "书名" << setw(20) << "作者" << setw(15) << "价格" << setw(15) << "库存" << endl;
for (int i = 0; i < Bcount; i++) file << Books[i];
file.close();
file.open("期刊.txt", ios::out);
cout.setf(ios_base::left);
file << "ISBN\t\t" << setw(25) << "期刊名" << setw(20) << "出版社" << setw(20) << "价格" << setw(15) << "库存" << endl;
for (int i = 0; i < Jcount; i++)file << Journals[i];
cout << "已成功输出为'书籍.txt'与'期刊.txt'" << endl;
file.close();
}
void welcome()
{
cout << "==============================="
<< endl << setw(30) << "欢迎使用小型书店进销存管理系统"
<< endl << "==============================="
<< endl << "该程序仅用于江西财经大学张老师《C++程序设计语言》课程之期末综合性实验报告,作者:刘燕、李溦、钟琳"
<< endl << "-----------------------------------------------"
<< endl << "预置账户列表:" << endl;
ID_Switch();
launch();
}
void launch()
{
Admin admin(ID_Value);
int select = 1;
while (select)
{
cout << setw(20) << "————————————————" << endl
<< "当前用户:" << admin.getID() << endl
<< "1.查看当前库存" << endl
<< "2.增加书刊信息" << endl
<< "3.修改书刊信息" << endl
<< "4.删除书刊信息" << endl
<< "5.增加书刊库存" << endl
<< "6.书刊销售系统" << endl
<< "7.当前财务统计" << endl
<< "8.更改管理员ID" << endl
<< "9.切换登录账户" << endl
<< "10.将库存信息输出至文件" << endl
<< "0.退出书店系统" << endl
<< setw(20) << "————————————————" << endl;
cout << "请输入操作序号:";
cin >> select;
if (select < 0 || select >10)
{
cerr << "非法值,请重新输入。" << endl;
continue;
}
else
{
switch (select)
{
case 1: admin.printAll(); continue;
case 2: admin.AddBook(); continue;
case 3: admin.modify();continue;
case 4: admin.DelBook(); continue;
case 5: admin.inStock(); continue;
case 6: admin.outStock(); continue;
case 7: admin.statics(); continue;
case 8:
{
string id;
cout << "输入目标ID";
cin >> id;
admin.changeID(id);
ID[ID_flag - 1] = id;
cout << "更改成功当前ID为" << id << endl;
ID_OUT();
continue;
}
case 9: system("cls"); welcome(); break;
case 10: fileOut(); continue;
case 0: break;
}
}
}
}
int main()
{
welcome();
return 0;
}