📄 main.cpp
字号:
#include<cstdlib>
#include"manager.H"
using namespace std;
void inportrecord(manager_net &mg){ //建立起所需链表并导出到文件
mg.input();
fstream outfile("myfile.txt",std::ios::out);
outfile<<mg;
outfile.close();
}
int main(){
manager_net sxy;
handle pjh;
fstream infile("myfile.txt",std::ios::in);
int p=0;
string pe;
infile>>pe;
while(!infile.eof()){
p++;
break;
}
infile.close();
delete &pe;
if(!p){
cout<<"系统检测到文件目录为空,请先建立好系统并将其导入文件..."<<endl;
inportrecord(sxy);
cout<<"建立完毕,谢谢!"<<endl;
}
else {
cout<<"1-直接从文件中载入内容到内存 2-清空源文件信息重新建立系统 请选择!"<<endl;
char pj;
cin>>pj;
if(pj=='1') sxy.loadrecord();
else if(pj=='2'){
inportrecord(sxy);
cout<<"建立完毕,谢谢!"<<endl;
}
else {
cout<<"选择错,系统默认选择1操作"<<endl;
sxy.loadrecord();
}
}
cout<<"请输入您要模拟的总时长,2N小时"<<endl;
int j;
cin>>j;
srand(time(0));
for(int i=0;i<j/2;i++){
int jj=(int)((sxy.coutcus()*2)*rand()/(RAND_MAX+1.0));//设想平均每个人在两小时内,打电话请求数为2;此‘2’值可以随意设定
int jk=sxy.coutcus()/2;//在某时刻最多只能有全体顾客数的一半在打电话
srand(time(0));
for(int m=0;m<7200;m++){
if(7199*rand()/(RAND_MAX+1.0)<jj){
lable: int jjj=(int)(sxy.coutcus()*rand()/(RAND_MAX+1.0));
customer *p=sxy.chazhao(jjj);
if((*p).out_light()) goto lable;
else{
cout<<"尊敬的 "<<(*p).out_name()<<"用户,您好!请选择您要执行的操作..."<<endl;
bool nnn=true;
while(nnn){
cout<<"1-打电话 2-发短信 3-查询&其它操作 4-退出 请选择..."<<endl;
char k;
cin>>k;
if(k=='1'){
char kk=(*p).telephone();
if(jk<=0)cout<<"网络繁忙,请稍后再试..."<<endl;
else{
customer *pp=sxy.scour_3(*p);
if(pp){
bool l=(*pp).tele_decide(p);
if(l){
cout<<"对方已接听..."<<endl;
(*p).set_tel_type(kk);
(*p).set_tel();
cout<<"通话开始!"<<endl;
pjh.pushin(p);
pjh.pushin(pp);
nnn=false;
jk--;
}
else cout<<"对方拒接!"<<endl;
}
else ;
}
}
else if(k=='2'){
bool md=true;
while(md){
string n=(*p).send_message();
if(jk<=0)cout<<"网络繁忙,发送失败!"<<endl;
else{
if(n!="null"){
sxy.scour_4(*p,n);
}
}
cout<<"继续? y/n?"<<endl;
char me;
cin>>me;
if(me=='y');
else if(me=='n')md=false;
else cout<<"选择错,程序默认选择继续 !"<<endl;
}
}
else if(k=='3'){
sxy.examine(p);
}
else if(k=='4') nnn=false;
else {
cout<<"选择错!"<<" 继续 y/n?"<<endl;
char mn;
cin>>mn;
if(mn=='y');
else if(mn=='n')nnn=false;
else {cout<<"由于您再次选择错误,纯属智商问题,对不起,程序跳出!"<<endl;
nnn=false;
}
}
}//while
}//else
}//if
pjh.reduce();
} //for
cout<<"***************"<<endl<<"Two hours later..."<<endl<<"***************"<<endl<<endl;
delay(2);
sxy.build(pjh.pass());
}//for
cout<<"保存已更改的信息并替换源文件类内容 y/n"<<endl;
char ty;
cin>>ty;
if(ty=='y'){cout<<"您选择保存,您所做的更改将生效!"<<endl;
cout<<"按任意键结束本程序..."<<endl;
fstream outfile("myfile.txt",std::ios::out);
outfile<<sxy;
outfile.close();
}
else if(ty=='n')cout<<"您选择不保存,您所做的更改将失效"<<endl<<"谢谢使用!"<<endl<<"按任意键结束本程序..."<<endl;
else cout<<"选择错,程序默认不保存,您所做的更改将失效"<<endl<<"谢谢使用!"<<endl<<"按任意键结束本程序..."<<endl;
system("PAUSE");
} //main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -