欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++實(shí)現(xiàn)圖書信息管理系統(tǒng)

 更新時(shí)間:2022年03月12日 11:17:02   作者:ōu?yǐng  
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)圖書信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C++實(shí)現(xiàn)圖書信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

1.題目:

類型有:編號(hào):ISBN
書名:name
價(jià)格:price

完成如下的功能:

①錄入:從鍵盤輸入(或從文件讀入)圖書(或?qū)W生)信息表的各個(gè)數(shù)據(jù)元素;
②查找:可按不同屬性查找所有等于給定值的數(shù)據(jù)元素,找到并返回它們?cè)诒碇械奈恍颍?br />③插入:在表中第i(1=<i<=N+1)個(gè)位置插入一個(gè)新元素;
④刪除:可刪除表中第i(1=<i<=N)個(gè)位置上的元素;
⑤輸出:依次打印表中的各個(gè)元素的值;
⑥排序:可按某屬性對(duì)表中的元素進(jìn)行排序。(可選)

2.實(shí)現(xiàn)方式:單鏈表(帶頭節(jié)點(diǎn))

3.代碼實(shí)現(xiàn):

#include <iostream>
#include <string>
using namespace std;

struct Node
{
? ? int ISBN;//編號(hào)
? ? string name;//書名
? ? float price;//定價(jià)
? ? Node *next;
};

//操作類
class Link
{
private:
? ? int number;//圖書數(shù)量
? ? Node *head;
public:
? ? Link(int a):number(a){}
? ? ~Link(){delete head;}
? ? void create_node();//創(chuàng)建
? ? void select();//功能選擇
? ? int find_node(int i);//按照編號(hào)查找
? ? int find_node(string n);//按照書名查找
? ? int find_node(float p);//按照價(jià)格查找
? ? int insert_node(int pos);//插入
? ? int delete_node(int d);//刪除
? ? int mod_node(int d);//修改
? ? void sort_node_ISBN();//按照編號(hào)排序
? ? void sort_node_price();//按照價(jià)格排序
? ? int get_node();//計(jì)數(shù)總數(shù)
? ? void print();//打印操作
};

void Link::create_node()
{
? ? Node *pnew;
? ? head = new Node;
? ? //cout<<"請(qǐng)按順序輸入圖書的ISBN,書名,定價(jià)";
? ? head->ISBN = 0;
? ? head->name = 'n';
? ? head->price = 0;
? ? head->next = NULL;
? ? Node *ptemp = head;
? ? for(int i=0;i<number;i++)
? ? {
? ? ? ? pnew = new Node;
? ? ? ? cout<<endl;
? ? ? ? cout<<"請(qǐng)按順序輸入圖書的ISBN,書名,定價(jià):";
? ? ? ? cin>>pnew->ISBN>>pnew->name>>pnew->price;
? ? ? ? pnew->next = NULL;
? ? ? ? ptemp->next = pnew;
? ? ? ? ptemp = pnew;
? ? }
}

//按編號(hào)查找
int Link::find_node(int i)
{
? ? Node *ptemp = head->next;
? ? for(int count = 0;count<number;count++)
? ? ? ? {
? ? ? ? ? ? if(ptemp->ISBN == i)//按編號(hào)查找圖書
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout<<"圖書的編號(hào)為:"<<ptemp->ISBN<<" ? ? 書名為:"<<ptemp->name<<" ? ? ? 定價(jià)為:"<<ptemp->price<<endl;
? ? ? ? ? ? ? ? return 1;
? ? ? ? ? ? }
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? return 0;
}

//按照書名查找
int Link::find_node(string n)
{
? ? Node *ptemp = head->next;
? ? for(int count=0;count<number;count++)
? ? ? ? {
? ? ? ? ? ? if(ptemp->name == n)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout<<"圖書的編號(hào)為:"<<ptemp->ISBN<<" ? ? 書名為:"<<ptemp->name<<" ? ? ? 定價(jià)為:"<<ptemp->price<<endl;
? ? ? ? ? ? ? ? return 1;
? ? ? ? ? ? }
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? return 0;
}

//按照價(jià)格查找
int Link::find_node(float p)
{
? ? Node *ptemp = head->next;
? ? for(int count=0;count<number;count++)
? ? ? ? {
? ? ? ? ? ? if(ptemp->price == p)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout<<"圖書的編號(hào)為:"<<ptemp->ISBN<<" ? ? 書名為:"<<ptemp->name<<" ? ? ? 定價(jià)為:"<<ptemp->price<<endl;
? ? ? ? ? ? ? ? return 1;
? ? ? ? ? ? }
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? return 0;
}

