📄 bookstore.cpp
字号:
//*****************************************************************************
//* 软件工程开发设计 *
//* ——“小型图书销售系统” *
//* *
//* 工作组: 翟乃钧(030310229)、陈奎(030310226)、蔡晟(030310211) *
//* 完成时间: 2005年11月24日 *
//*****************************************************************************
#include<stdlib.h>
#include<iostream.h>
#include<string.h>
#include<ctype.h>
#include<iomanip.h>
#include<fstream.h>
#include"tables.h"
//*****************************************************************************
//* 主函数 *
//*****************************************************************************
void main(void)
{
Administrator *limits1,*limits2,*q;
int choice,a,i,times=1;
int authority=0; //权限标示符
char b[40],select;
float t;
float percent=1; //折扣率
fstream dataFile;
dataFile.open("Library.dat",ios::in);
if(!dataFile)
{
cout<<endl<<" 图书数据文件出现错误,程序中止!"<<endl;
cin.get();
return;
}
cout<<endl<<" 程序启动成功,正在读取资料..."<<endl;
for(i=1;!dataFile.eof();i++,max++)
{
dataFile>>a;
Book[i].setNum(a);
dataFile>>b;
Book[i].setTitle(b);
dataFile>>a;
Book[i].setKind(a);
dataFile>>b;
Book[i].setAuthor(b);
dataFile>>b;
Book[i].setPub(b);
dataFile>>a;
Book[i].setTot(a);
dataFile>>a;
Book[i].setQty(a);
dataFile>>t;
Book[i].setCost(t);
} //读取文件资料至类变量
dataFile.close();
loope1:
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<" 欢迎使用本系统,请选择您的登陆身份:"<<endl;
cout<<endl<<" 1.管理员 2.顾客"<<endl;
loope2:
cin>>choice;
cin.ignore();
while(choice!=1 && choice!=2)
{
cout<<" 请在数字1和2中选择:"<<endl;
cin>>choice;
cin.ignore();
}
if(choice==1)
{
dataFile.open("Advanced.dat",ios::in);
if(!dataFile)
{
cout<<endl<<" 高级管理员文件出现错误,程序中止!"<<endl;
cin.get();
return;
}
limits1=new Administrator;
while(!dataFile.eof())
{
q=new Administrator;
dataFile>>q->name;
dataFile>>q->password;
q->next=limits1->next;
limits1->next=q;
} //读取高级管理员资料至类变量
dataFile.close();
dataFile.open("Common.dat",ios::in);
if(!dataFile)
{
cout<<endl<<" 普通管理员文件出现错误,程序中止!"<<endl;
cin.get();
return;
}
limits2=new Administrator;
while(!dataFile.eof())
{
q=new Administrator;
dataFile>>q->name;
dataFile>>q->password;
q->next=limits2->next;
limits2->next=q;
} //读取普通管理员资料至类变量
dataFile.close();
cout<<" 您将以管理员身份登陆,请输入您的姓名:";
cin>>b;
cout<<endl;
for(q=limits1->next;q;q=q->next)
if(strcmp(b,q->name)==0)
{
cout<<" 请输入六位密码:";
cin>>b;
cout<<endl;
while(strcmp(q->password,b)!=0 && times<3)
{
while(strlen(b)!=6)
{
cout<<" 密码为六位,请重新输入:";
cin>>b;
cout<<endl;
}
if(strcmp(q->password,b)!=0)
{
cout<<" 你的密码不正确,请重新输入:";
cin>>b;
times++;
cout<<endl;
}
}
if(strcmp(q->password,b)!=0 && times==3)
{
cout<<" 您已连续三次输错密码,请重新选择登陆:(1.管理员 2.顾客)"<<endl;
times=1;
goto loope2;
}
authority=1;
cout<<" 欢迎光临,"<<q->name<<",您是高级管理员!";
cin.ignore();
break;
}
if(!authority)
for(q=limits2->next;q;q=q->next)
if(strcmp(b,q->name)==0)
{
cout<<" 请输入六位密码:";
cin>>b;
cout<<endl;
while(strcmp(q->password,b)!=0 && times<3)
{
while(strlen(b)!=6)
{
cout<<" 密码为六位,请重新输入:";
cin>>b;
cout<<endl;
}
if(strcmp(q->password,b)!=0)
{
cout<<" 你的密码不正确,请重新输入:";
cin>>b;
times++;
cout<<endl;
}
}
if(strcmp(q->password,b)!=0 && times==3)
{
cout<<" 您已连续三次输错密码,请重新选择登陆:(1.管理员 2.顾客)"<<endl;
times=1;
goto loope2;
}
authority=2;
cout<<" 你好,"<<q->name<<"管理员!";
cin.ignore();
break;
}
if(!authority)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 列表中没有您的信息,请重新选择登陆:1.管理员 2.顾客"<<endl;
goto loope2;
}
}
else
{
cout<<" 顾客朋友您好,欢迎使用本系统!";
authority=3;
}
cout<<endl<<endl<<" 请按回车键开始操作。"<<endl;
cin.get();
while(1)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl;
if(authority<3)
{
cout<<" 图书管理系统 "<<endl<<endl;
cout<<" 1. 采编入库 "<<endl;
cout<<" 2. 清除库存 "<<endl;
cout<<" 3. 信息查询 "<<endl;
cout<<" 4. 设置折扣";
if(authority==2) cout<<"(不可操作)";
cout<<endl;
cout<<" 5. 统计报表";
if(authority==2) cout<<"(不可操作)";
cout<<endl;
cout<<" 6. 管理员名单";
if(authority==2) cout<<"(不可操作)";
cout<<endl;
cout<<" 7. 修改登陆密码 "<<endl;
cout<<" 8. 返回登陆界面 "<<endl;
cout<<" 9. 关闭系统 "<<endl<<endl;
cout<<" 请输入您的选择: "<<endl<<endl;
do
{
cout<<" 请在数字1-9的范围内输入:";
cin>>choice;
cin.ignore();
cout<<endl;
}while(choice<1 || choice>9);
switch(choice)
{
case 1: Add(); break;
case 2: Delete(); break;
case 3: Infor(authority,percent); break;
case 4:
if(authority==2)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 很抱歉,您不是高级管理员,没有设置折扣的权限。"<<endl;
cout<<endl<<" 请按回车键返回";
cin.get();
}
else
percent=Price(percent); break;
case 5:
if(authority==2)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 很抱歉,您不是高级管理员,没有察看报表的权限。"<<endl;
cout<<endl<<" 请按回车键返回";
cin.get();
}
else
Tables(); break;
case 6:
if(authority==2)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 很抱歉,您不是高级管理员,没有察看名单的权限。"<<endl;
cout<<endl<<" 请按回车键返回";
cin.get();
}
else Admin(); break;
case 7: Password(q->name,authority); break;
case 8:
system("cls");
authority=0;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 管理员操作已完成。";
cin.get();
goto loope1;
case 9:
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
do
{
cout<<" 确认关闭系统吗?(Y/N)"<<endl;
cin>>select;
select=toupper(select);
cin.ignore();
}while(select!='Y' && select!='N');
if(select=='Y')
{
cout<<" 系统已关闭,请按回车键结束……";
cin.get();
exit(0);
}
}
}
else
{
cout<<" 图书销售系统 "<<endl<<endl;
cout<<" 1. 信息查询 "<<endl<<endl;
cout<<" 2. 选购图书 "<<endl<<endl;
cout<<" 3. 管理规定 "<<endl<<endl;
cout<<" 4. 退出系统 "<<endl<<endl;
cout<<" 请输入您的选择: "<<endl<<endl;
do
{
cout<<" 请在数字1-4的范围内输入:";
cin>>choice;
cin.ignore();
cout<<endl;
}while(choice<1 || choice>4);
switch(choice)
{
case 1: Infor(authority,percent); break;
case 2: Sell(percent); break;
case 3: Rules(); break;
case 4:
system("cls");
authority=0;
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" 谢谢您的操作及对本书店的支持,欢迎下次再来!";
cin.get();
goto loope1;
}
}
dataFile.open("Library.dat",ios::out);
if(!dataFile)
{
cout<<" 文件打开出现错误,程序中止!"<<endl;
return;
}
for(i=1;i<max;i++)
{
dataFile<<Book[i].getNum()<<endl;
dataFile<<Book[i].getTitle()<<endl;
dataFile<<Book[i].getKind()<<endl;
dataFile<<Book[i].getAuthor()<<endl;
dataFile<<Book[i].getPub()<<endl;
dataFile<<Book[i].getTot()<<endl;
dataFile<<Book[i].getQty()<<endl;
dataFile<<Book[i].getCost();
if(i!=max-1)
dataFile<<endl; //最后一个数据存入文件后不再换行
} //将数据写入文件
cout<<endl<<" 数据资料存储完毕。"<<endl;
dataFile.close();
cout<<endl<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -