C++大作业
(09201216季枫,09201217张宇博,09201218陈予诚,09201219杨文涛,09201220
赵洪涛,09201222齐天宇)
商场销售管理系统商品类图(commodity):
commodity
Int number
Char cm_name[ ]
Char type_code
Float price_in
Float price_out
Int num_store
Int num_least
Long date_in
Long deadline
Char season_code
food dress appliance
Void checkquality(char[ ],int ) Void checkquality(char [ ],int)
商场销售管理系统员工类图(employee):
employee
Int number
Char name[]
Char group_code
Char status_code
Int month
Float salary
Void addemployee()
Void delemployee()
Void statuschange(char[ ],int)
Int findstatus(char[ ],int *)
Void countsalary(char[ ],int)
Void recordsalary()
Void query(char[ ])
manager warehouseman salesman
Float fixedsalary Float fixedsalary Float fixedsalary
Float salesum Float salesum Float bonus
Float getrate Float getrate
Salesman(floatx=2000,floaty=0.05) Manager(floatx=4000,floaty=0.005) Warehouseman(floatx=3000)
Void countsalary(char[ ],int) Void countsalary(char[ ],int) Void countsalary(char[ ],int)
程序代码
class employee
{ //基类
protected:
int number; //员工编号
char name[30]; //员工姓名
char group_code; //员工柜组代码(1.食品;2.服装;3.电器)
char status_code; //员工职务代码(1.售货员;2.经理;3.库管)
int month; //月份,用于记录员工工资
float salary; //工资额,用于员工工资 public:
void addemployee(); //增加员工
void delemployee(); //减少员工
void statuschange(char[],int,int); //改变员工柜组和职务
int findstatus(char[],int *); //查询员工职务代码及编号
void countsalary(char[],int); //计算员工工资
void recordsalary(); //记录员工工资
void query(char[]); //查询员工个人信息及工资信息 };
class salesman:public employee
{ //售货员类
float fixedsalary; //售货员的固定工资
float salesum; //售货员的销售额
float getrate; //售货员的提成比率 public:
salesman(float x=2000,float y=0.05); //售货员类的构造函数
void countsalary(char[],int); //售货员类的工资计算函数 };
class manager:public employee
{ //经理类
float fixedsalary; //经理的固定工资
float salesum; //经理的销售总额
float getrate; //经理的提成比率 public:
manager(float x=4000,float y=0.005); //经理类的构造函数
void countsalary(char[],int); //经理类的工资计算函数 };
class warehouseman:public employee
{ //库管类
float fixedsalary; //库管类的固定工资
float bonus; //库管的奖金 public:
warehouseman(float x=3000); //库管类的构造函数
void countsalary(char[],int); //库管类的工资计算函数 };
class commodity
{
protected:
int number; //商品编号
char cm_name[30]; //商品名称
char type_code; //商品类型代码
float price_in; //商品进价
float price_out; //商品售价
int num_store; //商品库存
int num_least; //商品临界值
long date_in; //商品的入库时间
long deadline; //商品的保质期
char season_code; //商品的季节代码(1.春 2.夏 3.秋 4.冬)
public:
void additem(); //增加商品
void delitem(); //删除商品
void checkquantity(); //检查库存
//查询商品的类型代码,季节代码,入库时间和保质期
int findtype(char [],int *,int *,int *);
void checkquality(); //检查商品的保质期或节令,为空,用于重载
void query(char[]); //查询商品信息
};
class food:public commodity { //食品类
public:
void checkquality(char [],int,int);//检查食品保质期 };
class dress:public commodity {
public:
void checkquality(char [],int); //检查服装保质期 };
class appliance:public commodity
{
public:
void checkquality(char []); //检查电器保质期 };
//#include "stdafx.h" #include "string.h"
#include "iostream"
#include "fstream"
//#include "employee.h"
using namespace std;
struct emp_struct
{
int number;
char name[30];
int gcode;
int scode;
}estruct; //员工信息记录结构,用于记录员工信息
struct sal_struct
{
int number;
char name[30];
int month;
float salary;
}sstruct; //员工工资信息记录结构,用于记录员工工资信息
////////// class employee ////// void employee::addemployee() //增加员工信息 {
cout<>name;
cout<<"请输入员工编号(1000-9999):";
cin>>number;
while(number<1000||number>9999) //检查员工编号
{
cout<>number;
}
cout<<"请输入员工所在柜组的代码(1.食品;2.服装;3.电器):";
cin>>group_code; //获取员工柜组代码
while(group_code!='1'&&group_code!='2'&&group_code!='3') //检查柜组代码
{
cin>>group_code;
}
group_code-=48; //将柜组代码由字符转换为数字
cout<>status_code; //获取员工职务代码 while(status_code!='1'&&status_code!='2'&&status_code!='3') //检查职务代码 {
cin>>status_code;
}
status_code-=48; //将职务代码转换为数字 strcpy(estruct.name,name); //将信息写入结构estruct中 estruct.number=number;
estruct.gcode=group_code;
estruct.scode=status_code;
ofstream ofile("employee.txt",ios::app|ios::binary); //打开员工信息文件employee,txt
if(! ofile)
{
cerr<>name;
fstream iofile("employee.txt",ios::in|ios::out|ios::binary); //打开员工信息文件
if(! iofile)
{cerr<>ch1;
while(ch1!='Y' && ch1!='y' && ch1!='N' && ch1!='n'){cin>>ch1;} //检查输入
if (ch1=='N'||ch1=='n')return; //不存需要存档 else //需要存档 {cout<>month;
while(month<1||month>12) //简单检验输入月份 {cout<>month;}
//将信息写入工资记录结构
sstruct.number=number;
strcpy(sstruct.name,name); sstruct.month=month;
sstruct.salary=salary;
ofstream ofile ("salary.txt",ios::app|ios::binary);//打开员工工资文件salary.txt
if(! ofile)
{ cerr<>salesum; //输入营业额
salary=fixedsalary+salesum*getrate; //工资=固定工资+营业额*提成比率
//将信息写入对象中,用于recordsalary()函数将其写入文件
number=num;
strcpy(name,namestr);
cout<<"[售货员]"<>salesum; //输入销售总额
salary=fixedsalary+salesum*getrate; //工资=固定工资+销售总额*提成比率 //将信息写入对象中,用于recordsalary()函数将其写入文件
number=num;
strcpy(name,namestr);
cout<<"[经理]"<>bonus; //输入奖金额
salary=fixedsalary+bonus; //工资=固定工资+奖金 //将信息写入对象中,用于recordsalary()函数将其写入文件
number=num;
strcpy(name,namestr);
cout<<"[库管]"<>number;
while(number<10000||number>99999)//检查商品编号
{
cout<<"商品编号应为5位数,请重新输入:";
cin>>number;
}
;3电脑):"; cout<<"请输入商品的类型代码(1.食品;2.服装
cin>>type_code;
while (type_code!='1' && type_code!='2' && type_code!='3') //检查商品类型代码 {
cin>>type_code;
}
type_code-=48; //将字符'1'、'2'或'3'转变为数字1、2或3 cout<>price_in;
cout<<"请输入商品的售价:";
cin>>price_out;
cout<<"请输入商品的数量:";
cin>>num_store;
cout<<"请输入商品的临界值:";
cin>>num_least;
cout<<"请输入进货时间(年年年年月月日日):";
cin>>date_in;
//解析进货时间
day=date_in-(date_in/100)*100; //取日 month=(date_in-(date_in/10000)*10000-day)/100; //取月 year=date_in/10000; //取天 while(year<2000||year>2050||month<1||month>12||day<1||day>31)
{ //检查进货时间
cout<<"输入进货时间错误,请重输入:";
cin>>date_in;
day=date_in-(date_in/100)*100;
month=(date_in-(date_in/10000)*10000-day)/100;
year=date_in/10000;
}
if(type_code==1) //如果是食品,则要求输入保质期
{ cout<<"请输入商品的保质期(年年月月日日,无保质期输入0):";
cin>>deadline;
day=deadline-(deadline/100)*100;
month=(deadline-(deadline/10000)*10000-day)/100;
year=deadline/10000;
while(year<0||year>20||month<0||day<0)
{ if(deadline==0)break;
cout<<"输入保质期错误,请重新输入:";
cin>>deadline;
day=deadline-(deadline/100)*100;
month=(deadline-(deadline/10000)*10000-day)/100;
year=deadline/10000;
}
}
else deadline=0;
if(type_code==2) //如果是服装,则要求输入节令
{ cout<<"请输入商品的节令(1.春;2.夏;3.秋;4.冬;无节令则输入0:";
cin>>season_code;
while(season_code!='0' && season_code!='1' && season_code!='2' &&
season_code!='3' && season_code!='4')
{cin>>season_code;
}
season_code-=48;
}
else season_code=0;
//将商品信息写入商品信息结构中
cstruct.number=number;
strcpy(cstruct.cm_name,cm_name); cstruct.type_code=type_code; cstruct.price_in=price_in; cstruct.price_out=price_out; cstruct.num_store=num_store; cstruct.num_least=num_least; cstruct.date_in=date_in;
cstruct.deadline=deadline; cstruct.season_code=season_code; ofstream ofile("store.txt",ios::app|ios::binary); //打开商品文件store.txt if(! ofile)
{ cerr<>cm_name;
fstream iofile("store.txt",ios::in|ios::out|ios::binary); //打开商品信息文件store.txt
if(! iofile)
{ cerr<cstruct.num_store) //如果库存小于临界值,则警告
{ cout<>date_now; //读取当前日期 //将当前日期分解为年、月、日
day1=date_now-(date_now/100)*100;
month1=(date_now-(date_now/10000)*10000-day1)/100;
year1=date_now/10000;
while(year1<2000||year1>2050||month1<1||month1>12||day1<1||day1<31)
{ //检查当前日期输入
cout<<"输入当前日期错误,请重新输入:";
cin>>date_now;
day1=date_now-(date_now/100)*100;
month1=(date_now-(date_now/10000)*10000-day1)/100;
year1=date_now/10000;
}
day2=date_in-(date_in/100)*100; //将进货日期分解为年、月、日
month2=(date_in-(date_in/10000)*10000-day2)/100;
year2=date_in/10000;
//计算当前日期与进货时间的天数差
daysx=((year1-year2)*12+(month1-month2))*30+(day1-day2);
day3=deadline-(deadline/100)*100; //将保质期分解为年、月、日
month3=(deadline-(deadline/10000)*10000-day3)/100;
year3=deadline/10000;
daysy=year3*365+month3*30+day3; //将保质期转换为天数
daysz=daysy-daysx; //计算是否过期
if(daysz>0) //未过期
cout<>scode; //获取当前节令代码
while (scode!='1' && scode!='2' && scode!='3' && scode!='4')
//检查输入的节令码
{ cin>>scode;
}
scode-=48; //将节令代码由字符转换为数字
if(season_code==0||season_code==scode) //如果服装无节令或与当前节令相符汤锋
cout<>ch1;
while(ch1!='1' && ch1!='2' && ch1!='3' )
{cin>>ch1;}
//—————1.人事管理功能模块——————
if(ch1=='1')
{
while (true) //建立循环操作
{
cout<>ch2;
while(ch2!='1' && ch2!='2' && ch2!='3' && //检查输入
ch2!='4' && ch2!='5' && ch2!='6'){
cin>>ch2;
}
if(ch2=='1')em1.addemployee(); //增加员工信息 else if (ch2=='2')em1.delemployee(); //删除员工信息 else if (ch2=='3') //员工职务变化 {
cout<>namestr;
cout<<"请输入员工现在的柜组代码(1.食品;2.服装;3.电器):"; cin>>gcode;
while(gcode!='1' && gcode!='2' && gcode!='3' ) //检查输入 {
cin>>gcode;
}
gcode-=48; //将字符转化为数字 cout<>scode;
while (scode!='1' && scode!='2' && scode!='3' )
{
cin>>scode;
}
scode-=48; //将字符转化为数字 em1.statuschange(namestr,gcode,scode);
}
else if (ch2=='4') //计算员工工资 {
cout<>namestr;
scode=em1.findstatus(namestr,&num); //查找员工职务代码 if(scode==1) //员工为售货员 {
sm1.countsalary(namestr,num); sm1.recordsalary();
}
else if(scode==2) //员工为经理
{
g1.countsalary(namestr,num); m
wm1.recordsalary();
}
else if(scode==3) //员工为库管
{
wm1.countsalary(namestr,num);
wm1.recordsalary();
}}
else if(ch2=='5') //查询员工信息
{
cout<>namestr;
em1.query(namestr);
}
else break; //退出
} }
//-------2.商品管理功能模块--------
else if(ch1=='2')
{
while (true) //建立循环操作
{
cout<>ch2;
while(ch2!='1' && ch2!='2' && ch2!='3' && //检查输入
ch2!='4' && ch2!='5' && ch2!='6')
{
cin>>ch2;
}
if(ch2=='1')cm1.additem(); //增加商品信息
else if(ch2=='2')cm1.delitem(); //减少商品信息
else if(ch2=='3')cm1.delitem(); //检查库存
else if(ch2=='4') //检查商品保质期或节令
{cout<>namestr;
//查询商品的类型
tcode=cm1.findtype(namestr,&datein,&dline,&season);
if(tcode==1)fd1.checkquality(namestr,datein,dline); //商品为食品 else if(tcode==2) dr1.checkquality(namestr,season); //商品为服装 else if(tcode==3) ap1.checkquality(namestr); //商品为电器 else cout<>namestr;
cm1.query(namestr);
}
else break; //退出
}
}
//-------------------3.退出---------------------
else break;
}
}
本文档为【C++大作业】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。