C++实现宠物商店信息管理系统
C++实现宠物商店信息管理系统
本⽂实例为⼤家分享了C++实现宠物商店信息管理系统的具体代码,供⼤家参考,具体内容如下
⼀、问题描述
设计⼀个程序实现对⼩动物商店的简单管理,主要功能:宠物基本信息(编号,名称,体重,年龄,类别,价格,性格等)的输⼊、显⽰、查询等功能;宠物的交易、状态及顾客(宠物主⼈)的记录查询和修改。
⼆、基本要求
(1)使⽤⾯向对象思想开发需要的类,⽐如:宠物类包含宠物的基本属性信息和基本操作,⽇期类记录交易⽇期,顾客类记录顾客的信息;管理类,实现对宠物情况的操作;输⼊和输出的操作要求对输出运算符“>>”和输出运算符“<<”进⾏重载
(2)输⼊和输出可以使⽤⽂本⽂件重定向输⼊(保存数据为磁盘⽂件);也可以使⽤标准输⼊输出进⾏(提交时需要提交TXT格式输⼊数据)。程序运⾏时进⾏初始化数据,使⽤vector数组存放。交易数据记录交易的⽇期、宠物名称、宠物类别、顾客姓名、交易⾦额等,有6条以上记录。
(3)运⾏后使⽤菜单功能显⽰所有宠物信息,根据类别显⽰记录,根据名称查询记录,添加(购⼊)宠物,删除(卖出)宠物,交易记录,按⽇期查询交易记录。
系统流程图
源代码
#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;//宠物编号:00,01,02 ...
Cname=Name;//宠物名称:贝贝
Cage=Age;//宠物年龄:20,14
姹紫嫣红的嫣是什么意思Cweight=Weight;//宠物重量(⽄):20,45
Ctype=Type;//宠物种类:cat
Cnature=Nature;//宠物性格:
Cprice=Price;//宠物价格:20...
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();//begin()指链表开始处
d();//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.d(),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();
d();
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();
d();
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();
d();
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();
d();
for(;first!=last;++first)
{
if((name==(*first).Cname)&&(price==(*first).Cprice)&&(type==(*first).Ctype))
{
symbol=1;
cout<<"★到该宠物信息!可删除!"<<endl;
父亲节的日期
it=first;
}
}
if((first==last)&&(symbol==0))
{
cout<<"★没有该宠物信息!";
return false;}
else
{
return true;
}
}
//保存宠物信息
void PetAnimals::Write()
{
char file[256];
string FileName;
cout<<"★请输⼊⽂件名:(可以加扩展名!如.txt)";
//若输⼊完整路径则在你输⼊的路径下读取⽂件,否则到程序所在位置的⽂件夹中读取    cin>>FileName;
if(FileName.find (".")>FileName.length())
{
FileName=FileName+".txt";
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。