舍友说我这是夹带私货,明明没有
一些废话
学校安排去东软生产实习,更像是换个地方写C++大作业,带我们的崔老师很好,确实是学到了不少东西。所经历的过程越痛苦,走出来时获得越多,真的应了尼采的“凡是不能置我于死地的必将使我受益”。
就粘一些我写过的代码吧,队友写的我就不粘了,软工有很多文档,最后都是队友好心帮忙写的,也就不粘了
题目
某超市进销存管理系统
-
项目功能需求:
系统分为两个权限部分:管理员用户登录模块,普通用户登录模块。管理员用户登录模块包括:供应商管理,员工管理,商品管理,采购管理。普通用户登陆模块包括:个人信息,商品信息,采购信息。本项目实现以下功能:
(管理员、采购、普通员工) -
管理员用户登录模块:
A、供应商管理- 批量录入供应商数据,手动输入供应商编号,供应商名称,供应商简称,地址,公司电话,邮件,联系人,联系人电话,备注(是否合作)。
- 查询并列出表中所有的供应商信息。
- 修改指定供应商的信息。
- 删除指定供应商数据。
B、商品管理
- 批量录入商品数据,手动输入商品编号,商品名称,商品单价,供应商编号,商品简介,备注等。
- 查询并列出所有商品信息。
- 修改制定商品的商品信息。
- 删除指定商品数据。
C、员工管理
- 批量录入员工数据,手动输入员工编号,员工姓名,员工密码,员工级别,员工电话,员工工资,备注(是否离职)等。
- 查询并列出所有员工信息。
- 修改指定员工信息。
- 删除指定员工数据。
D、采购管理
- 录入采购主表数据,手动输入采购清单号,员工编号(外码),采购数量,采购总价,采购时间,备注。
- 录入采购明细数据,手动输入采购明细号,采购清单号(外码),商品编号(外码),采购数量,商品单价,商品总价,备注。
- 查询并列出所有采购主表和采购明细信息。
- 修改指定采购主表信息和采购明细信息。
- 删除指定采购主表信息和采购明细信息。
-
普通用户登录模块。
- 查询自己的员工信息。
- 查询所有商品信息。
- 查询所有的采购信息。
主要注意一下通过外码实现动态查询。老师是建议用友元函数,但是我们最后时间来不及了,趁着测试样例不会很多,时间空间都没有管,实现得像作弊一样
代码
头文件就放一个供应商吧,其他的都差不多
#pragma once
#define len 11
#include <vector>
#include <string>
#define len 11
using namespace std;
class Sup {
public:
int sup_id; //主键 id
char sup_name[len];
char sup_abbr[len];//缩写
char sup_addr[len];//地址
char sup_tele[len];
char sup_mail[len];
char contact_name[len];
char contact_tele[len];
char sup_remark[len];
};
class Sups {
private:
vector <Sup> sups;
public:
friend class Admin;
void AddSupMore();//批量输入
friend istream& operator>>(istream& in, Sups& s);
void DeleteSup(int sup_id);//删除指定供应商数据
void ResearchSup(int sup_id);//查询
void ReviseSupInfo(); //修改指定供应商的信息
void PrintSupInfo();//列出表中所有的供应商信息
void Save();
};
菜单部分
#include<iostream>
#include<string>
#include<windows.h>
#include<vector>
#include"buy.h"
#include"sup.h"
#include"goods.h"
#include"staff.h"
#define DANGER 3
using namespace std;
void MainMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts);
void AdminMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts);
void PurchaseMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts);
void SupMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice3,id;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
//Sups supss = {};
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to do about Sup?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.AddMore" << endl;
cout << "\t2.AddOne" << endl;
cout << "\t3.Research" << endl;
cout << "\t4.Modify" << endl;
cout << "\t5.Delete" << endl;
cout << "\t6.Print" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice3;
switch (choice3) {
case 1:
supss.AddSupMore();//批量输入
supss.Save();
break;
case 2:
cin >> supss;//手动输入
supss.Save();
break;
case 3:
cout << "Enter your id:";
cin >> id;
supss.ResearchSup(id);//查询
break;
case 4:
supss.ReviseSupInfo(); //修改指定供应商的信息
supss.Save();
break;
case 5:cout << "Enter your id:";
cin >> id;
supss.DeleteSup(id);//删除指定供应商数据
cout<<"delete"<<endl;
supss.Save();
break;
case 6:supss.PrintSupInfo();//输出所有
break;
case -1:
exit(0);
break;
case -2:
AdminMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
void GoodsMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice4,id,supid;
char button;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
//Goodss goodss = {};
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to do about Goods?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.AddMore" << endl;
cout << "\t2.AddOne" << endl;
cout << "\t3.Research" << endl;
cout << "\t4.Modify" << endl;
cout << "\t5.Delete" << endl;
cout << "\t6.Print" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice4;
switch (choice4) {
case 1:goodss.AddGoodsMore();//批量输入
goodss.Save();
break;
case 2:cin >> goodss;//手动输入
goodss.Save();
break;
case 3:cout << "Enter your id:";
cin >> id;
supid = goodss.ResearchGoods(id);//查询
goodss.Save();
cout << "Maybe you want to know more about the supplyer of the goods."<<endl;
cout << "Y or N ?"<<endl;
cin >> button;
if(button=='Y'||button=='y') supss.ResearchSup(supid);
break;
case 4:goodss.ReviseGoodsInfo(); //修改指定供应商的信息
goodss.Save();
break;
case 5:cout << "Enter your id:";
cin >> id;
goodss.DeleteGoods(id);//删除指定供应商数据
goodss.Save();
break;
case 6:goodss.PrintGoodsInfo();//输出所有
goodss.Save();
break;
case -1:exit(0);
break;
case -2:AdminMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
void OStaffMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice5,id;
//Staffs staffs = {};
//BuyHosts b={};
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to do about Staff?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.AddMore" << endl;
cout << "\t2.AddOne" << endl;
cout << "\t3.Research" << endl;
cout << "\t4.Modify" << endl;
cout << "\t5.Delete" << endl;
cout << "\t6.Print" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice5;
switch (choice5) {
case 1:staffs.AddStaffMore();//批量输入
staffs.Save();
break;
case 2:cin >> staffs;//手动输入
staffs.Save();
break;
case 3:cout << "Enter your id:";
cin >> id;
staffs.ResearchStaff(id);//查询
staffs.Save();
break;
case 4:staffs.ReviseStaffInfo(); //修改指定供应商的信息
staffs.Save();
break;
case 5:cout << "Enter your id:";
cin >> id;
staffs.DeleteStaff(id);//删除指定供应商数据
staffs.Save();
break;
case 6:staffs.PrintStaffInfo();//输出所有
staffs.Save();
break;
case -1:exit(0);
break;
case -2:AdminMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
void BuyHostMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice7, id, staffid;
char button;
//BuyHosts buyhosts = {};
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to do about Buyhost?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.AddMore" << endl;
cout << "\t2.AddOne" << endl;
cout << "\t3.Research" << endl;
cout << "\t4.Modify" << endl;
cout << "\t5.Delete" << endl;
cout << "\t6.Print" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice7;
switch (choice7) {
case 1:buyhosts.AddBuyHostMore();//批量输入
buyhosts.Save();
break;
case 2:cin >> buyhosts;//手动输入
buyhosts.Save();
break;
case 3:cout << "Enter your id:";
cin >> id;
staffid = buyhosts.ResearchBuyHost(id);//查询
buyhosts.Save();
cout << "Maybe you want to know more about the buyer."<<endl;
cout << "Y or N ?"<<endl;
cin >> button;
if(button=='Y'||button=='y') staffs.ResearchStaff(staffid);
break;
case 4:buyhosts.ReviseBuyHostInfo(); //修改指定供应商的信息
buyhosts.Save();
break;
case 5:cout << "Enter your id:";
cin >> id;
buyhosts.DeleteBuyHost(id);//删除指定供应商数据
buyhosts.Save();
break;
case 6:buyhosts.PrintBuyHostInfo();//输出所有
buyhosts.Save();
break;
case -1:exit(0);
break;
case -2:PurchaseMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
void BuyPartMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice8, id;
int *both;
char button1, button2;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
//BuyParts buyparts = {};
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to do about Buypart?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.AddMore" << endl;
cout << "\t2.AddOne" << endl;
cout << "\t3.Research" << endl;
cout << "\t4.Modify" << endl;
cout << "\t5.Delete" << endl;
cout << "\t6.Print" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice8;
switch (choice8) {
case 1:buyparts.AddBuyPartMore();//批量输入
buyparts.Save();
break;
case 2:cin >> buyparts;//手动输入
buyparts.Save();
break;
case 3:cout << "Enter your id:";
cin >> id;
both = buyparts.ResearchBuyPart(id);//查询
buyparts.Save();
cout << "Maybe you want to know more about the buyhost."<<endl;
cout << "Y or N ?"<<endl;
cin >> button1;
if(button1=='Y'||button1=='y') buyhosts.ResearchBuyHost(both[0]);
cout << "Maybe you want to know more about the goods."<<endl;
cout << "Y or N ?"<<endl;
cin >> button2;
if(button2=='Y'||button2=='y') goodss.ResearchGoods(both[1]);
break;
case 4:buyparts.ReviseBuyPartInfo(); //修改指定供应商的信息
buyparts.Save();
break;
case 5:cout << "Enter your id:";
cin >> id;
buyparts.DeleteBuyPart(id);//删除指定供应商数据
buyparts.Save();
break;
case 6:buyparts.PrintBuyPartInfo();//输出所有
buyparts.Save();
break;
case -1:exit(0);
break;
case -2:PurchaseMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
void PurchaseMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice6;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to do about Purchasing?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.Operator on Buyhost" << endl;
cout << "\t2.Operator on Buypart" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice6;
switch (choice6) {
case 1:BuyHostMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case 2:BuyPartMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case -1:exit(0);
break;
case -2:AdminMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
void AdminMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int code=123456;
int codein=0;
int count = 0;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
while(1){
cout<<endl;
cout<<"admincode:";
cin>>codein;
if(codein==code){
int choice1;
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to know?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.Sup" << endl;
cout << "\t2.Goods" << endl;
cout << "\t3.Staff" << endl;
cout << "\t4.Purchasing" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice1;
switch (choice1) {
case 1:SupMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case 2:GoodsMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case 3:OStaffMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case 4:PurchaseMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case -1:exit(0);
break;
case -2:MainMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
}
}
}
else{
count++;
cout<<"WARNING::code wrong!!!"<<endl;
Sleep(3);
if(count != DANGER) continue;
else{
cout<<endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED);
cout << "ACCESSED MORE THAN SAFE TIMES"<<endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
Sleep(5);
exit(0);
}
}
}
void StaffMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice2;
int id;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
while (1) {
system("cls");
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
cout << "What do you want to know?" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.Query your own information" << endl;
cout << "\t2.Query all goods information" << endl;
cout << "\t3.Query all Buyhost information" << endl;
cout << "\t4.Query all Buypart information" << endl;
cout << "\t-1.Exit" << endl;
cout << "\t-2.Back" << endl;
cout << "Your choice: " << endl;
cin >> choice2;
switch (choice2) {
case 1:cout << "Enter your id:";
cin >> id;
staffs.ResearchStaff(id);//查询
break;
case 2:cout << "Enter goods id:";
cin >> id;
goodss.ResearchGoods(id);//查询
break;
case 3:cout << "Enter Buyhost id:";
cin >> id;
buyhosts.ResearchBuyHost(id);//查询
break;
case 4:cout << "Enter buypart id:";
cin >> id;
buyparts.ResearchBuyPart(id);//查询
break;
case -1:exit(0);
break;
case -2:MainMenu(supss,goodss,staffs,buyhosts,buyparts);
}
}
}
void MainMenu(Sups supss,Goodss goodss,Staffs staffs,BuyHosts buyhosts,BuyParts buyparts) {
int choice;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
//HDC dskDC=GetWindowDC(desk);
while (1) {
system("cls");
cout <<endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);
//fontRect.lfHeight=-50;
cout << "login mode:" << endl;
cout << endl;
SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
cout << "\t1.Admin" << endl;
cout << "\t2.Staff" << endl;
cout << "\t-1.Exit" << endl;
cout << "Your choice: " << endl;
cin >> choice;
switch (choice) {
case 1:
AdminMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case 2:StaffMenu(supss,goodss,staffs,buyhosts,buyparts);
break;
case -1:exit(0);
}
}
}
int main() {
Sups supss = {};
Goodss goodss = {};
Staffs staffs = {};
BuyHosts buyhosts = {};
BuyParts buyparts = {};
MainMenu(supss,goodss,staffs,buyhosts,buyparts);
}
输入,这块也以供应商举例:
#include<iostream>
#include<string>
#include<vector>
#include"buy.h"
#include"sup.h"
#include"goods.h"
#include"staff.h"
#include<fstream>
using namespace std;
istream& operator>>(istream& in, Sups& x)
{
Sup c;
cout << "Supplyer ID:" << endl;
in >> c.sup_id;
cout << "Supplyer Name:" << endl;
in >> c.sup_name;
cout << "Supplyer Abbr:" << endl;
in >> c.sup_abbr;
cout << "Supplyer Address" << endl;
in >> c.sup_addr;
cout << "Supplyer Telephone Number:" << endl;
in >> c.sup_tele;
cout << "Supplyer Email:" << endl;
in >> c.sup_mail;
cout << "Contact Name:" << endl;
in >> c.contact_name;
cout << "Contact Telephone Number:" << endl;
in >> c.contact_tele;
cout << "Supplyer Remark:" << endl;
in >> c.sup_remark;
x.sups.push_back(c);
return in;
}
void Sups::AddSupMore()//批量输入
{
Sup s;
cout<<"have entered"<<endl;
ifstream inFile("sup.lsp", ios::in | ios::binary);
if (!inFile) cout << "file open error" << endl;
else cout<<"loading..."<<endl;
int length = 0;
while (inFile.read((char*)&s, sizeof(s))) {
length++;
sups.push_back(s);
}
cout<<"have added "<<length<<" sup(s)."<<endl;
cout<<endl<<"Then you want to ?"<<endl;
cout<<"\t-1.Back"<<endl;
cout<<"\t-2.Exit"<<endl;
int choice;
cin>>choice;
switch(choice){
case -1: break;
case -2: exit(0);
}
}
保存,以供应商为例:
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include"sup.h"
#include"staff.h"
#include"goods.h"
#include"buy.h"
#include <string>
using namespace std;
bool supcomp(const Sup &a, const Sup &b){
return a.sup_id < b.sup_id;
}
void Sups::Save(){
Sup s;
//int length=sups.size();
//cout<<length<<endl;
vector<Sup>::iterator it;
sort(sups.begin(),sups.end(),supcomp);
ofstream outFile("sup.lsp",ios::out | ios::binary);
for(it = sups.begin();it != sups.end();it++){
s = *it;
outFile.write((char*)&s,sizeof(s));
}
outFile.close();
}
删除,也是举个例子:
void Sups::DeleteSup(int id){
vector<Sup>::iterator it;
int flag = 0;
cout << "Sure to delete ?"<<endl;
cout << "y or n?"<<endl;
char button;
cin >> button;
if(button == 'Y'|| button == 'y') ;
else return;
for(it = sups.begin();it != sups.end();it++){
if(it->sup_id == id){
sups.erase(it);
flag = 1;
break;
}
}
if(flag == 0) cout<<"Not Found"<<endl;
else cout<<"delete have done!"<<endl;
cout<<endl<<"Then you want to ?"<<endl;
cout<<"\t1.Continue"<<endl;
cout<<"\t-1.Back"<<endl;
cout<<"\t-2.Exit"<<endl;
int choice;
int hid;
cin>>choice;
switch(choice){
case 1:
cout << "Enter your id:";
cin >> hid;
DeleteSup(hid);
case -1: cout<<"111111"<<endl;break;
case -2: exit(0);
}
}
其他的其实也差不多,完整代码可以私戳我