#include<iostream>
#include<cstring>
#include<vector>
#include<fstream>
#include"list"
using namespace std;
class Data
{
public:
void set_time( );
void show_time( );
private:
bool is_time(int, int, int);
int year;
int month;
int day;
};
void Data::set_time( )
{
char c1,c2;
cout<<"请输入日期(格式年-月-日)"<<endl;
while(1)
{
cin>>year>>c1>>month>>c2>>day;
if(c1!='-'||c2!='-')
cout<<"格式不正确,请重新输入"<<endl;
else
break;
}
}
void Data::show_time( )
{
cout<<year<<"-"<<month<<"-"<<day<<endl;
}
class Pet
{
public:
PetAnimals(){}
PetAnimals( string Number, string Name, string Age, string Weight, string Type,
string Nature, string Price, string People )
{
Cnumber=Number;
Cname=Name;
Cage=Age;
Cweight=Weight;
Ctype=Type;
Cnature=Nature;
Cprice=Price;
Cpeople=People;
}
string Cnumber;
string Cname;
string Cage;
string Cweight;
string Ctype;
string Cnature;
string Cprice;
string Cpeople;
};
class guest
{
public:
string Cnumber;
string Cname;
string Cage;
string Cweight;
string Ctype;
string Cnature;
string Cprice;
string Cpeople;
};
class PetAnimals:public Pet
{
public:
void Insert();
bool Look();
bool Change();
void Show();
bool Delete();
void Read();
void Write();
};
list<PetAnimals>PetList;
void PetAnimals::Insert()
{
PetAnimals Pet;
char ch;
int symbol=0;
list<PetAnimals>::iterator first,last;
first=PetList.begin();
last=PetList.end();
do{
cout<<"【请输入宠物相关信息!】"<<endl;
cout<<"编号:";
cin>>Pet.Cnumber;
cout<<"名称:";
cin>>Pet.Cname;
cout<<"年龄:";
cin>>Pet.Cage;
cout<<"重量:";
cin>>Pet.Cweight;
cout<<"种类:";
cin>>Pet.Ctype;
cout<<"性格:";
cin>>Pet.Cnature;
cout<<"价格:";
cin>>Pet.Cprice;
cout<<"主人:";
cin>>Pet.Cpeople;
for( ; first != last ; ++first )
{
if((Pet.Cname==(*first).Cname)&&(Pet.Cprice==(*first).Cprice)
&&(Pet.Ctype==(*first).Ctype))
{
symbol=1;
cout<<endl<<"★该宠物已经存在!"<<endl;
cout<<"编号:"<<(*first).Cnumber<<endl;
cout<<"名称:"<<(*first).Cname<<endl;
cout<<"年龄:"<<(*first).Cage<<endl;
cout<<"重量:"<<(*first).Cweight<<endl;
cout<<"种类:"<<(*first).Ctype<<endl;
cout<<"性格:"<<(*first).Cnature<<endl;
cout<<"价格:"<<(*first).Cprice<<endl;
cout<<"主人:"<<(*first).Cpeople;
}
}
if(symbol==0)
{
PetList.insert(PetList.end(),Pet);
}
cout<<endl<<"★继续添加宠物信息[Y或N]?";
cin>>ch;
}
while(ch=='Y'||ch=='y');
}
bool PetAnimals::Look()
{
string name,price,type;
int symbol=0;
int option;
list <PetAnimals>::iterator first,last;
do
{
cout<<"t【请输入你查找的方式】!"<<endl;
cout<<"t1.按名称查找"<<endl;
cout<<"t2.按价格查找"<<endl;
cout<<"t3.按种类查找"<<endl;
cout<<"t4.退出!"<<endl;
cin>>option;
switch(option)
{
case 1: cout<<"请输入名称:";
cin>>name;break;
case 2: cout<<"请输入价格:";
cin>>price;break;
case 3: cout<<"请输入种类:";
cin>>type;break;
case 4:break;
}
first=PetList.begin();
last=PetList.end();
for(;first!=last;++first)
{
if((name==(*first).Cname)&&(option==1))
{
symbol=1;
cout<<"★宠物名称为"+(*first).Cname+"宠物信息如下:"<<endl;
cout<<"编号:"+(*first).Cnumber<<endl;
cout<<"名称:"+(*first).Cname<<endl;
cout<<"年龄:"+(*first).Cage<<endl;
cout<<"重量:"+(*first).Cweight<<endl;
cout<<"种类:"+(*first).Ctype<<endl;
cout<<"性格:"+(*first).Cnature<<endl;
cout<<"价格:"+(*first).Cprice<<endl;
cout<<"主人:"+(*first).Cpeople<<endl;
}
if((price==(*first).Cprice)&&(option==2))
{
symbol=1;
cout<<"★宠物价格为"+(*first).Cprice+"宠物信息如下:"<<endl;
cout<<"编号:"+(*first).Cnumber<<endl;
cout<<"名称:"+(*first).Cname<<endl;
cout<<"年龄:"+(*first).Cage<<endl;
cout<<"重量:"+(*first).Cweight<<endl;
cout<<"种类:"+(*first).Ctype<<endl;
cout<<"性格:"+(*first).Cnature<<endl;
cout<<"价格:"+(*first).Cprice<<endl;
cout<<"主人:"+(*first).Cpeople<<endl;
}
if((type==(*first).Ctype)&&(option==3))
{
symbol=1;
cout<<"★宠物种类为"+(*first).Ctype+"宠物信息如下:"<<endl;
cout<<"编号:"+(*first).Cnumber<<endl;
cout<<"名称:"+(*first).Cname<<endl;
cout<<"年龄:"+(*first).Cage<<endl;
cout<<"重量:"+(*first).Cweight<<endl;
cout<<"种类:"+(*first).Ctype<<endl;
cout<<"性格:"+(*first).Cnature<<endl;
cout<<"价格:"+(*first).Cprice<<endl;
cout<<"主人:"+(*first).Cpeople<<endl;
}
}
}
while(option!=4);
if((first==last)&&(symbol==0))
{
cout<<"★没有该宠物信息!";
return false;}
else
return true;
}
bool PetAnimals::Change()
{
PetAnimals pet;
string name,price,type;
int symbol=0;
cout<<"请输入名称:";
cin>>name;
cout<<"请输入价格:";
cin>>price;
cout<<"请输入种类:";
cin>>type;
list <PetAnimals>::iterator first,last;
first=PetList.begin();
last=PetList.end();
for(;first!=last;++first)
{
if((name==(*first).Cname)&&(price==(*first).Cprice)&&(type==(*first).Ctype))
{
symbol=1;
cout<<endl<<"★该宠物信息找到,其修改前的宠物信息为:"<<endl;
cout<<"编号:"+(*first).Cnumber<<endl;
cout<<"名称:"+(*first).Cname<<endl;
cout<<"年龄:"+(*first).Cage<<endl;
cout<<"重量:"+(*first).Cweight<<endl;
cout<<"种类:"+(*first).Ctype<<endl;
cout<<"性格:"+(*first).Cnature<<endl;
cout<<"价格:"+(*first).Cprice<<endl;
cout<<"主人:"+(*first).Cpeople<<endl;
break;
}
}
if(symbol)
{
cout<<endl<<"★修改后的宠物信息为:"<<endl;
cout<<"年龄:";
cin>>pet.Cage;
cout<<"重量:";
cin>>pet.Cweight;
cout<<"性格:";
cin>>pet.Cnature;
cout<<"主人:";
cin>>pet.Cpeople;
pet.Cname=name;
pet.Cprice=price;
pet.Ctype=type;
for(;first!=last;++first)
{
if((name==(*first).Cname)&&(price==(*first).Cprice)&&(type==(*first).Ctype))
{
(*first)=pet;
}
}
return true;
}
else
{
cout<<"★没有该宠物信息!";
return false;
}
}
void PetAnimals::Show()
{
list <PetAnimals>::iterator first,last,it;
first=PetList.begin();
last=PetList.end();
for(;first!=last;++first)
{
cout<<"******************您的宠物信息**********************"<<endl;
cout<<"编号:"<<(*first).Cnumber<<endl;
cout<<"名称:"<<(*first).Cname<<endl;
cout<<"年龄:"<<(*first).Cage<<endl;
cout<<"重量:"<<(*first).Cweight<<endl;
cout<<"种类:"<<(*first).Ctype<<endl;
cout<<"性格:"<<(*first).Cnature<<endl;
cout<<"价格:"<<(*first).Cprice<<endl;
cout<<"主人:"<<(*first).Cpeople<<endl;
cout<<"****************************************"<<endl;
}
}
bool PetAnimals::Delete()
{
string name,price,type;
int symbol=0;
cout<<"请输入名称:";
cin>>name;
cout<<"请输入价格:";
cin>>price;
cout<<"请输入种类:";
cin>>type;
list <PetAnimals>::iterator first,last,it;
first=PetList.begin();
last=PetList.end();
for(;first!=last;++first)
{
if((name==(*first).Cname)&&(price==(*first).Cprice)&&(type==(*first).Ctype))
{
symbol=1;
cout<<"★找到该宠物信息!可删除!"<<endl;
it=first;
PetList.erase(first);
}
}
if((first==last)&&(symbol==0))
{
cout<<"★没有该宠物信息!";
return false;}
else
{
PetList.erase(it);
return true;
}
}
void PetAnimals::Write()
{
char file[256];
string FileName;
cout<<"★请输入文件名:(可以加扩展名!如.txt)";
cin>>FileName;
if(FileName.find (".")>FileName.length())
{
FileName=FileName+".txt";
}
strcpy(file,FileName.c_str());
ofstream fout(file);
if(!fout)
{
cout<<"★文件写入失败!请检查您的文件名!"<<endl;
return;
}
else
{
list <PetAnimals>::iterator first,last;
first=PetList.begin();
last=PetList.end();
for(;first!=last;++first)
{
fout<<endl<<"编号:"<<(*first).Cnumber<<endl<<"名称:"<<(*first).Cname<<endl
<<"年龄:"<<(*first).Cage<<endl<<"重量:"<<(*first).Cweight<<endl
<<"种类:"<<(*first).Ctype<<endl<<"性格:"<<(*first).Cnature<<endl
<<"价格:"<<(*first).Cprice<<endl<<"主人:"<<(*first).Cpeople<<endl;
}
cout<<"★文件保存成功!"<<endl;
}
fout.close ();
}
void PetAnimals::Read()
{
char file[256];
string FileName;
cout<<"★请输入文件名:(可以加扩展名!如.txt)";
cin>>FileName;
if(FileName.find (".")>FileName.length())
{
FileName=FileName+".txt";
}
strcpy(file,FileName.c_str());
ifstream fin(file);
int index;
if(!fin)
{
cout<<"★文件写入失败!请检查您的文件名!"<<endl;
return ;
}
else
{
PetList.clear ();
while(!fin.eof())
{
PetAnimals pet;
string str;
fin>>str;
index=str.find(":");
pet.Cnumber =str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Cname =str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Cage =str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Cweight =str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Ctype =str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Cnature=str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Cprice=str.substr(index+1);
fin>>str;
index=str.find (":");
pet.Cpeople =str.substr(index+1);
PetList.insert(PetList.end(),pet);
}
cout<<"n"<<" ★请保护好您的爱宠哦(^。^*)!★ "<<endl;
cout<<" ★文件读取成功! ★"<<endl;
}
fin.close();
}
int main()
{
PetAnimals pet;
int option;
do
{
cout<<endl<<"★★★【欢迎进入宠物商店管理系统! 请选择菜单:】★★★"<<endl;
cout<<" t┌-------------------------┐"<<endl;
cout<<" t┊ 1.添加宠物的信息 ┊"<<endl;
cout<<" t┊ 2.查找宠物的信息 ┊"<<endl;
cout<<" t┊ 3.修改宠物的信息 ┊"<<endl;
cout<<" t┊ 4.显示(浏览)宠物的信息┊"<<endl;
cout<<" t┊ 5.删除宠物的信息 ┊"<<endl;
cout<<" t┊ 6.保存文件 ┊"<<endl;
cout<<" t┊ 7.读取文件 ┊"<<endl;
cout<<" t┊ 8.退出系统 ┊"<<endl;
cout<<" t└-------------------------┘n"<<endl;
cin>>option;
switch(option)
{
case 1: { pet.Insert(); break; }
case 2: { pet.Look(); break; }
case 3: { pet.Change(); break; }
case 4: { pet.Show(); break; }
case 5: { pet.Delete(); break; }
case 6: { pet.Write(); break; }
case 7: { pet.Read(); break; }
case 8: { break ; }
}
}
while(option != 8);
return 0;
}
相关知识
宠物商店信息管理系统(C++)
宠物商店信息管理系统
Java+MySQL宠物商店系统设计与实现
基于SpringBoot+Vue宠物商店的设计与实现
Java实现简单的宠物商店管理系统
宠物商店管理系统功能详解与操作指南
网上宠物商店系统开题报告
springboot+vue宠物医院信息管理系统的设计与实现【开题+程序+论文】
基于springboot+mybatis+mysql+html实现宠物医院管理系统(包含实验报告)资源
java宠物商店项目
网址: C++实现宠物商店信息管理系统 https://m.mcbbbk.com/newsview642457.html
上一篇: 定期给狗狗称体重的重要性 |
下一篇: python宠物信息管理系统的思 |