C++超市庫存管理系統期末作業

前言:
期末前的一個作業,忙了好久才做好,真是要吐了。
下面是個流程圖,相關功能我寫的還算清晰,最後還加上了按任意鍵繼續的代碼和清屏代碼。只是,還沒有修改商品的功能,做了這些已經快要廢了。還有考試,不做了不做了。就先這樣子吧。百度的我都快吐了,看代碼,查代碼,寫代碼,從這點看出來我以後可能不適合做開發。哈哈。不說了不說了,考試真的慌啊。狗頭保命。
m0re

代碼

//main.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <conio.h>
using namespace std;

//倉庫管理員類
class admin
{
public:
admin();
private:
string name;
};

//倉庫貨架類
class shelf
{
public:
shelf();
private:
admin men;//管理員
string storeNo;//倉庫編號
string kinds;//生產產地
string shelfNo;//貨架號
};

//electrical class
class ele
{
public:
ele();
private:
string name;//商品名
double price;//價格
shelf sh;//所屬貨架
long count;//商品數量
};
//管理(組合類)
class mana
{
public:
mana();
char first_face();//首頁
void in_storage();//入庫
void out_storage();// 出庫
void select_ele();//查詢
void select_name();//按商品名稱查詢
void select_price();//按商品價格查詢
void select_kind();//按產地查詢
void call_break();//商品報損
private:
ele aele;
shelf ashelf;
admin abs;
};

//電器類默認構造函數
ele::ele():sh()
{
name = "xxx";//商品名
price = 0.0;//價格
count = 0;//商品數量
}



//倉庫貨架類默認構造函數
shelf::shelf():men()
{
storeNo = "xxx";//倉庫編號
kinds = "xxx";//生產產地
shelfNo = "xxx";;//貨架號
}

//倉庫管理員類
admin::admin()
{
name = "xxx";
}

//管理類默認構造函數
mana::mana():aele(), ashelf(), abs()
{
}

char mana::first_face()
{

cout << endl;
cout <<endl <<"\t\t>>>>>>>>>>>>>>>>超市庫存貨物管理系統<<<<<<<<<<<<<<<<<<<<\t\t"
<<endl<<"\t--------------------------系統菜單顯示如下---------------------\t"
<<endl <<"\t\t¥¥"
<<endl <<"\t\t¥¥ 1. 商品入庫 ¥¥"
<<endl <<"\t\t¥¥ 2. 商品出庫 ¥¥"
<<endl <<"\t\t¥¥ 3. 查詢統計 ¥¥"
<<endl <<"\t\t¥¥ 4. 商品報損 ¥¥"
<<endl <<"\t\t¥¥ 5. 退出系統 ¥¥"
<<endl <<"\t\t---------------------------------------------------" <<endl <<endl <<"\t\t";
system("pause");
return getch();
}

//入庫
void mana::in_storage()
{

string name;//商品名
double price;//價格
string storeNo;//倉庫編號
string kinds;//生產產地
string shelfNo;//貨架號
long count = 0; //商品數量

cout << endl << "商品入庫,請輸入相關信息 : " << endl << endl ;
cout << "\t商品名稱 : ";
cin >> name;
cout << endl << "\t商品價格 : ";
cin >> price;
cout << endl << "\t商品數量 : ";
cin >> count;
cout << endl << "\t倉庫編號 : ";
cin >> storeNo;
cout << endl << "\t生產產地 : ";
cin >> kinds;
cout << endl << "\t貨架編號 : " ;
cin >> shelfNo;

ofstream storeFile("m0re.txt", ios::app);
storeFile << setiosflags(ios::left) << setw(20) << name << " "
<< setw(15) << price << " " << setw(10) << count << " "
<< setw(10) << storeNo << " " << setw(20) << kinds << " "
<< shelfNo << endl;
storeFile.close();

cout << endl << endl << "\t該商品已經入庫......." << endl << endl << "\t";
system("pause");
system("cls");
}


// 出庫
void mana::out_storage()
{

string name;//商品名

cout << endl << "\t商品出庫,輸入出庫商品信息 : " << endl << endl;
cout << "\t商品名稱 : ";
cin >> name;

ifstream storeFile("m0re.txt");
if (!storeFile)
{
ofstream storeFile1("m0re.txt");
storeFile1.close();
cout << endl << endl << "\t倉存爲空!!!!" << endl << endl << "\t";
system("pause");
system("cls");
return;
}
bool flag = false;
string name1;//商品名
double price1;//價格
string storeNo1;//倉庫編號
string kinds1;//生產產地
string shelfNo1;//貨架號
long count1 = 0; //商品數量

ofstream tempFile("j4y.txt");

while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1==name)
flag = true;
else
{
tempFile << setiosflags(ios::left) << setw(20) << name1 << " "
<< setw(15) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(20) << kinds1 << " "
<< shelfNo1 << endl;
}
}
tempFile.close();
storeFile.close();

if (!flag)
{
cout << endl << endl << "\t倉庫中沒有這種商品!!!" << endl << endl << "\t";
system("pause");
system("cls"); 
return;
}

ofstream storeFile1("m0re.txt");
ifstream tempFile1("j4y.txt");
storeFile1 << tempFile1.rdbuf();
storeFile1.close();
tempFile1.close();

cout << endl << "\t這些商品已經出庫, 請仔細檢查!!!" << endl << endl << "\t";

}

