最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++實現(xiàn)團購訂單管理系統(tǒng)

 更新時間:2022年12月30日 11:06:45   作者:派大星覺得我很聰明  
這篇文章主要為大家詳細(xì)介紹了如何利用C++實現(xiàn)團購訂單管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

項目需求

功能說明

要求編寫一個團購訂單信息管理系統(tǒng)。

系統(tǒng)包含對訂單的添加、查詢、修改、刪除和瀏覽等功能。

系統(tǒng)設(shè)有口令,只有正確輸入口令才能使用該信息管理系統(tǒng)

功能具體說明

菜單的設(shè)計:共設(shè)置6個選項,包括訂單的添加、查詢、修改、刪除、瀏覽和退出。退出系統(tǒng)前菜單是重復(fù)循環(huán)的。

訂單信息的設(shè)計:本案例采用簡化形式,只定義了訂單編號、商品編號、商品單價、商品數(shù)量、收件人姓名等。

添加訂單:添加時訂單的詳細(xì)信息從鍵盤輸入相應(yīng)內(nèi)容。

瀏覽訂單:顯示當(dāng)前訂單的所有信息,要求有格式控制。

查詢訂單:可輸入訂單編號或收件人姓名查詢相應(yīng)訂單。

修改訂單:對特定訂單信息進(jìn)行修改并保存。

刪除訂單:可根據(jù)訂單編號對該訂單進(jìn)行刪除操作。

口令設(shè)置:被設(shè)為一個字符串常量。程序開始運行時,要求通過鍵盤輸入口令。3次輸入不正確,直接結(jié)束程序。

代碼實現(xiàn)

對于訂單設(shè)計的類

class Order

{

public:

       //構(gòu)造函數(shù)

       Order(string oid = "", string sid = "", double sp = 0, int sc = 0, string n 
= "")

       {

              order_num = oid;

              goods_num = sid;

              goods_price = sp;

              goods_count = sc;

              name = n;

       }



       //打印基本信息

       void print()

       {

              cout << "訂單編號:" << setw(N) << order_num << " 商品編號:" << 
setw(N) << goods_num << " 商品價格:"

                     << setw(N) << goods_price << " 商品數(shù)量:" << setw(N) << 
goods_count << " 收件人姓名:" << setw(N) << name << endl;

       }



       //獲得訂單編號

       string getOid()

       {

              return order_num;

       }



       //獲得姓名

       string getName()

       {

              return name;

       }



private:

       string order_num;    //訂單編號

       string goods_num;          //商品編號

       double goods_price;  //商品價格

       int goods_count;           //商品數(shù)量

       string name;         //收件人姓名

};

系統(tǒng)中各個功能的實現(xiàn)

對于系統(tǒng)中的添加,瀏覽,查詢,修改,刪除五項功能分別定義了函數(shù)來實現(xiàn)。

其中的orders是用來保存訂單信息的數(shù)組,index是記錄當(dāng)前數(shù)組位置

void add(Order orders[], int& index)

{

       if (index == MAX)

       {

              cout << "訂單已滿" << endl;

              return;

       }



       string oid;

       string sid;

       double sp;

       int sc;

       string n;

       cout << "請輸入訂單編號:";

       cin >> oid;

       cout << "請輸入商品編號:";

       cin >> sid;

       cout << "請輸入商品價格:";

       cin >> sp;

       cout << "請輸入商品數(shù)量:";

       cin >> sc;

       cout << "請輸入收件人姓名:";

       cin >> n;

       Order o(oid, sid, sp, sc, n);

       orders[index++] = o;

       cout << "添加成功" << endl;

}



void visit(Order orders[], int& index)

{

       cout << "目前共有" << index << "個訂單" << endl;

       for (int i = 0; i < index; i++)

       {

              orders[i].print();

       }

}



void find(Order orders[], int& index)

{

       if (index == 0)

       {

              cout << "訂單為空" << endl;

       }



       int chiose;

       cout << "請選擇查詢方式  1、訂單編號  2、收件人姓名" << endl;

       cin >> chiose;

       if (chiose == 1)

       {

              string oid;

              cout << "請輸入要查詢的訂單編號" << endl;

              cin >> oid;

              for (int i = 0; i < index; i++)

              {

                     if (orders[i].getOid() == oid)

                     {

                           orders[i].print();

                     }

              }

       }

       else if (chiose == 2)

       {

              string name;

              cout << "請輸入要查詢的收件人姓名" << endl;

              cin >> name;

              for (int i = 0; i < index; i++)

              {

                     if (orders[i].getName() == name)

                     {

                           orders[i].print();

                     }

              }

       }

       else

       {

              cout << "錯誤的選擇" << endl;

       }

}



void fixed(Order orders[], int& index)

