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

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

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

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

1.題目:

類型有:編號:ISBN
書名:name
價格:price

完成如下的功能:

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

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

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

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

struct Node
{
? ? int ISBN;//編號
? ? string name;//書名
? ? float price;//定價
? ? 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);//按照編號查找
? ? int find_node(string n);//按照書名查找
? ? int find_node(float p);//按照價格查找
? ? int insert_node(int pos);//插入
? ? int delete_node(int d);//刪除
? ? int mod_node(int d);//修改
? ? void sort_node_ISBN();//按照編號排序
? ? void sort_node_price();//按照價格排序
? ? int get_node();//計數(shù)總數(shù)
? ? void print();//打印操作
};

void Link::create_node()
{
? ? Node *pnew;
? ? head = new Node;
? ? //cout<<"請按順序輸入圖書的ISBN,書名,定價";
? ? 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<<"請按順序輸入圖書的ISBN,書名,定價:";
? ? ? ? cin>>pnew->ISBN>>pnew->name>>pnew->price;
? ? ? ? pnew->next = NULL;
? ? ? ? ptemp->next = pnew;
? ? ? ? ptemp = pnew;
? ? }
}

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

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

//插入
int Link::insert_node(int pos)
{
? ? if((pos > number)||(pos<0))
? ? {
? ? ? ? cout<<"插入位置錯誤!"<<endl;
? ? ? ? return 0;
? ? }
? ? else
? ? {
? ? ? ? Node *ptemp = head,*pnew;
? ? ? ? for(int i=0;i<pos-1;i++)
? ? ? ? {
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? pnew = new Node;
? ? ? ? cout<<"請按順序輸入圖書的ISBN,書名,價格:";
? ? ? ? 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<<"刪除位置錯誤!"<<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<<"要修改的位置錯誤!"<<endl;
? ? ? ? return 0;
? ? }
? ? else
? ? {
? ? ? ? Node *ptemp = head->next;
? ? ? ? for(int i=0;i<d-1;i++)
? ? ? ? {
? ? ? ? ? ? ptemp = ptemp->next;
? ? ? ? }
? ? ? ? cout<<"要修改編號請輸入0,要修改書名請輸入1,要修改價格請輸入2:";
? ? ? ? int k;
? ? ? ? cin>>k;
? ? ? ? switch(k)
? ? ? ? {
? ? ? ? case 0:
? ? ? ? ? ? cout<<"請輸入要修改的編號:";
? ? ? ? ? ? cin>>aa;
? ? ? ? ? ? ptemp->ISBN = aa;
? ? ? ? ? ? cout<<endl;
? ? ? ? ? ? break;
? ? ? ? case 1:
? ? ? ? ? ? cout<<"請輸入要更改的書名:";
? ? ? ? ? ? cin>>bb;
? ? ? ? ? ? ptemp->name = bb;
? ? ? ? ? ? cout<<endl;
? ? ? ? ? ? break;
? ? ? ? case 2:
? ? ? ? ? ? cout<<"請輸入要更改的價格:";
? ? ? ? ? ? cin>>cc;
? ? ? ? ? ? ptemp->price = cc;
? ? ? ? ? ? cout<<endl;
? ? ? ? ? ? break;
? ? ? ? }
? ? }
? ? return 1;
}

//按編號排序
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();
}

//按照價格排序
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();
}

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

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

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


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

4.效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

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

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

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

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

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

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

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

    淺談C++內存管理基礎知識

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

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

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

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

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

    C++運算符重載與多繼承及二義性詳解

    繼友元知識過后,就到了今天的C++運算符重載的內容了,運算符重載是C++里比較重要的內容。這篇博文不會一下子講完各種運算符重載,因為太多了了也不好吸收掌握,所以運算符重載我準備分多次記錄和分享,那么接下來進入正文
    2022-11-11
  • C語言編程中分配內存空間的相關函數(shù)

    C語言編程中分配內存空間的相關函數(shù)

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

    Qt控件之QToolButton的使用及示例

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

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

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

最新評論