教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 幼儿教育 >

宠物店管理系统

来源:网络收集 时间:2026-07-16
导读: c++实训实例 ///宠物店信息管理系统 ///功能:使用菜单实现对宠物信息的检索、增加、修改、删除、显示和存取等功能 ///关键实现:使用C++模板类中的链表(list)类操作,链表节点值是Cpet类型, //包括宠物昵称(关键字)、性别、种类、性格、价格等 ///注意:

c++实训实例

///宠物店信息管理系统

///功能:使用菜单实现对宠物信息的检索、增加、修改、删除、显示和存取等功能 ///关键实现:使用C++模板类中的链表(list)类操作,链表节点值是Cpet类型, //包括宠物昵称(关键字)、性别、种类、性格、价格等

///注意:保存的文件类型建议为txt文件,这样便可以方便用记事本打开看,也可以为dat型,测试的时候可以直接在记事本中添加信息,

//但最后一行不能有回车,否则读文件的时候会认为是新的数据,会多读出来一个空白节点

#include"iostream"//C++标准输入输出头文件

#include"list"//链表类头文件

#include"string"

#include"vector"//容器类头文件

#include"fstream"//文件读写头文件

using namespace std;//标准命名空间

///////////// the core: Class //////////////////////

class Cpet{

public:

//构造函数,对类对象进行初始化,重载了两个构造函数:带参数和不带参数的

Cpet(){} Cpet(string Name,string Sex,string Species,string Character,string Price) { Cname=Name;//宠物昵称:keke,lele or 老宁,you define it! } Csex=Sex;//宠物性别:male or female Cspecies=Species;//宠物种类:cat or dog,and so on Ccharacter=Character;//宠物性格:meek,rabid Cprice=Price;//宠物价格:1000 void Insert();//添加宠物信息 bool Search();//查找宠物信息 bool Change();//修改宠物信息 void Display();//显示宠物信息 bool Delete();//删除宠物信息 void Read();//读入宠物信息文件 void Write();//写出宠物信息文件

private:

string Cname;

string Csex; string Cspecies;

string Ccharacter;

string Cprice;

};

c++实训实例

list<Cpet>PetList;//使用模板库中的双向链表

//////////添加宠物信息////////////

void Cpet::Insert()

{

Cpet Pet;//定义节点类一对象(宠物),很重要哦!

char ch_judge; int flag=0;//标记,用于判断宠物信息是否存在 list<Cpet>::iterator first,last;//迭代器指针,用于遍历链表,关于链表请你详细看first=PetList.begin(); last=PetList.end();//begin()指链表开始处,end()指链表结尾处 do{ cout<<"请输入宠物信息>>"<<endl; cout<<"昵称:"; cin>>http://www.77cn.com.cname; cout<<"性别:"; cin>>Pet.Csex; cout<<"种类:"; cin>>Pet.Cspecies; cout<<"性格:"; cin>>http://www.77cn.com.cnharacter; cout<<"价格:"; cin>>Pet.Cprice; for(;first!=last;++first) { 一下数据结构的书籍,不懂的也可以问我 //假设宠物可以重名,但重名不同性别,若同性别同名但不同种类 if((http://www.77cn.com.cname==(*first).Cname)&&(Pet.Csex==(*first).Csex)&&(Pet.Cspecies==(*first).Cspecies))

{

} } flag=1;//设置存在标志 cout<<endl<<"该宠物已经存在!"<<endl; cout<<"昵称:"<<(*first).Cname<<endl; cout<<"性别:"<<(*first).Csex<<endl; cout<<"种类:"<<(*first).Cspecies<<endl; cout<<"性格:"<<(*first).Ccharacter<<endl; cout<<"价格:"<<(*first).Cprice<<endl; if(flag==0)//如果不存在 {

c++实训实例

}

} cout<<endl<<"继续添加宠物信息[Y/N]?"; cin>>ch_judge; }while(ch_judge=='Y'||ch_judge=='y');

//////////查找宠物信息//////////////////

bool Cpet::Search()

{

string name,sex,species; int flag=0; int select; list <Cpet>::iterator first,last; do{ cout<<"\t请输入你查找的方式!"<<endl; cout<<"\t1.按昵称查找"<<endl; cout<<"\t2.按性别查找"<<endl; cout<<"\t3.按种类查找"<<endl; cout<<"\t4.退出!"<<endl; cin>>select; switch(select) { case 1: cout<<"请输入姓名:"; cin>>name; break; case 2: cout<<"请输入性别:"; cin>>sex; break; case 3: cout<<"请输入种类:"; cin>>species; break; case 4:break; } first=PetList.begin(); last=PetList.end(); for(;first!=last;++first) { if((name==(*first).Cname)&&(select==1)) { flag=1;

c++实训实例

} cout<<"昵称:"+(*first).Cname<<endl; cout<<"性别:"+(*first).Csex<<endl; cout<<"种类:"+(*first).Cspecies<<endl; cout<<"性格:"+(*first).Ccharacter<<endl; cout<<"价格:"+(*first).Cprice<<endl; } if((sex==(*first).Csex)&&(select==2)) { flag=1; cout<<"宠物性别为"+(*first).Csex+"宠物信息如下>>"<<endl; cout<<"昵称:"+(*first).Cname<<endl; cout<<"性别:"+(*first).Csex<<endl; cout<<"种类:"+(*first).Cspecies<<endl; cout<<"性格:"+(*first).Ccharacter<<endl; cout<<"价格:"+(*first).Cprice<<endl; } if((species==(*first).Cspecies)&&(select==3)) { flag=1; cout<<"宠物种类为"+(*first).Cspecies+"宠物信息如下>>"<<endl; cout<<"昵称:"+(*first).Cname<<endl; cout<<"性别:"+(*first).Csex<<endl; cout<<"种类:"+(*first).Cspecies<<endl; cout<<"性格:"+(*first).Ccharacter<<endl; cout<<"价格:"+(*first).Cprice<<endl; }

}while(select!=4);

if((first==last)&&(flag==0))

}

///////////修改宠物资料//////////////

bool Cpet::Change()

{

Cpet pet; string name,sex,species; int flag=0; cout<<"请输入昵称:"; cin>>name; {cout<<"无该宠物信息!";return false;} else return true;

c++实训实例

cin>>sex; cout<<"请输入种类:"; cin>>species; li …… 此处隐藏:5517字,全部文档内容请下载后查看。喜欢就下载吧 ……

宠物店管理系统.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1528684.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)