{

       if (index == 0)

       {

              cout << "訂單為空" << endl;

       }



       string oid;

       cout << "請輸入要修改的訂單編號" << endl;

       cin >> oid;



       bool have = false;

       for (int i = 0; i < index; i++)

       {

              if (orders[i].getOid() == oid)

              {

                     have = true;



                     string oid;

                     string sid;

                     double sp;

                     int sc;

                     string n;

                     cout << "請輸入訂單編號:";

                     cin >> oid;

                     cout << "請輸入商品編號:";

                     cin >> sid;

                     cout << "請輸入商品價格:";

                     cin >> sp;

                     cout << "請輸入商品數(shù)量:";

                     cin >> sc;

                     cout << "請輸入收件人姓名:";

                     cin >> n;



                     Order o(oid, sid, sp, sc, n);

                     orders[i] = o;

              }

       }



       if (have == false)

       {

              cout << "沒有該訂單號的訂單" << endl;

              return;

       }

       cout << "修改成功" << endl;

}



void deleteOrder(Order orders[], int& index)

{

       if (index == 0)

       {

              cout << "訂單為空" << endl;

       }



       string oid;

       cout << "請輸入要刪除的訂單編號" << endl;

       cin >> oid;



       bool have = false;

       int i;

       for (i = 0; i < index; i++)

       {

              if (orders[i].getOid() == oid)

              {

                     have = true;

                     break;

              }

       }



       if (have == false)

       {

              cout << "沒有該訂單號的訂單" << endl;

              return;

       }

       else

       {

              for (int j = i; j < index - 1; j++)

              {

                     orders[j] = orders[j + 1];

              }

              index--;

       }



       cout << "刪除成功" << endl;

}

完整代碼

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

#define N 5

#define MAX 3 //最大訂單數(shù)量



class Order

{

public:

       //構(gòu)造函數(shù)

       Order(string oid = "", string sid = "", double sp = 0, int sc = 0, string n 
= "")

       {

              order_num = oid;

              goods_num = sid;

              goods_price = sp;

              goods_count = sc;

              name = n;

       }



       //打印基本信息

       void print()

       {

              cout << "訂單編號:" << setw(N) << order_num << " 商品編號:" << 
setw(N) << goods_num << " 商品價格:"

                     << setw(N) << goods_price << " 商品數(shù)量:" << setw(N) << 
goods_count << " 收件人姓名:" << setw(N) << name << endl;

       }



       //獲得訂單編號

       string getOid()

       {

              return order_num;

       }



       //獲得姓名

       string getName()

       {

              return name;

       }



private:

       string order_num;    //訂單編號

       string goods_num;          //商品編號

       double goods_price;  //商品價格

       int goods_count;           //商品數(shù)量

       string name;         //收件人姓名

};



Order orders[MAX];

int index = 0;



void add(Order orders[], int& index)

{

       if (index == MAX)

       {

              cout << "訂單已滿" << endl;

              return;

       }



       string oid;

       string sid;

       double sp;

       int sc;

       string n;

       cout << "請輸入訂單編號:";

       cin >> oid;

       cout << "請輸入商品編號:";

       cin >> sid;

       cout << "請輸入商品價格:";

       cin >> sp;

       cout << "請輸入商品數(shù)量:";

       cin >> sc;

       cout << "請輸入收件人姓名:";

       cin >> n;

       Order o(oid, sid, sp, sc, n);

       orders[index++] = o;

       cout << "添加成功" << endl;

}



void visit(Order orders[], int& index)

{

       cout << "目前共有" << index << "個訂單" << endl;

       for (int i = 0; i < index; i++)

       {

              orders[i].print();

       }

}



void find(Order orders[], int& index)

{

       if (index == 0)

       {

              cout << "訂單為空" << endl;

       }



       int chiose;

       cout << "請選擇查詢方式  1、訂單編號  2、收件人姓名" << endl;

       cin >> chiose;

       if (chiose == 1)

       {

              string oid;

              cout << "請輸入要查詢的訂單編號" << endl;

              cin >> oid;

              for (int i = 0; i < index; i++)

              {

                     if (orders[i].getOid() == oid)

                     {

                           orders[i].print();

                     }

              }

       }

       else if (chiose == 2)

       {

              string name;

              cout << "請輸入要查詢的收件人姓名" << endl;

              cin >> name;

              for (int i = 0; i < index; i++)

              {

                     if (orders[i].getName() == name)

                     {

                           orders[i].print();

                     }

              }

       }

       else

       {

              cout << "錯誤的選擇" << endl;

       }

}



void fixed(Order orders[], int& index)

