// 307.cpp : Defines the entry point for the console application.//
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
void Menu();
class account
{
string user;
string pass;
public:
void reg();//注册
void login();//登录
void password();
private:
void save();
string** read();
};
void account::reg()
{
ofstream out ("account.dat", ios::app);
//string disk[4][2];
//string ** d1;
string pass1;
string pass2;
cout<<"欢迎来到注册页面"<<endl;
cout<<"请输入用户名"<<endl;
cin>>user;
cout<<"请输入密码"<<endl;
cin>>pass1;
cout<<"请再输入一次密码"<<endl;
cin>>pass2;
string **disk=read();
for ( int i = 0 ; i <sizeof(disk[0]); i++)
{
if(disk[i][0] != user )
{
cout<<"ok"<<endl;
break;
}
else
{
cout<<"用户名已经存在"<<endl;
cout<<"请重新注册:"<<endl;
reg();
}
}
if(pass1==pass2)
{
cout<<"注册成功"<<endl;
save();
}
else
{
cout<<"输入的密码两次不相同"<<endl;
reg();
}
}
void account::login()
{
//string disk[4][2];
cout<<"欢迎来到登录界面"<<endl;
cout<<"请输入您的用户名:";
cin>>user;
cout<<"请输入您的密码:";
cin>>pass;
cout<<endl;
string **disk=read();
for(int i=0;i<sizeof(disk);i++)
{
if(disk[i][0]==user&&disk[i][1]==pass)
{
cout<<"登录成功!进入下一个菜单"<<endl;
Menu();
}
else
{
cout<<"用户名注册错误或者密码错误"<<endl;
cout<<"请重新登录"<<endl;
login();
}
}
}
string** account::read()
{
ifstream in("account.dat");
int x, y;
string disk[4][2];
for (x = 0; !in.eof(); x++)
{
string line;
getline(in,line);
istringstream ss(line);
for (y = 0; !ss.eof(); y++)
{
ss >> disk[x][y];
}
}
/*string *a ;
a=&disk;*/
return (string**)disk;
}
void account::save()
{
ofstream out ("account.dat",ios::out);
out<<user<<" "<<pass<<endl;
//out.close();
}
class book
{
protected:
string cname;//餐厅名字
string num;//电话号码
int month;
int day;
int quantity;//人数
string remark;
public:
book(string pcname);
void enter();
void report();
};
book::book(string pcname):
cname(pcname)
{}
void book::enter()
{
cout<<"请输入要预定"+cname+"的相关信息(电话号码、日期、人数、备注):"<<endl;
cin>>num>>month>>day>>quantity>>remark;
}
void book::report()
{
cout<<"以下是您预定餐厅的信息"<<endl;
cout<<"餐厅名字:"<<cname<<endl;
cout<<"您的电话:"<<num<<endl;
cout<<"日期为: "<<month<<"月"<<day<<"日"<<endl;
cout<<"人数: "<<quantity<<endl;
cout<<"备注: "<<remark<<endl;
}
int main()
{
account acc1;
int choose=-1;
while(1)
{
cout<<"请选择"<<endl;
cout<<"************************"<<endl;
cout<<" 0.退出 "<<endl;
cout<<" 1.注册 "<<endl;
cout<<" 2.登录 "<<endl;
cout<<"************************"<<endl;
cin>>choose;
switch (choose)
{
case 1: acc1.reg();
continue;
case 2: acc1.login();
continue;
case 0: exit(0);
default: cout<<"选择超出范围"<<endl;
continue;
}
}
Menu();
return 0;
}
void Menu()
{
while(1)
{
book a1("307");
int choose=-1;
cout<<"请选择"<<endl;
cout<<"************************"<<endl;
cout<<" 0. 退出 "<<endl;
cout<<" 1.填写预定信息 "<<endl;
cout<<" 2.您的预定信息 "<<endl;
cout<<"************************"<<endl;
cin>>choose;
switch (choose)
{
case 1: a1.enter();
continue;
case 2: a1.report();
break;
case 0: exit(0);
default: cout<<"选择超出范围,请重新选择"<<endl;
continue;
}
}
}