#include<iostream>
#include<fstream>
#include<ctime>
#include<cstdlib>
#include<iomanip>
#include<string>
#define space "\t\t\t"
using namespace std;
class customer{
public:
string id;
string password;
string phone,mail;
};
class Product{
public:
string pname;
double price;
string deadline;
string pno,other;
};
void a_price(string z,string y,double x);
void newproduct(string z);
void list(string z);
void regist(customer x);
void login();
void menu(string z);
void information(string z);
void modify(customer x);
void store();
int i=0;
customer c;
void index(){
ifstream infile;
infile.open("number.ini");
infile>>i;
int choice;
cout<<space<<"****欢迎使用在线仿真拍卖系统****\n"<<space<<"\t(已注册人数:"<<i<<")"<<endl;
cout<<"\t\t\t 制作人:XXX \n"<<endl;
cout << "\t\t1 -- 注册\t2 -- 登录\t3--退出\n";
cin>>choice;
switch(choice){
case 1: regist(c);
case 2: login();
case 3: exit(0);
}
}
void store(){
i=i-1;
ofstream outfile;
outfile.open("number.ini");
outfile<<i;
outfile.close();
}
void regist(customer x){
cout<<"\n请输入用户名(不得超过12个字符):\n";
cin>>x.id;
while((x.id).length()>12){
cout<<"!!!用户名过长,请重新输入...\n";
cout<<"\n请输入用户名(不得超过12个字符):\n";
cin>>x.id;
}
cout<<"检查用户名是否可用"<<endl;
system("PAUSE");
ifstream infile;
string fname1;
fname1=x.id ;//"_c.txt";
infile.open(fname1.c_str(),ios::in);
string same_n;
infile>>same_n;
if(same_n!=x.id){
cout<<"\n ^_^ 恭喜!该用户名可用。"<<endl;
}
else{
cout<<"\n T_T 对不起,该用户名已存在\n\n请重新输入..." <<endl;
regist(x);
}
cout<<"\n请输入密码(不得超过20位):\n" ;
cin>>x.password;
while((x.password).length()>20){
cout<<"!!!密码过长,请重新输入...\n";
cout<<"\n请输入密码(不得超过20位):\n" ;
cin>>x.password;
}
system("pause");
system("cls");
cout<<"请输入联系电话:\n";
cin>>x.phone;
cout<<"请输入电子邮箱:\n";
cin>>x.mail;
string fname2;
fname2=x.id ;//"_c.txt";
ofstream file(fname2.c_str());
file<<x.id<<'\n'<<x.password<<'\n'<<x.phone<<'\n'<<x.mail;
file.close();
cout<<"信息保存成功!!"<<endl;
store();
system("PAUSE");
system("cls");
index();
}
void login(){
customer log;
customer a;
cout<<"请输入用户名:";
cin>>log.id;
cout<<"请输入密码:";
cin>>log.password;
ifstream infile;
string fname=log.id ;//"_c.txt";
infile.open(fname.c_str());
infile>>a.id>>a.password;
if(log.id==a.id&&log.password==a.password)
{
system("cls");
menu(a.id);//转到产品列表等菜单
}
else{
system("cls");
cerr<<"用户名或密码错误,是否重新输入(Y/N)\n";
char c;
cin>>c;
if(c=='Y'||c=='y')
login();
else index();
}
}
void menu(string z){
cout<<"\n\n\t\t......&欢迎"<<z<<"进入拍卖系统&......\n"
<<space<<"$1. 用户信息\n"
<<space<<"$2. 自出产品参与竞拍\n"
<<space<<"$3. 在线竞拍产品信息列表\n"
<<space<<"$4. 退出系统\n";
int c;
cin>>c;
switch(c){
case 1: information(z);// 竞拍计时器
case 2: newproduct(z);
case 3: list(z);
case 4: system("cls");index();
}
}
void information(string z){
ifstream infile;
string fname=z ;//"_c.txt";
infile.open(fname.c_str());
customer a;
infile>>a.id>>a.password>>a.phone>>a.mail;
cout<<"\n用户名:"<<a.id<<"\n联系电话:"<<a.phone<<"\n电子邮箱:"<<a.mail;
cout<<"\n......您的信息如上.......\n"<<"\n#1.修改密码"<<space<<"#2.返回\n";
int c;
cin>>c;
switch(c){
case 1: modify(a);
case 2: system("cls");menu(a.id);
}
system("PAUSE");
}
void modify(customer x){
cout<<"请输入新密码:\n" ;
cin>>x.password;
system("cls");
ofstream outfile;
string fname=x.id ;//"_c.txt";
outfile.open(fname.c_str());
outfile<<x.id<<'\n'
<<x.password<<'\n'
<<x.phone<<'\n'
<<x.mail;
outfile.close();
cout<<"密码修改成功!!"<<endl;
system("PAUSE");
index();
}
string set(){
string c;
time_t stamp;
time_t now=time(0);
stamp=864000;//now 864000;
c=ctime( &stamp);
return c;}
void a_price(string z,string y,double x){
string set();
ifstream infile;
ofstream outfile;
infile.open(y.c_str(),ios::in);
Product p;
string day1,mon1,da1,t1,y1,name1;
infile>>p.pname>>p.price>>day1>>mon1>>da1>>t1>>y1>>name1>>p.other;
if(x>p.price)
{
p.deadline=set();
p.price=x;
outfile.open(y.c_str());
outfile<<p.pname<<'\n'<<p.price<<'\n'<<p.deadline<<'\n'<<z<<'\n'<<p.other;
outfile.close();
cout<<"\n**恭喜竞价成功!**\n"<<endl;
cout<<"~~返回产品列表~~";
system("PAUSE");
system("cls");
list(z);
}
else{
cerr<<"\n对不起,您的出价无效!\n";
cout<<"\n1.重新输入竞价 || 2.返回主菜单\n";
int c;
cin>>c;
switch(c){
case 1: {double newpric;cout<<"\n重新输入的价格:";cin>>newpric;a_price(z,y,newpric);}
case 2: system("cls");menu(z);
}
}
infile.close();
}
void newproduct(string z){
string set();
Product newpr;
cout<<"请输入产品名称:";
cin>>newpr.pname;
ifstream infile;
ifstream ifile;
ofstream outfile;
ofstream oufile;
infile.open("product.ini");
int a=0;
infile>>a;
oufile.open("product.ini");
oufile<<a;
oufile.close();
outfile.open("list.txt",ios::app);
outfile<<a<<" "<<newpr.pname<<'\n';
outfile.close();
ifile.open("product.ini");
string s;
ifile>>s;
string fname;
fname=s ;//"_p.txt";
ofstream file(fname.c_str());
cout<<"请输入底价:";
cin>>newpr.price;
newpr.deadline=set();
cout<<"产品简介:\n";
cin>>newpr.other;
file<<newpr.pname<<'\n'
<<newpr.price<<'\n'
<<newpr.deadline<<'\n'
<<z<<'\n'<<newpr.other;
file.close();
system("PAUSE");
system("cls");
menu(z);
}
void list(string z){
cout<<setw(4)<<"产品编号 "<<setw(10)<<"产品名称\t"<<setw(10)<<"目前最高价\t"<<"拍卖截止日期"<<"\t\t\t出价者"<<endl;
Product p[1000];
int scope;
ifstream infile,ifile;
infile.open("product.ini",ios::in);
infile>>scope;
ifile.open("list.txt");
for(int t=0;t<=scope;t )
{
ifile>>p[t].pno>>p[t].pname;
if(t<scope){
string fname;
fname=p[t].pno ;//"_p.txt";
ifstream in_file;
in_file.open(fname.c_str());
Product d;
d.pno=p[t].pno;
string day,mon,da,t,y,name;
in_file>>d.pname>>d.price>>day>>mon>>da>>t>>y>>name;
cout<<setw(4)<<d.pno<<'\t'<<setw(10)<<d.pname<<'\t'<<setw(10)<<d.price<<'\t'<<day<<" "<<mon<<" "<<da<<" "<<t<<" "<<y<<'\t' <<name<<endl;
}
else
break;
}
cout<<"---------------------------------\n"
<<" 1.查看商品详细信息\t"<<"2.返回主菜单\n";
int c;
cin>>c;
if(c==1)
{
string no;
cout<<"请输入产品编号:\n";
cin>>no;
string fname2=no ;//"_p.txt";
ifstream pfile;
pfile.open(fname2.c_str());
Product pd;
string day1,mon1,da1,t1,y1,name1;
pfile>>pd.pname>>pd.price>>day1>>mon1>>da1>>t1>>y1>>name1>>pd.other;
cout<<"\n产品详细信息如下>>\n";
cout<<"\n产品名称: "<<pd.pname<<endl;
cout<<"目前最高价: "<<pd.price<<" 元"<<endl;
cout<<"截止日期: "<<day1<<" "<<mon1<<" "<<da1<<" "<<t1<<" "<<y1<<endl;
cout<<"最高价出价者: "<<name1<<endl;
cout<<"产品简介:\n"<<pd.other<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"
<<"1.我要出价||2.返回列表\n"<<endl;
int ch;
cin>>ch;
if(ch==1){
cout<<"您出的价格为: ";
double newprice;
cin>>newprice;
a_price(z,fname2,newprice);
}
else list(z);
}
else {system("cls");menu(z);}
}
int main()
{
index();
return EXIT_SUCCESS;
}
--------------------Configuration: taobao - Win32 Debug--------------------
Compiling...
taobao.cpp
Linking...
taobao.exe - 0 error(s), 0 warning(s)
不好意思,这是我改过几处地方,你看看吧。希望你能找到更好的方法。