網(wǎng)站首頁 編程語言 正文
本文實例為大家分享了C++實現(xiàn)寵物商店信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、問題描述
設(shè)計一個程序?qū)崿F(xiàn)對小動物商店的簡單管理,主要功能:寵物基本信息(編號,名稱,體重, 年齡,類別,價格,性格等)的輸入、顯示、查詢等功能;寵物的交易、狀態(tài)及顧客(寵物主人)的記錄查詢和修改。
二、基本要求
(1)使用面向?qū)ο笏枷腴_發(fā)需要的類,比如:寵物類包含寵物的基本屬性信息和基本操作,日期類記錄交易日期,顧客類記錄顧客的信息;管理類,實現(xiàn)對寵物情況的操作;輸入和輸出的操作要求對輸出運算符“>>”和輸出運算符“<<”進行重載
(2)輸入和輸出可以使用文本文件重定向輸入(保存數(shù)據(jù)為磁盤文件);也可以使用標準輸入輸出進行(提交時需要提交TXT格式輸入數(shù)據(jù))。程序運行時進行初始化數(shù)據(jù),使用vector數(shù)組存放。交易數(shù)據(jù)記錄交易的日期、寵物名稱、寵物類別、顧客姓名、交易金額等,有6條以上記錄。
(3)運行后使用菜單功能顯示所有寵物信息,根據(jù)類別顯示記錄,根據(jù)名稱查詢記錄,添加( 購入) 寵物,刪除(賣出)寵物,交易記錄,按日期查詢交易記錄。
系統(tǒng)流程圖
源代碼
#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()指鏈表結(jié)尾處 do{ ? ? cout<<"【請輸入寵物相關(guān)信息!】"< >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))//假設(shè)寵物可以重名 ? ? ? ? ?{ ? ? ? ? ? ? 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型的字符串轉(zhuǎn)換成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(":");//要":"后的內(nèi)容? ?? ??? ??? ?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)//選擇不同函數(shù)功能? ?? ?{ ?? ??? ?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; }
原文鏈接:https://blog.csdn.net/cjl1831050185/article/details/109230806
相關(guān)推薦
- 2022-04-19 在html中src和href的區(qū)別,以及img中的srcset的作用是什么?
- 2022-07-16 TritonObjDet新增要素的方法
- 2022-04-08 關(guān)于C++11中限定作用域的枚舉類型的問題_C 語言
- 2022-07-19 RPM命令和YUM命令用法
- 2022-08-18 Redis7.0部署集群的實現(xiàn)步驟_Redis
- 2022-11-17 python實現(xiàn)excel轉(zhuǎn)置問題詳解_python
- 2022-02-13 React中插入視頻(video-react),自動播放
- 2022-12-29 React點擊事件的兩種寫法小結(jié)_React
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支