![]() |
#2
毕如笑2012-06-18 13:17
回复 楼主 zyd909673284
//我也不知道为什么。就在红色加下划线的那一行后面加注释就没有错误了。
![]() #include <iostream> #include<string> #include<fstream> #include<iomanip> using namespace std; class pet //宠物类 { protected: int age,number; char sex; double price; string breed; public: int a(); int n(); string b(); char s(); double p; }; string pet::b() {return breed;} char pet::s() {return sex;} int pet::a() {return age;} int pet::n() {return number;} class dog:public pet //狗类 { protected: double price; public: void display1() {cout<<"宠物狗的编号:";cin>>number; cout<<"品种:";cin>>breed; cout<<"性别(m/w):";cin>>sex; cout<<"年龄:";cin>>age; cout<<"售价:";cin>>price; } }; class cat:public pet //猫类 { protected: int number; double price; public: void display2() {cout<<"宠物猫的编号:";cin>>number; cout<<"其品种:";cin>>breed; cout<<"性别(m/w):";cin>>sex; cout<<"年龄:";cin>>age; cout<<"售价为:";cin>>price; } }; class mouse:public pet //鼠类 { protected: int number; double price; public: void display3() {cout<<"宠物鼠的编号:";cin>>number; cout<<"其品种:";cin>>breed; cout<<"性别(m/w):";cin>>sex; cout<<"年龄:";cin>>age; cout<<"售价为:";cin>>price; } }; class customer //顾客类 { protected: int conph,age; char sex; string name,family,buyst; public: int ag(),co(); string na(),fa(),bu(); char se(); }; string customer::na() {return name;} string customer::fa() {return family;} string customer::bu() {return buyst;} char customer::se() {return sex;} int customer::ag() {return age;} int customer::co() {return conph;} void cwxt() { cout<<"◆◆◇小小宠物店系统◇◆◆"<<endl; cout<<"┌—————————————————┐"<<endl; cout<<"│ 请选择您喜欢的宠物种类 │"<<endl; cout<<"├—————┬—————┬—————┤"<<endl; cout<<"│ 狗:a │ 猫:b │ 鼠:c │"<<endl; cout<<"├—————┼—————┼—————┤"<<endl; // cout<<"│并按回车键│并按回车键│并按回车键│"<<endl; cout<<"└—————┴—————┴—————┘"<<endl; cout<<"请选择一个种类:"; } int main() { int i,conph,age; char j,sex,r; string name,family,buyst; cwxt(); dog d[4]; cat c[4]; mouse m[4]; customer cu[4]; cin>>j; while(j=='a'||j=='b'||j=='c') {switch(j) { case 'a': system("CLS"); cout<<" ┌————┬——————┬——————┬——————┬——————┐"<<endl; cout<<" │ 犬类 │ 吉娃娃(1) │ 泰迪(2) │ 贵宾(3) │ 金毛列犬(4)│"<<endl; cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<" │ 年龄 │ 三个月 │ 三个月 │ 四个月 │ 五个月 │"<<endl; cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<" │ 性别 │ 公 │ 母 │ 母 │ 公 │"<<endl; cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<" │ │毛色:棕 │毛色:褐 │毛色:白 │毛色:金黄 │"<<endl; cout<<" │宠物信息│ │ │ │ │"<<endl; cout<<" │ │体型:较小 │体型:小 │体型:标准 │体型:大 │"<<endl; cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<" │ 售价 │ 550元 │ 1800元 │ 3000元 │ 700元 │"<<endl; cout<<" └————┴——————┴——————┴——————┴——————┘"<<endl; break; case 'b': system("CLS"); cout<<"┌————┬——————┬——————┬——————┬——————┐"<<endl; cout<<"│ 猫类 │ 短毛猫 (1) │ 波斯猫(2) │ 暹罗猫(3) │ 卡尔特猫(4)│"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ 年龄 │ 三个月 │ 两个月 │ 三个月 │ 两个月 │"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ 性别 │ 公 │ 母 │ 公 │ 公 │"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ │毛色:黑、白│毛色:白 │毛色:棕 │毛色:蓝灰 │"<<endl; cout<<"│宠物信息│ │ │ │ │"<<endl; cout<<"│ │体型:魁梧 │体型:健壮 │体型:标准 │体型:稍胖 │"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ 售价 │ 5500元 │ 1000元 │ 666元 │ 1500元 │"<<endl; cout<<"└————┴——————┴——————┴——————┴——————┘"<<endl; break; case 'c': system("CLS"); cout<<"┌————┬——————┬——————┬——————┬——————┐"<<endl; cout<<"│ 鼠类 │ 天竺鼠(1) │ 黄金鼠(2) │ 银狐(3) │ 通心粉鼠(4)│"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ 年龄 │ 三个月 │ 三个月 │ 四个月 │ 两个月 │"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ 性别 │ 公 │ 母 │ 母 │ 公 │"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ │毛色: 棕 │毛色:金 │毛色:银白 │毛色:白、红│"<<endl; cout<<"│宠物信息│ │ │ │ │"<<endl; cout<<"│ │体型:小 │体型:大 │体型:标准 │体型:肥硕 │"<<endl; cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl; cout<<"│ 售价 │ 30 元 │ 10 元 │ 150元 │ 200元 │"<<endl; cout<<"└————┴——————┴——————┴——————┴——————┘"<<endl; break; } if(j=='a'||j=='b'||j=='c') cout<<"请选择您想购买的种类 ,输入编号:"; { cin>>i; if(i==1||i==2||i==3||i==4) { cout<<"您将购买"<<i<<"号宠物,请确认(y/n)!"<<endl; cin>>r; if(r=='y') { system("CLS"); cout<<" ※※请填写下面的资料※※"<<endl; cout<<"姓名:"<<endl; cin>>name; cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl; cout<<"性别(w/m):"<<endl; cin>>sex; cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl; cout<<"年龄:"<<endl; cin>>age; cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl; cout<<"购买类型:"<<endl; cin>>buyst; cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl; cout<<"联系电话:"<<endl; cin>>conph; cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl; cout<<"家庭住址:"<<endl; cin>>family; cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl; cout<<"█ 〓█ ★ 填写完成,请按1 !★█ 〓 ███▄"<<endl; int x; cin>>x; switch(x) case 1: cout<<" 为了确保您的信息丢失,请您按1进行资料备份"<<endl; int y; cin>>y; switch(y) { case 1: { ofstream outfile("beifen.txt",ios::out) ; if(! outfile) { cerr<<"open error!"<<endl; exit(0); } cout<<"数据备份,请等待........ "; outfile<<"顾客信息:"<<endl; for(i=0;i<4;i++) { outfile<<" 姓名: "<<cu[i].na()<<" 性别: "<<cu[i].se()<<" 年龄: "<<cu[i].ag() <<" 购买类型: "<<cu[i].bu()<<" 联系电话: "<<cu[i].co()<<" 家庭住址: "<<cu[i].fa()<<endl; } outfile<<"------------------------------------------------------------------"<<endl; } } system("CLS"); cout<<" 恭喜您,购买成功!"<<endl; } else cout<<"谢谢光临!"<<endl; } return 0; } } } |
#include <iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
class pet //宠物类
{
protected:
int age,number;
char sex;
double price;
string breed;
public:
int a();
int n();
string b();
char s();
double p;
};
string pet::b()
{return breed;}
char pet::s()
{return sex;}
int pet::a()
{return age;}
int pet::n()
{return number;}
class dog:public pet //狗类
{
protected:
double price;
public:
void display1()
{cout<<"宠物狗的编号:";cin>>number;
cout<<"品种:";cin>>breed;
cout<<"性别(m/w):";cin>>sex;
cout<<"年龄:";cin>>age;
cout<<"售价:";cin>>price;
}
};
class cat:public pet //猫类
{
protected:
int number;
double price;
public:
void display2()
{cout<<"宠物猫的编号:";cin>>number;
cout<<"其品种:";cin>>breed;
cout<<"性别(m/w):";cin>>sex;
cout<<"年龄:";cin>>age;
cout<<"售价为:";cin>>price;
}
}; class mouse:public pet //鼠类
{
protected:
int number;
double price;
public:
void display3()
{cout<<"宠物鼠的编号:";cin>>number;
cout<<"其品种:";cin>>breed;
cout<<"性别(m/w):";cin>>sex;
cout<<"年龄:";cin>>age;
cout<<"售价为:";cin>>price;
}
}; class customer //顾客类
{
protected:
int conph,age;
char sex;
string name,family,buyst;
public:
int ag(),co();
string na(),fa(),bu();
char se();
};
string customer::na()
{return name;}
string customer::fa()
{return family;}
string customer::bu()
{return buyst;}
char customer::se()
{return sex;}
int customer::ag()
{return age;}
int customer::co()
{return conph;}
void cwxt()
{
cout<<"◆◆◇小小宠物店系统◇◆◆"<<endl;
cout<<"┌—————————————————┐"<<endl;
cout<<"│ 请选择您喜欢的宠物种类 │"<<endl;
cout<<"├—————┬—————┬—————┤"<<endl;
cout<<"│ 狗:a │ 猫:b │ 鼠:c │"<<endl;
cout<<"├—————┼—————┼—————┤"<<endl;
cout<<"│并按回车键│并按回车键│并按回车键│"<<endl;
cout<<"└—————┴—————┴—————┘"<<endl;
cout<<"请选择一个种类:";
}
int main()
{
int i,conph,age;
char j,sex,r;
string name,family,buyst;
cwxt();
dog d[4];
cat c[4];
mouse m[4];
customer cu[4];
cin>>j;
while(j=='a'||j=='b'||j=='c')
{switch(j)
{
case 'a':
system("CLS");
cout<<" ┌————┬——————┬——————┬——————┬——————┐"<<endl;
cout<<" │ 犬类 │ 吉娃娃(1) │ 泰迪(2) │ 贵宾(3) │ 金毛列犬(4)│"<<endl;
cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<" │ 年龄 │ 三个月 │ 三个月 │ 四个月 │ 五个月 │"<<endl;
cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<" │ 性别 │ 公 │ 母 │ 母 │ 公 │"<<endl;
cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<" │ │毛色:棕 │毛色:褐 │毛色:白 │毛色:金黄 │"<<endl;
cout<<" │宠物信息│ │ │ │ │"<<endl;
cout<<" │ │体型:较小 │体型:小 │体型:标准 │体型:大 │"<<endl;
cout<<" ├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<" │ 售价 │ 550元 │ 1800元 │ 3000元 │ 700元 │"<<endl;
cout<<" └————┴——————┴——————┴——————┴——————┘"<<endl;
break;
case 'b':
system("CLS");
cout<<"┌————┬——————┬——————┬——————┬——————┐"<<endl;
cout<<"│ 猫类 │ 短毛猫 (1) │ 波斯猫(2) │ 暹罗猫(3) │ 卡尔特猫(4)│"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ 年龄 │ 三个月 │ 两个月 │ 三个月 │ 两个月 │"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ 性别 │ 公 │ 母 │ 公 │ 公 │"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ │毛色:黑、白│毛色:白 │毛色:棕 │毛色:蓝灰 │"<<endl;
cout<<"│宠物信息│ │ │ │ │"<<endl;
cout<<"│ │体型:魁梧 │体型:健壮 │体型:标准 │体型:稍胖 │"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ 售价 │ 5500元 │ 1000元 │ 666元 │ 1500元 │"<<endl;
cout<<"└————┴——————┴——————┴——————┴——————┘"<<endl;
break;
case 'c':
system("CLS");
cout<<"┌————┬——————┬——————┬——————┬——————┐"<<endl;
cout<<"│ 鼠类 │ 天竺鼠(1) │ 黄金鼠(2) │ 银狐(3) │ 通心粉鼠(4)│"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ 年龄 │ 三个月 │ 三个月 │ 四个月 │ 两个月 │"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ 性别 │ 公 │ 母 │ 母 │ 公 │"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ │毛色: 棕 │毛色:金 │毛色:银白 │毛色:白、红│"<<endl;
cout<<"│宠物信息│ │ │ │ │"<<endl;
cout<<"│ │体型:小 │体型:大 │体型:标准 │体型:肥硕 │"<<endl;
cout<<"├————┼——————┼——————┼——————┼——————┤"<<endl;
cout<<"│ 售价 │ 30 元 │ 10 元 │ 150元 │ 200元 │"<<endl;
cout<<"└————┴——————┴——————┴——————┴——————┘"<<endl;
break;
}
if(j=='a'||j=='b'||j=='c')
cout<<"请选择您想购买的种类 ,输入编号:";
{
cin>>i;
if(i==1||i==2||i==3||i==4)
{ cout<<"您将购买"<<i<<"号宠物,请确认(y/n)!"<<endl;
cin>>r;
if(r=='y')
{
system("CLS");
cout<<" ※※请填写下面的资料※※"<<endl;
cout<<"姓名:"<<endl;
cin>>name;
cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"性别(w/m):"<<endl;
cin>>sex;
cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"年龄:"<<endl;
cin>>age;
cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"购买类型:"<<endl;
cin>>buyst;
cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"联系电话:"<<endl;
cin>>conph;
cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"家庭住址:"<<endl;
cin>>family;
cout<<"〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"█ 〓█ ★ 填写完成,请按1 !★█ 〓 ███▄"<<endl;
int x;
cin>>x;
switch(x)
case 1:
cout<<" 为了确保您的信息丢失,请您按1进行资料备份"<<endl;
int y;
cin>>y;
switch(y)
{
case 1:
{
ofstream outfile("beifen.txt",ios::out) ;
if(! outfile)
{
cerr<<"open error!"<<endl;
exit(0);
}
cout<<"数据备份,请等待........ ";
outfile<<"顾客信息:"<<endl;
for(i=0;i<4;i++)
{
outfile<<" 姓名: "<<cu[i].na()<<" 性别: "<<cu[i].se()<<" 年龄: "<<cu[i].ag()
<<" 购买类型: "<<cu[i].bu()<<" 联系电话: "<<cu[i].co()<<" 家庭住址: "<<cu[i].fa()<<endl;
}
outfile<<"------------------------------------------------------------------"<<endl;
}
}
system("CLS");
cout<<" 恭喜您,购买成功!"<<endl;
}
else
cout<<"谢谢光临!"<<endl;
}
return 0;
}
}
}