//查詢
void mana::select_ele()
{
while (1)
{


cout << endl << endl;
cout << "\t=============================================================" << endl
<< "\t|| ||" << endl
<< "\t|| 商 品 查 詢 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 1. 按商品名稱查詢 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 2. 按商品價格查詢 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 3. 按產地查詢 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 4. 返回 ||" << endl
<< "\t|| ||" << endl
<< "\t=============================================================" << endl << endl << "\t\t";
char select = getch();

switch (select)
{
case '1':
select_name();
break;
case '2':
select_price();
break;
case '3':
select_kind();
break;
case '4':
return;
default:
break;
}
}
}

//按商品名稱查詢
void mana::select_name()
{
cout << endl << "\t按商品名查詢 : " << endl << endl ;
cout << "\t輸入商品名 : ";
string name;
cin >> name;

string name1;//商品名
double price1;//價格
string storeNo1;//倉庫編號
string kinds1;//生產產地
string shelfNo1;//貨架號
long count1 = 0; //商品數量

ifstream storeFile("m0re.txt");
if (!storeFile)
{
cout << endl << endl << "\t對不起,你的庫存爲空!!!" << endl << endl << "\t";

return;
}

bool flag = false;
cout << endl << "商品名 " << "價格 " << "商品數量 " << "倉庫編號 "
<< "生產產地 " << "貨架號" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1 == name)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();

if (!flag)
cout << endl << endl << "對不起,庫存中沒有這種商品!!!";
cout << endl << endl;
system("pause");
system("cls");
}
//按商品價格查詢
void mana::select_price()
{

cout << endl << "\t按商品價格查詢 : " << endl << endl ;
cout << "\t輸入價格 : ";
double price;
cin >> price;

string name1;//商品名
double price1;//價格
string storeNo1;//倉庫編號
string kinds1;//生產產地
string shelfNo1;//貨架號
long count1 = 0; //商品數量

ifstream storeFile("m0re.txt");
if (!storeFile)
{
cout << endl << endl << "\t對不起,你的庫存爲空!!!" << endl << endl << "\t";

return;
}

bool flag = false;
cout << endl << "商品名 " << "價格 " << "商品數量 " << "倉庫編號 "
<< "生產產地 " << "貨架號" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (price1 == price)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();

if (!flag)
cout << endl << endl << "對不起,庫存中沒有這個價格的商品!!!";
cout << endl << endl;

}

//按產地查詢
void mana::select_kind()
{

cout << endl << "\t按生產產地查詢 : " << endl << endl ;
cout << "\t輸入產地名 : ";
string kinds;
cin >> kinds;

string name1;//商品名
double price1;//價格
string storeNo1;//倉庫編號
string kinds1;//生產產地
string shelfNo1;//貨架號
long count1 = 0; //商品數量

ifstream storeFile("m0re.txt");
if (!storeFile)
{
cout << endl << endl << "\t對不起,你的庫存爲空!!!" << endl << endl << "\t";

return;
}

bool flag = false;
cout << endl << "商品名 " << "價格 " << "商品數量 " << "倉庫編號 "
<< "生產產地 " << "貨架號" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (kinds1 == kinds)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();

if (!flag)
cout << endl << endl << "對不起,庫存中沒有這類商品!!!";
cout << endl << endl;

}

//商品報損
void mana::call_break()
{


string name;//商品名

cout << endl << "\t商品報損,請輸入要報損商品信息 : " << endl << endl;
cout << "\t商品名稱 : ";
cin >> name;

ifstream storeFile("m0re.txt");
if (!storeFile)
{
ofstream storeFile1("m0re.txt");
storeFile1.close();
cout << endl << endl << "\t倉存爲空!!!!" << endl << endl << "\t";

return;
}

bool flag = false;
string name1;//商品名
double price1;//價格
string kinds1;//生產產地
string shelfNo1;//貨架號
long count1 = 0; //商品數量

ofstream tempFile("j4y.txt");
string storeNo1;//倉庫編號
cout << endl << endl << "你想報損商品信息如下 : " << endl << endl;
cout << endl << "商品名 " << "價格 " << "商品數量 " << "倉庫編號 "
<< "生產產地 " << "貨架號" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1==name)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
shelfNo1 += "(損壞)";
}
tempFile << setiosflags(ios::left) << setw(20) << name1 << " "
<< setw(15) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(20) << kinds1 << " "
<< shelfNo1 << endl;
}
tempFile.close();
storeFile.close();

if (!flag)
{
cout << endl << endl << "對不起,倉庫中沒有這種商品!!!" << endl << endl;

return;
}
ofstream storeFile1("m0re.txt");
ifstream tempFile1("j4y.txt");
storeFile1 << tempFile1.rdbuf();
storeFile1.close();
tempFile1.close();

cout << endl << endl << "這些商品已經損壞,請儘快從倉庫中取出!!!" << endl << endl;
cout << "報損成功,記錄已經更改!!!" << endl << endl ;


}
int main()
{
char select;
mana men;

while (select = men.first_face())
{
switch (select)
{
case '1':

men.in_storage();
break;
case '2':

men.out_storage();
break;
case '3':

men.select_ele();
break;
case '4':

men.call_break();
break;
case '5':

cout << "\t" << "謝謝使用!!!!" << endl << endl << "\t\t";

break;
default:
break;
}
}
return 0; 
}

還可以點擊這裏打包帶走
演示圖
m0re

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章