//插入
int Link::insert_node(int pos)
{
? ? if((pos > number)||(pos<0))
? ? {
? ? ? ? cout<<"插入位置錯(cuò)誤!"<<endl;
? ? ? ? return 0;
? ? }
? ? else
? ? {
? ? ? ? Node *ptemp = head,*pnew;
? ? ? ? for(int i=0;i<pos-1;i++)
? ? ? ? {
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? pnew = new Node;
? ? ? ? cout<<"請(qǐng)按順序輸入圖書的ISBN,書名,價(jià)格:";
? ? ? ? cin>>pnew->ISBN>>pnew->name>>pnew->price;
? ? ? ? pnew->next = ptemp->next;
? ? ? ? ptemp->next = pnew;
? ? ? ? number += 1;
? ? }
? ? return 1;

}

//刪除
int Link::delete_node(int d)
{
? ? if((d > number)||(d<0))
? ? {
? ? ? ? cout<<"刪除位置錯(cuò)誤!"<<endl;
? ? ? ? return 0;
? ? }
? ? else
? ? {
? ? ? ? Node *ptemp = head,*pdelete;
? ? ? ? for(int i=0;i<d-1;i++)
? ? ? ? {
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? pdelete = ptemp->next;
? ? ? ? ptemp->next = pdelete->next;
? ? ? ? delete pdelete;
? ? ? ? number -= 1;
? ? }
? ? return 1;
}

//修改
int Link::mod_node(int d)
{
? ? int aa;
? ? string bb;
? ? float cc;
? ? if((d > number)||(d<0))
? ? {
? ? ? ? cout<<"要修改的位置錯(cuò)誤!"<<endl;
? ? ? ? return 0;
? ? }
? ? else
? ? {
? ? ? ? Node *ptemp = head->next;
? ? ? ? for(int i=0;i<d-1;i++)
? ? ? ? {
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? cout<<"要修改編號(hào)請(qǐng)輸入0,要修改書名請(qǐng)輸入1,要修改價(jià)格請(qǐng)輸入2:";
? ? ? ? int k;
? ? ? ? cin>>k;
? ? ? ? switch(k)
? ? ? ? {
? ? ? ? case 0:
? ? ? ? ? ? cout<<"請(qǐng)輸入要修改的編號(hào):";
? ? ? ? ? ? cin>>aa;
? ? ? ? ? ? ptemp->ISBN = aa;
? ? ? ? ? ? cout<<endl;
? ? ? ? ? ? break;
? ? ? ? case 1:
? ? ? ? ? ? cout<<"請(qǐng)輸入要更改的書名:";
? ? ? ? ? ? cin>>bb;
? ? ? ? ? ? ptemp->name = bb;
? ? ? ? ? ? cout<<endl;
? ? ? ? ? ? break;
? ? ? ? case 2:
? ? ? ? ? ? cout<<"請(qǐng)輸入要更改的價(jià)格:";
? ? ? ? ? ? cin>>cc;
? ? ? ? ? ? ptemp->price = cc;
? ? ? ? ? ? cout<<endl;
? ? ? ? ? ? break;
? ? ? ? }
? ? }
? ? return 1;
}

//按編號(hào)排序
void Link::sort_node_ISBN()
{
? ? Node *ptemp = head->next,*pre;
? ? Node *pr = ptemp->next;
? ? ptemp->next = NULL;
? ? ptemp = pr;
? ? while(ptemp != NULL)
? ? {
? ? ? ? pr = ptemp->next;
? ? ? ? pre = head;
? ? ? ? while(pre->next != NULL && pre->next->ISBN > ptemp->ISBN)
? ? ? ? {
? ? ? ? ? ? pre = pre->next;
? ? ? ? }
? ? ? ? ptemp->next = pre->next;
? ? ? ? pre->next = ptemp;
? ? ? ? ptemp = pr;
? ? }
? ? Link::print();
}

//按照價(jià)格排序
void Link::sort_node_price()
{
? ? Node *ptemp = head->next,*pre;
? ? Node *pr = ptemp->next;
? ? ptemp->next = NULL;
? ? ptemp = pr;
? ? while(ptemp != NULL)
? ? {
? ? ? ? pr = ptemp->next;
? ? ? ? pre = head;
? ? ? ? while(pre->next != NULL && pre->next->price > ptemp->price)
? ? ? ? {
? ? ? ? ? ? pre = pre->next;
? ? ? ? }
? ? ? ? ptemp->next = pre->next;
? ? ? ? pre->next = ptemp;
? ? ? ? ptemp = pr;
? ? }
? ? ?Link::print();
}

//獲取長(zhǎng)度
int Link::get_node()
{
? ? return number;
}

//打印輸出
void Link::print()
{
? ? Node *ptemp = head->next;
? ? for(int k=0;k<number;k++)
? ? {
? ? ? ? cout<<"圖書編號(hào):"<<ptemp->ISBN<<" ? ? ? 書名為:"<<ptemp->name<<" ? ? ? 價(jià)格為:"<<ptemp->price<<endl;
? ? ? ? ptemp = ptemp->next;
? ? }
}

//功能函數(shù)
void Link::select()
{
? ? int a;//ISBN
? ? string b;//書名
? ? float c;//定價(jià)
? ? int d;//位置
? ? int p;//選擇功能
? ? cin>>p;
? ? switch(p)
? ? {
? ? case 0:
? ? ? ? cout<<"請(qǐng)輸入圖書的編號(hào)";
? ? ? ? cin>>a;
? ? ? ? if(this->find_node(a))
? ? ? ? {
? ? ? ? ? ? cout<<endl;
? ? ? ? }
? ? ? ? else
? ? ? ? ? ? cout<<"該圖書不存在!"<<endl;
? ? ? ? break;
? ? case 1:
? ? ? ? cout<<"請(qǐng)輸入圖書的名字:";
? ? ? ? cin>>b;
? ? ? ? if(this->find_node(b))
? ? ? ? {
? ? ? ? ? ? cout<<endl;
? ? ? ? }
? ? ? ? else
? ? ? ? ? ? cout<<"該圖書不存在!"<<endl;
? ? ? ? break;
? ? case 2:
? ? ? ? cout<<"請(qǐng)輸入圖書的價(jià)格:";
? ? ? ? cin>>c;
? ? ? ? if(this->find_node(c))
? ? ? ? {
? ? ? ? ? ? cout<<endl;
? ? ? ? }
? ? ? ? else
? ? ? ? ? ? cout<<"該圖書不存在!"<<endl;
? ? ? ? break;
? ? case 3:
? ? ? ? cout<<"請(qǐng)輸入要插入的位置:";
? ? ? ? cin>>d;
? ? ? ? if(this->insert_node(d))
? ? ? ? {
? ? ? ? ? ? cout<<"插入操作的結(jié)果為:"<<endl;
? ? ? ? ? ? this->print();//打印插入結(jié)果
? ? ? ? }
? ? ? ? break;
? ? case 4:
? ? ? ? cout<<"請(qǐng)輸入要?jiǎng)h除的位置:";
? ? ? ? cin>>d;
? ? ? ? if(this->delete_node(d))
? ? ? ? {
? ? ? ? ? ? cout<<"刪除操作的結(jié)果為:"<<endl;
? ? ? ? ? ? this->print();//打印插入結(jié)果
? ? ? ? }
? ? ? ? break;
? ? case 5:
? ? ? ? cout<<"請(qǐng)輸入要修改的圖書的位置:";
? ? ? ? cin>>d;
? ? ? ? if(this->mod_node(d))
? ? ? ? {
? ? ? ? ? ? cout<<"修改后的結(jié)果為:"<<endl;
? ? ? ? ? ? this->print();
? ? ? ? }
? ? ? ? break;
? ? case 6:
? ? ? ? cout<<"按照?qǐng)D書的編號(hào)進(jìn)行排序的結(jié)果為:"<<endl;
? ? ? ? this->sort_node_ISBN();
? ? ? ? break;
? ? case 7:
? ? ? ? cout<<"按照?qǐng)D書的價(jià)格進(jìn)行排序的結(jié)果為:"<<endl;
? ? ? ? this->sort_node_price();
? ? ? ? break;
? ? case 8:
? ? ? ? cout<<"當(dāng)前館內(nèi)的圖書數(shù)量為:";
? ? ? ? cout<<this->get_node();
? ? ? ? break;
? ? }
}


int main()
{
? ? int sele=1;//功能選擇
? ? int i;//最開始的數(shù)量
? ? cout<<"請(qǐng)輸入你要輸入的圖書的數(shù)量:";
? ? cin>>i;
? ? Link l(i);
? ? l.create_node();
? ? cout<<endl;
? ? cout<<"0---------------------為查找(按編號(hào))"<<endl;
? ? cout<<"1---------------------為查找(按書名)"<<endl;
? ? cout<<"2---------------------為查找(按定價(jià))"<<endl;
? ? cout<<"3---------------------為插入"<<endl;
? ? cout<<"4---------------------為刪除"<<endl;
? ? cout<<"5---------------------為修改"<<endl;
? ? cout<<"6---------------------為按照?qǐng)D書編號(hào)排序"<<endl;
? ? cout<<"7---------------------為按照?qǐng)D書的價(jià)格排序"<<endl;
? ? cout<<"8---------------------為顯示當(dāng)前館內(nèi)的圖書總數(shù)"<<endl;
? ? cout<<"請(qǐng)輸入要選擇的功能:";
? ? while(sele == 1)
? ? {
? ? ? ? l.select();
? ? ? ? cout<<"是否要退出管理系統(tǒng)?(輸入0退出、輸入1繼續(xù))";
? ? ? ? cin>>sele;
? ? ? ? cout<<"請(qǐng)輸入要選擇的功能:";
? ? }
? ? cout<<"-----------已退出圖書管理系統(tǒng)------------";
? ? return 0;
}

4.效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 利用C++11原子量如何實(shí)現(xiàn)自旋鎖詳解

    利用C++11原子量如何實(shí)現(xiàn)自旋鎖詳解

    當(dāng)自旋鎖嘗試獲取鎖時(shí)以忙等待(busy waiting)的形式不斷地循環(huán)檢查鎖是否可用,下面這篇文章主要給大家介紹了關(guān)于利用C++11原子量如何實(shí)現(xiàn)自旋鎖的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-06-06
  • 內(nèi)聯(lián)函數(shù)inline與宏定義深入解析

    內(nèi)聯(lián)函數(shù)inline與宏定義深入解析

    類的內(nèi)斂函數(shù)是一個(gè)真正的函數(shù)。使用內(nèi)聯(lián)函數(shù)inline可以完全取代表達(dá)式形式的宏定義
    2013-09-09
  • C++使用鏈表存儲(chǔ)實(shí)現(xiàn)通訊錄功能管理

    C++使用鏈表存儲(chǔ)實(shí)現(xiàn)通訊錄功能管理

    這篇文章主要為大家詳細(xì)介紹了C++使用鏈表存儲(chǔ)實(shí)現(xiàn)通訊錄功能管理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • 淺談C++內(nèi)存管理基礎(chǔ)知識(shí)

    淺談C++內(nèi)存管理基礎(chǔ)知識(shí)

    這篇文章主要為大家介紹了C++的內(nèi)存管理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • C++深入探究list的模擬實(shí)現(xiàn)

    C++深入探究list的模擬實(shí)現(xiàn)

    list相較于vector來(lái)說(shuō)會(huì)顯得復(fù)雜,它的好處是在任意位置插入,刪除都是一個(gè)O(1)的時(shí)間復(fù)雜度,本文主要介紹了C++中List的模擬實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • 基于QT的TCP通信服務(wù)的實(shí)現(xiàn)

    基于QT的TCP通信服務(wù)的實(shí)現(xiàn)

    在項(xiàng)目開發(fā)過(guò)程中,很多地方都會(huì)用到TCP通信,本文主要介紹了基于QT的TCP通信服務(wù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • C++運(yùn)算符重載與多繼承及二義性詳解

    C++運(yùn)算符重載與多繼承及二義性詳解

    繼友元知識(shí)過(guò)后,就到了今天的C++運(yùn)算符重載的內(nèi)容了,運(yùn)算符重載是C++里比較重要的內(nèi)容。這篇博文不會(huì)一下子講完各種運(yùn)算符重載,因?yàn)樘嗔肆艘膊缓梦照莆?,所以運(yùn)算符重載我準(zhǔn)備分多次記錄和分享,那么接下來(lái)進(jìn)入正文
    2022-11-11
  • C語(yǔ)言編程中分配內(nèi)存空間的相關(guān)函數(shù)

    C語(yǔ)言編程中分配內(nèi)存空間的相關(guān)函數(shù)

    這篇文章主要介紹了C語(yǔ)言編程中分配內(nèi)存空間的相關(guān)函數(shù),分別是malloc()函數(shù)和calloc()函數(shù),需要的朋友可以參考下
    2015-08-08
  • Qt控件之QToolButton的使用及示例

    Qt控件之QToolButton的使用及示例

    QToolButton類提供了一個(gè)快速訪問(wèn)命令或選項(xiàng)的按鈕,通常在QToolBar內(nèi)部使用,本文主要介紹了Qt控件之QToolButton的使用及示例,感興趣的可以了解一下
    2023-10-10
  • C語(yǔ)言并查集的非遞歸實(shí)現(xiàn)詳解

    C語(yǔ)言并查集的非遞歸實(shí)現(xiàn)詳解

    以下是對(duì)C語(yǔ)言并查集的遞歸實(shí)現(xiàn)與非遞歸實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望能夠給你帶來(lái)幫助
    2021-09-09

最新評(píng)論