千家信息网

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

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章将为大家详细讲解有关如何使用C++实现宠物商店信息管理系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。具体内容如下一、问题描述设计一个程序实现对小动物商店
千家信息网最后更新 2026年10月31日如何使用C++实现宠物商店信息管理系统

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

具体内容如下

一、问题描述

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

二、基本要求

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

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

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

系统流程图

源代码

#include #include#include#include#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<<"请输入日期(格式年-月-日)"<>year>>c1>>month>>c2>>day;          if(c1!='-'||c2!='-')              cout<<"格式不正确,请重新输入"<PetList;//使用双向链表//添加宠物信息void PetAnimals::Insert(){    PetAnimals Pet;    char ch;    int symbol=0;//判断宠物信息是否存在    list::iterator first,last;    first=PetList.begin();//begin()指链表开始处    last=PetList.end();//end()指链表结尾处do{    cout<<"【请输入宠物相关信息!】"<>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<>ch;    }while(ch=='Y'||ch=='y'); }//查找宠物信息bool PetAnimals::Look(){    string name,price,type;    int symbol=0;    int option;    list ::iterator first,last; do  {     cout<<"\t【请输入你查找的方式】!"<>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+"宠物信息如下:"<>name;    cout<<"请输入价格:";    cin>>price;    cout<<"请输入种类:";    cin>>type;    list ::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<>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 ::iterator first,last,it;    first=PetList.begin();    last=PetList.end();    for(;first!=last;++first)    {        cout<<"******************您的宠物信息**********************"<>name;    cout<<"请输入价格:";    cin>>price;    cout<<"请输入种类:";    cin>>type;    list ::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<<"★找到该宠物信息!可删除!"<>FileName;    if(FileName.find (".")>FileName.length())     {        FileName=FileName+".txt";     }     //把String型的字符串转换成char*型的字符串    strcpy(file,FileName.c_str());    ofstream fout(file);    if(!fout)     {        cout<<"★文件写入失败!请检查您的文件名!"<::iterator first,last;        first=PetList.begin();        last=PetList.end();        for(;first!=last;++first)         {            fout<>FileName;    if(FileName.find (".")>FileName.length())     {        FileName=FileName+".txt";     }        strcpy(file,FileName.c_str());        ifstream fin(file);        int index;    if(!fin)     {        cout<<"★文件写入失败!请检查您的文件名!"<>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"<<"   ★请保护好您的爱宠哦(^。^*)!★ "<>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++实现宠物商店信息管理系统"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

宠物 信息 名称 文件 价格 种类 输入 主人 年龄 性格 重量 交易 日期 系统 管理 输出 商店 功能 数据 顾客 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技 与互联网科技公司 西安互联网科技公司 互联网高科技企业 互联网科技咨询 科技大学互联网专业好不好 湖南洣水互联网科技有限公司扣款 北京大学互联网科技怎么样 湖北码尼互联网科技有限公司电话 互联网科技扶贫时间 明优互联网科技有限公司 互联网科技大赛获奖感言 中科明德北京互联网科技 2021互联网科技公司排名 互联网金融科技元年 图游互联网科技 新氧科技和美国互联网有关系吗 广东鹅鹅鹅互联网科技有限公司 互联网金融运营模式中的金融科技 长沙渺峰互联网科技有限公司 广州为想互联网科技有限公司 互联网金融 科技金融 互联网科技咨询 北京大学互联网科技怎么样 昭通云南众福互联网科技有限公司 伊宁互联网科技做什么的 山东星卡互联网科技有限公司官网 互联网相关科技技术 科技互联网专业务虚会材料 互联网科技自媒体灵感
0