日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網(wǎng)站首頁 編程語言 正文

C++實現(xiàn)寵物商店信息管理系統(tǒng)_C 語言

作者:陸鳴笙 ? 更新時間: 2022-05-21 編程語言

本文實例為大家分享了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

欄目分類
最近更新