iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >如何使用C++实现宠物商店信息管理系统
  • 165
分享到

如何使用C++实现宠物商店信息管理系统

2023-06-29 12:06:44 165人浏览 安东尼
摘要

这篇文章将为大家详细讲解有关如何使用c++实现宠物商店信息管理系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。具体内容如下一、问题描述设计一个程序实现对小动物商店的简单管理,主要功能:宠物基本信息(编号

这篇文章将为大家详细讲解有关如何使用c++实现宠物商店信息管理系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

具体内容如下

一、问题描述

设计一个程序实现对小动物商店的简单管理,主要功能:宠物基本信息(编号,名称,体重, 年龄,类别,价格,性格等)的输入、显示、查询等功能;宠物的交易、状态及顾客(宠物主人)的记录查询和修改。

二、基本要求

(1)使用面向对象思想开发需要的类,比如:宠物类包含宠物的基本属性信息和基本操作,日期类记录交易日期,顾客类记录顾客的信息;管理类,实现对宠物情况的操作;输入和输出的操作要求对输出运算符“>>”和输出运算符“<<”进行重载

(2)输入和输出可以使用文本文件重定向输入(保存数据为磁盘文件);也可以使用标准输入输出进行(提交时需要提交TXT格式输入数据)。程序运行时进行初始化数据,使用vector数组存放。交易数据记录交易的日期、宠物名称、宠物类别、顾客姓名、交易金额等,有6条以上记录。

(3)运行后使用菜单功能显示所有宠物信息,根据类别显示记录,根据名称查询记录,添加( 购入) 宠物,删除(卖出)宠物,交易记录,按日期查询交易记录。

系统流程图

如何使用C++实现宠物商店信息管理系统

源代码

#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 or dog...     Cnature=Nature;//宠物性格:clver,ferocious...    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()指链表开始处    last=PetList.end();//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";     }     //把String型的字符串转换成char*型的字符串    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++实现宠物商店信息管理系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

--结束END--

本文标题: 如何使用C++实现宠物商店信息管理系统

本文链接: https://www.lsjlt.com/news/325059.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何使用C++实现宠物商店信息管理系统
    这篇文章将为大家详细讲解有关如何使用C++实现宠物商店信息管理系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。具体内容如下一、问题描述设计一个程序实现对小动物商店的简单管理,主要功能:宠物基本信息(编号...
    99+
    2023-06-29
  • C++实现宠物商店信息管理系统
    本文实例为大家分享了C++实现宠物商店信息管理系统的具体代码,供大家参考,具体内容如下 一、问题描述 设计一个程序实现对小动物商店的简单管理,主要功能:宠物基本信息(编号,名称,体重...
    99+
    2024-04-02
  • 如何使用C++实现信息管理系统
    小编给大家分享一下如何使用C++实现信息管理系统,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!具体内容如下有一个信息管理系统,要求检查每一个登录系统的用户(Use...
    99+
    2023-06-29
  • 如何使用C++实现图书信息管理系统
    小编给大家分享一下如何使用C++实现图书信息管理系统,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!具体内容如下1.题目:类型有:编号:ISBN书名:name价格:price完成如下的功能:①录入:从键盘输入(或从文件读入)...
    99+
    2023-06-29
  • C++实现商店仓库管理系统
    本文实例为大家分享了C++实现商店仓库管理系统的具体代码,供大家参考,具体内容如下 一、问题描述 系统应具有下列主要功能:输入记录功能:从键盘输入货物信息:商品代号,商品名称, 数量...
    99+
    2024-04-02
  • 如何使用C++实现酒店管理系统
    这篇文章主要介绍了如何使用C++实现酒店管理系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。现今大多数宾馆所提供的服务样式都各式各样,规模大小也是各有不同,但是归总下来,不...
    99+
    2023-06-29
  • C++实现信息管理系统
    本文实例为大家分享了C++实现信息管理系统的具体代码,供大家参考,具体内容如下 有一个信息管理系统,要求检查每一个登录系统的用户(User)的用户名和口令,系统检查合格以后方可登录系...
    99+
    2024-04-02
  • 如何使用C++实现教职工信息管理系统
    这篇文章主要介绍如何使用C++实现教职工信息管理系统,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!具体内容如下一.问题描述一个小公司包含四类人员:经理,技术人员,销售人员和销售经理,各类人员的工资计算方法如下:经理:...
    99+
    2023-06-29
  • 基于C++如何实现信息管理系统
    这篇“基于C++如何实现信息管理系统”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“基于C++如何实现信息管理系统”文章吧。使...
    99+
    2023-06-29
  • C++如何实现学生信息管理系统
    本篇内容主要讲解“C++如何实现学生信息管理系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C++如何实现学生信息管理系统”吧!实现功能上面的功能基本完全实现目前的程序其实还存在两个问题:无法...
    99+
    2023-06-30
  • 如何使用C语言实现车辆信息管理系统
    小编给大家分享一下如何使用C语言实现车辆信息管理系统,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!具体内容如下车辆信息管理系统问题描述:建立车辆信息管理系统,实现...
    99+
    2023-06-29
  • Java怎么实现药店信息管理系统
    这篇“Java怎么实现药店信息管理系统”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Java怎么实现药店信息管理系统”文章吧...
    99+
    2023-06-29
  • 如何使用C语言实现超市信息管理系统
    这篇文章主要介绍了如何使用C语言实现超市信息管理系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。具体内容如下设计要求:设计一个超市信息管理系统,利用结构体存储货物信息和所购...
    99+
    2023-06-29
  • C/C++实现图书信息管理系统
    本文实例为大家分享了c/c++实现图书信息管理系统的具体代码,供大家参考,具体内容如下 程序流程图 源代码 #include <stdio.h> #include ...
    99+
    2024-04-02
  • C++实现职工信息管理系统
    本文实例为大家分享了c++实现职工信息管理系统的具体代码,供大家参考,具体内容如下 1、项目需求 2、功能实现的具体思路为: (1) 经行职工信息的读入,用while循环进行读入,...
    99+
    2024-04-02
  • C++实现图书信息管理系统
    本文实例为大家分享了C++实现图书信息管理系统的具体代码,供大家参考,具体内容如下 1.题目: 类型有:编号:ISBN书名:name价格:price 完成如下的功能: ①录入:从键盘...
    99+
    2024-04-02
  • 基于C++实现信息管理系统
    基于c++设计的信息管理系统,供大家参考,具体内容如下 1、使用类+函数实现2、使用STL容器的vector3、fstream的文件存储方式4、xls文件读入 写出5、数据的四大功能...
    99+
    2024-04-02
  • C++实现简单信息管理系统
    本文实例为大家分享了C++实现简单信息管理系统的具体代码,供大家参考,具体内容如下 信息管理系统 因为学校布置了写一个信息管理系统的作业,所以写下了这个信息管理系统,这是用cpp写的...
    99+
    2024-04-02
  • Python如何实现信息管理系统
    本文小编为大家详细介绍“Python如何实现信息管理系统”,内容详细,步骤清晰,细节处理妥当,希望这篇“Python如何实现信息管理系统”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。具体代码如下"&qu...
    99+
    2023-06-30
  • C++如何实现景区旅游信息管理系统
    这篇文章主要介绍C++如何实现景区旅游信息管理系统,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!具体内容如下1 问题描述如今生活水平提高,大家都喜欢在假期中到一个旅游景点参观,在旅游景区中经常听到游客打听从一个景点到...
    99+
    2023-06-29
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作