{

       if (index == 0)

       {

              cout << "訂單為空" << endl;

       }



       string oid;

       cout << "請輸入要修改的訂單編號" << endl;

       cin >> oid;



       bool have = false;

       for (int i = 0; i < index; i++)

       {

              if (orders[i].getOid() == oid)

              {

                     have = true;



                     string oid;

                     string sid;

                     double sp;

                     int sc;

                     string n;

                     cout << "請輸入訂單編號:";

                     cin >> oid;

                     cout << "請輸入商品編號:";

                     cin >> sid;

                     cout << "請輸入商品價格:";

                     cin >> sp;

                     cout << "請輸入商品數(shù)量:";

                     cin >> sc;

                     cout << "請輸入收件人姓名:";

                     cin >> n;



                     Order o(oid, sid, sp, sc, n);

                     orders[i] = o;

              }

       }



       if (have == false)

       {

              cout << "沒有該訂單號的訂單" << endl;

              return;

       }

       cout << "修改成功" << endl;

}



void deleteOrder(Order orders[], int& index)

{

       if (index == 0)

       {

              cout << "訂單為空" << endl;

       }



       string oid;

       cout << "請輸入要刪除的訂單編號" << endl;

       cin >> oid;



       bool have = false;

       int i;

       for (i = 0; i < index; i++)

       {

              if (orders[i].getOid() == oid)

              {

                     have = true;

                     break;

              }

       }



       if (have == false)

       {

              cout << "沒有該訂單號的訂單" << endl;

              return;

       }

       else

       {

              for (int j = i; j < index - 1; j++)

              {

                     orders[j] = orders[j + 1];

              }

              index--;

       }



       cout << "刪除成功" << endl;

}



int main(void)

{

       int n = 0;           //記錄口令輸入次數(shù)

       string password;                  //輸入的密碼

       cout << "請輸入登錄口令(默認(rèn)abcd)" << endl;

       while (1)

       {

              cin >> password;

              if (password == "abcd")

              {

                     cout << "輸入口令正確!" << endl;

                     break;

              }

              else

              {

                     cout << "輸入口令正確,請重新輸入!" << endl;

                     n++;

                     if (n == 3)

                     {

                           cout << "已輸入三次,您無權(quán)進(jìn)行操作!" << endl;

                           return 0;

                     }

              }

       }

       cout << endl;



       while (1)

       {

              system("cls");

              cout << "*******************************************" << endl;

              cout << "*     根據(jù)所做操作選擇一下數(shù)字序號        *" << endl;

              cout << "*     1.添加訂單        2.瀏覽訂單        *" << endl;

              cout << "*     3.查詢訂單        4.修改訂單        *" << endl;

              cout << "*     5.刪除訂單        6.退出系統(tǒng)        *" << endl;

              cout << "*******************************************" << endl;

              int n;

              cin >> n;

              switch (n)

              {

              case 1:

                     add(orders, index);

                     system("pause");

                     break;

              case 2:

                     visit(orders, index);

                     system("pause");

                     break;

              case 3:

                     find(orders, index);

                     system("pause");

                     break;

              case 4:

                     fixed(orders, index);

                     system("pause");

                     break;

              case 5:

                     deleteOrder(orders, index);

                     system("pause");

                     break;

              case 6:

                     return 0;

                     break;

              default:

                     break;

              }

       }



       return 0;

}

結(jié)語

該系統(tǒng)比較簡單,對數(shù)據(jù)的存儲使用了數(shù)組,也可以使用順序表,鏈表等數(shù)據(jù)結(jié)構(gòu),代碼中也有很多值得優(yōu)化的地方。

以上就是C++實現(xiàn)團購訂單管理系統(tǒng)的詳細(xì)內(nèi)容,更多關(guān)于C++訂單管理系統(tǒng)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 深入理解c++常成員函數(shù)和常對象

    深入理解c++常成員函數(shù)和常對象

    下面小編就為大家?guī)硪黄钊肜斫鈉++常成員函數(shù)和常對象。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨小編過來看看吧
    2016-05-05
  • C語言從代碼中加載動態(tài)鏈接庫過程解析

    C語言從代碼中加載動態(tài)鏈接庫過程解析

    這篇文章主要介紹了C語言從代碼中加載動態(tài)鏈接庫過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-12-12
  • 深入了解C語言指針

    深入了解C語言指針

    這篇文章主要介紹了C語言指針詳解及用法示例,介紹了其相關(guān)概念,然后分享了幾種用法,具有一定參考價值。需要的朋友可以了解下
    2021-07-07
  • 最新評論

    正蓝旗| 庆元县| 惠安县| 娄烦县| 石门县| 左贡县| 镶黄旗| 阿勒泰市| 九龙坡区| 峨山| 益阳市| 永昌县| 香河县| 洮南市| 什邡市| 昭通市| 南华县| 新营市| 梁河县| 什邡市| 深水埗区| 塔河县| 杨浦区| 五台县| 新和县| 陵水| 城口县| 云浮市| 华安县| 衡东县| 杨浦区| 新源县| 铁岭县| 峨眉山市| 仪陇县| 镇原县| 岫岩| 曲靖市| 莎车县| 肃北| 北宁市|