C++實(shí)現(xiàn)團(tuán)購(gòu)訂單管理系統(tǒng)
項(xiàng)目需求
功能說(shuō)明
要求編寫(xiě)一個(gè)團(tuán)購(gòu)訂單信息管理系統(tǒng)。
系統(tǒng)包含對(duì)訂單的添加、查詢(xún)、修改、刪除和瀏覽等功能。
系統(tǒng)設(shè)有口令,只有正確輸入口令才能使用該信息管理系統(tǒng)
功能具體說(shuō)明
菜單的設(shè)計(jì):共設(shè)置6個(gè)選項(xiàng),包括訂單的添加、查詢(xún)、修改、刪除、瀏覽和退出。退出系統(tǒng)前菜單是重復(fù)循環(huán)的。
訂單信息的設(shè)計(jì):本案例采用簡(jiǎn)化形式,只定義了訂單編號(hào)、商品編號(hào)、商品單價(jià)、商品數(shù)量、收件人姓名等。
添加訂單:添加時(shí)訂單的詳細(xì)信息從鍵盤(pán)輸入相應(yīng)內(nèi)容。
瀏覽訂單:顯示當(dāng)前訂單的所有信息,要求有格式控制。
查詢(xún)訂單:可輸入訂單編號(hào)或收件人姓名查詢(xún)相應(yīng)訂單。
修改訂單:對(duì)特定訂單信息進(jìn)行修改并保存。
刪除訂單:可根據(jù)訂單編號(hào)對(duì)該訂單進(jìn)行刪除操作。
口令設(shè)置:被設(shè)為一個(gè)字符串常量。程序開(kāi)始運(yùn)行時(shí),要求通過(guò)鍵盤(pán)輸入口令。3次輸入不正確,直接結(jié)束程序。
代碼實(shí)現(xiàn)
對(duì)于訂單設(shè)計(jì)的類(lèi)
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 << "訂單編號(hào):" << setw(N) << order_num << " 商品編號(hào):" <<
setw(N) << goods_num << " 商品價(jià)格:"
<< setw(N) << goods_price << " 商品數(shù)量:" << setw(N) <<
goods_count << " 收件人姓名:" << setw(N) << name << endl;
}
//獲得訂單編號(hào)
string getOid()
{
return order_num;
}
//獲得姓名
string getName()
{
return name;
}
private:
string order_num; //訂單編號(hào)
string goods_num; //商品編號(hào)
double goods_price; //商品價(jià)格
int goods_count; //商品數(shù)量
string name; //收件人姓名
};
系統(tǒng)中各個(gè)功能的實(shí)現(xiàn)
對(duì)于系統(tǒng)中的添加,瀏覽,查詢(xún),修改,刪除五項(xiàng)功能分別定義了函數(shù)來(lái)實(shí)現(xiàn)。
其中的orders是用來(lái)保存訂單信息的數(shù)組,index是記錄當(dāng)前數(shù)組位置
void add(Order orders[], int& index)
{
if (index == MAX)
{
cout << "訂單已滿(mǎn)" << endl;
return;
}
string oid;
string sid;
double sp;
int sc;
string n;
cout << "請(qǐng)輸入訂單編號(hào):";
cin >> oid;
cout << "請(qǐng)輸入商品編號(hào):";
cin >> sid;
cout << "請(qǐng)輸入商品價(jià)格:";
cin >> sp;
cout << "請(qǐng)輸入商品數(shù)量:";
cin >> sc;
cout << "請(qǐng)輸入收件人姓名:";
cin >> n;
Order o(oid, sid, sp, sc, n);
orders[index++] = o;
cout << "添加成功" << endl;
}
void visit(Order orders[], int& index)
{
cout << "目前共有" << index << "個(gè)訂單" << 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 << "請(qǐng)選擇查詢(xún)方式 1、訂單編號(hào) 2、收件人姓名" << endl;
cin >> chiose;
if (chiose == 1)
{
string oid;
cout << "請(qǐng)輸入要查詢(xún)的訂單編號(hào)" << 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 << "請(qǐng)輸入要查詢(xún)的收件人姓名" << endl;
cin >> name;
for (int i = 0; i < index; i++)
{
if (orders[i].getName() == name)
{
orders[i].print();
}
}
}
else
{
cout << "錯(cuò)誤的選擇" << endl;
}
}
void fixed(Order orders[], int& index)
{
if (index == 0)
{
cout << "訂單為空" << endl;
}
string oid;
cout << "請(qǐng)輸入要修改的訂單編號(hào)" << 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 << "請(qǐng)輸入訂單編號(hào):";
cin >> oid;
cout << "請(qǐng)輸入商品編號(hào):";
cin >> sid;
cout << "請(qǐng)輸入商品價(jià)格:";
cin >> sp;
cout << "請(qǐng)輸入商品數(shù)量:";
cin >> sc;
cout << "請(qǐng)輸入收件人姓名:";
cin >> n;
Order o(oid, sid, sp, sc, n);
orders[i] = o;
}
}
if (have == false)
{
cout << "沒(méi)有該訂單號(hào)的訂單" << endl;
return;
}
cout << "修改成功" << endl;
}
void deleteOrder(Order orders[], int& index)
{
if (index == 0)
{
cout << "訂單為空" << endl;
}
string oid;
cout << "請(qǐng)輸入要?jiǎng)h除的訂單編號(hào)" << 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 << "沒(méi)有該訂單號(hào)的訂單" << 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 << "訂單編號(hào):" << setw(N) << order_num << " 商品編號(hào):" <<
setw(N) << goods_num << " 商品價(jià)格:"
<< setw(N) << goods_price << " 商品數(shù)量:" << setw(N) <<
goods_count << " 收件人姓名:" << setw(N) << name << endl;
}
//獲得訂單編號(hào)
string getOid()
{
return order_num;
}
//獲得姓名
string getName()
{
return name;
}
private:
string order_num; //訂單編號(hào)
string goods_num; //商品編號(hào)
double goods_price; //商品價(jià)格
int goods_count; //商品數(shù)量
string name; //收件人姓名
};
Order orders[MAX];
int index = 0;
void add(Order orders[], int& index)
{
if (index == MAX)
{
cout << "訂單已滿(mǎn)" << endl;
return;
}
string oid;
string sid;
double sp;
int sc;
string n;
cout << "請(qǐng)輸入訂單編號(hào):";
cin >> oid;
cout << "請(qǐng)輸入商品編號(hào):";
cin >> sid;
cout << "請(qǐng)輸入商品價(jià)格:";
cin >> sp;
cout << "請(qǐng)輸入商品數(shù)量:";
cin >> sc;
cout << "請(qǐng)輸入收件人姓名:";
cin >> n;
Order o(oid, sid, sp, sc, n);
orders[index++] = o;
cout << "添加成功" << endl;
}
void visit(Order orders[], int& index)
{
cout << "目前共有" << index << "個(gè)訂單" << 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 << "請(qǐng)選擇查詢(xún)方式 1、訂單編號(hào) 2、收件人姓名" << endl;
cin >> chiose;
if (chiose == 1)
{
string oid;
cout << "請(qǐng)輸入要查詢(xún)的訂單編號(hào)" << 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 << "請(qǐng)輸入要查詢(xún)的收件人姓名" << endl;
cin >> name;
for (int i = 0; i < index; i++)
{
if (orders[i].getName() == name)
{
orders[i].print();
}
}
}
else
{
cout << "錯(cuò)誤的選擇" << endl;
}
}
void fixed(Order orders[], int& index)
{
if (index == 0)
{
cout << "訂單為空" << endl;
}
string oid;
cout << "請(qǐng)輸入要修改的訂單編號(hào)" << 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 << "請(qǐng)輸入訂單編號(hào):";
cin >> oid;
cout << "請(qǐng)輸入商品編號(hào):";
cin >> sid;
cout << "請(qǐng)輸入商品價(jià)格:";
cin >> sp;
cout << "請(qǐng)輸入商品數(shù)量:";
cin >> sc;
cout << "請(qǐng)輸入收件人姓名:";
cin >> n;
Order o(oid, sid, sp, sc, n);
orders[i] = o;
}
}
if (have == false)
{
cout << "沒(méi)有該訂單號(hào)的訂單" << endl;
return;
}
cout << "修改成功" << endl;
}
void deleteOrder(Order orders[], int& index)
{
if (index == 0)
{
cout << "訂單為空" << endl;
}
string oid;
cout << "請(qǐng)輸入要?jiǎng)h除的訂單編號(hào)" << 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 << "沒(méi)有該訂單號(hào)的訂單" << 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 << "請(qǐng)輸入登錄口令(默認(rèn)abcd)" << endl;
while (1)
{
cin >> password;
if (password == "abcd")
{
cout << "輸入口令正確!" << endl;
break;
}
else
{
cout << "輸入口令正確,請(qǐng)重新輸入!" << endl;
n++;
if (n == 3)
{
cout << "已輸入三次,您無(wú)權(quán)進(jìn)行操作!" << endl;
return 0;
}
}
}
cout << endl;
while (1)
{
system("cls");
cout << "*******************************************" << endl;
cout << "* 根據(jù)所做操作選擇一下數(shù)字序號(hào) *" << endl;
cout << "* 1.添加訂單 2.瀏覽訂單 *" << endl;
cout << "* 3.查詢(xún)訂單 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é)語(yǔ)
該系統(tǒng)比較簡(jiǎn)單,對(duì)數(shù)據(jù)的存儲(chǔ)使用了數(shù)組,也可以使用順序表,鏈表等數(shù)據(jù)結(jié)構(gòu),代碼中也有很多值得優(yōu)化的地方。
以上就是C++實(shí)現(xiàn)團(tuán)購(gòu)訂單管理系統(tǒng)的詳細(xì)內(nèi)容,更多關(guān)于C++訂單管理系統(tǒng)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C語(yǔ)言關(guān)系運(yùn)算符實(shí)例詳解
本文主要介紹C語(yǔ)言的關(guān)系運(yùn)算符的知識(shí),這里提供實(shí)例代碼以便參考,希望能幫助有需要的小伙伴2016-07-07
C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易的掃雷小游戲
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易的掃雷小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
C++實(shí)例講解四種類(lèi)型轉(zhuǎn)換的使用
在C++語(yǔ)言中新增了四個(gè)關(guān)鍵字static_cast、const_cast、reinterpret_cast和dynamic_cast。這四個(gè)關(guān)鍵字都是用于類(lèi)型轉(zhuǎn)換的,類(lèi)型轉(zhuǎn)換(type cast),是高級(jí)語(yǔ)言的一個(gè)基本語(yǔ)法。它被實(shí)現(xiàn)為一個(gè)特殊的運(yùn)算符,以小括號(hào)內(nèi)加上類(lèi)型名來(lái)表示,接下來(lái)讓我們一起來(lái)詳細(xì)了解2022-06-06
使用pybind11封裝C++結(jié)構(gòu)體作為參數(shù)的函數(shù)實(shí)現(xiàn)步驟
這篇文章主要介紹了用pybind11封裝C++結(jié)構(gòu)體作為參數(shù)的函數(shù)實(shí)現(xiàn)步驟,本文分步驟通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-02-02
C語(yǔ)言從代碼中加載動(dòng)態(tài)鏈接庫(kù)過(guò)程解析

