标签:
一. 功能描述
某小型公司,主要有四类人员:经理、兼职技术人员、销售经理和兼职推销员。现在,需要存储这些人员的姓名、编号、级别、当月薪水,计算月薪总额并显示全部信息。
要求:
(1)其中,人员编号在生成人员信息时同时生成,每输入一个人员信息编号顺序加1。
(2)程序对所有人员有提升级别的功能
(3)月薪的计算方法是:经理拿固定月薪,兼职技术人员按工作小时数领取月薪,兼职推销员的报酬按该推销员当月销售额提成 ,销售经理既拿固定月薪也领取销售提成。
(4)能按姓名或者编号显示、查找、增加、删除和保存各类人员的信息 。
二. 概要设计
2.1 类的设计
2.2 流程图
(1)主函数流程图
(2)添加函数(左图)和删除函数(右图)的流程图
(3)查询函数流程图
三. 详细设计
1. 主函数设计
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>
#include<string.h>
#include<dos.h>
void main()
{ system("cls");
cout<<"\n\n\n\n\t\t********************************************\n"
<<"\t\t* *\n" <<"\t\t* *\n"
<<"\t\t* 欢迎使用小型超市商品销售管理系统(HYY) *\n"
<<"\t\t* *\n"
<<"\t\t* Desined by 王曰芳 206050529 *\n"
<<"\t\t* *\n"
<<"\t\t* (按任意键进入) *\n"
<<"\t\t* *\n"
<<"\t\t* *\n"
<<"\t\t********************************************\n"<<endl;
getch();
food f;
makeup m;
drink d;
live l;
while(1)
{A:
system("cls");
int choice;
int x;
cout<<"\n\n\t\t\t\t主菜单"<<"\n\n\t\t\t\t(1)添加商品品种\n" <<"\n\t\t\t\t(2)查询商品\n"
<<"\n\t\t\t\t(3)删除商品"<<"\n\n\t\t\t\t(4)退出"<<"\n\n\n请选择:"; cin>>x;
switch(x)
{ case 1:
{system("cls");
cout<<"\n\n\n\n\n\n\t\t请选择添加哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;
cin>>choice;
switch(choice)
{case 1:
system("cls");
f.addf();
break;
case 2:
system("cls");
m.addm();
break;
case 3:
system("cls");
d.addd();
break;
case 4:
system("cls"); l
.addl();
break;
case 5:
system("cls");
break;
}
break;
}
case 2:
{system("cls");
cout<<"\n\n\n\n\n\n\t\t请选择查询哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;
cin>>choice;
switch(choice)
{case 1:
system("cls");
f.searchf();
break;
case 2:
system("cls");
m.searchm()
break;
case 3:
system("cls");
d.searchd();
break;
case 4:
system("cls"); l
l.searchl();
break;
case 5:
system("cls");
break;
}
break;
}
case 3:
{system("cls");
cout<<"\n\n\n\n\n\n\t\t请选择删除哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;
cin>>choice;
switch(choice)
{case 1:
system("cls");
f.removef();
break;
case 2:
system("cls");
m.removem();
break;
case 3:
system("cls");
d.removed();
break;
case 4:
system("cls"); l
l.removel();
break;
case 5:
system("cls");
break;
}
break;
}
case 4:
{system("cls");
cout<<"\n\n\n\n\n\n\t\t\t\t谢谢使用!"<<"\n\n\t\t\t\t再见!\n";
exit(1);
}
break;
default:
{cout<<"输入有误,请重选!";
goto A;
}
}
}
}
上面即为主函数,通过switch语句来选择操作:添加,查询,删除,退出。在每项操作中又用switch语句来选择对哪一类商品进行操作,分别有食品,化妆品,饮料,生活用品四类。该函数没有把“显示商品利润”作为一项单独操作,而是把该功能加进了“查询”操作中,查询的同时直接显示商品利润。
class spbase
{public:
int t;
float oprice;
float iprice;
float prof;
int quantity;
char name[10];
void getdate();
void showdate();
void add();
void search();
void remove();
gett(){return t;}
};
oid spbase::getdate() //输入函数的设计
{ cout<<"\n\t\t请输入商品名称:";
cin>>name;
cout<<"\n\t\t请输入商品售价:";
cin>>oprice;
cout<<"\n\t\t请输入商品进价:";
cin>>iprice;
cout<<"\n\t\t请输入商品库存量:";
cin>>quantity;
}
void spbase::showdate() //输出函数的设计
{ cout<<"\n\n商品基本信息如下:";
cout<<"\n\n\t\t商品名称:";
cout<<name;
cout<<"\n\n\t\t商品售价:";
cout<<oprice;
cout<<"\n\n\t\t商品进价:";
cout<<iprice;
cout<<"\n\n\t\t商品库存量:";
cout<<quantity;
prof=(oprice-iprice)*quantity;
cout<<"\n\n\t\t商品利润为 :";
cout<<prof;
}
void spbase::add() //添加函数的设计
{ t=1;
ofstream file("HYY.txt",ios::out|ios::ate);
if(!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
spbase p1;
p1.getdate();
file.write(reinterpret_cast<char*>(&p1),sizeof(spbase)); //
reinterpret_cast强制转换
file.close();
}
void spbase::search() //查询函数的设计
{
char name4[10];
cout<<"\n请输入生活用品名称:";
cin>>name4;
fstream file("HYY.txt",ios::in);
if (!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
char flag=‘a‘; //设标志位
spbase p1;
file.read(reinterpret_cast<char*>(&p1),sizeof(spbase));
while(!file.eof()) //正确显示,指针还没到
末尾继续
{ if((strcmp(p1.name,name4)==0)&&gett())
{p1.showdate();
getch();
flag=‘z‘;
break;
}
file.read(reinterpret_cast<char*>(&p1),sizeof(spbase));
}
if(flag!=‘z‘)
{ cout<<("该商品已被删除!");
getch();
}
file.close();
}
void spbase::remove() //删除函数的设计
{ t=0;search();}
3. 食品类设计(food)
class food:public spbase
{ private:
char pfs[10];
public:
void getdatef()
{ spbase::getdate();
cout<<"\n\t\t请输入商品批发商:";
cin>>pfs;
}
void showdatef()
{ spbase::showdate();
cout<<"\n\n\t\t商品批发商:";
cout<<pfs;
}
void addf()
{ t=1;
ofstream file("HYY1.txt",ios::out|ios::ate);
if(!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
food f;
f.getdatef();
file.write(reinterpret_cast<char*>(&f),sizeof(food));
file.close();
}
void searchf()
{ char name1[10];
cout<<"\n请输入食品名称:";
cin>>name1;
fstream file("HYY1.txt",ios::in);
if (!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
char flag=‘a‘;
food f;
file.read(reinterpret_cast<char*>(&f),sizeof(food));
while(!file.eof())
{ if((strcmp(f.name,name1)==0)&&gett())
{f.showdatef();
getch();
flag=‘z‘;
break;
}
file.read(reinterpret_cast<char*>(&f),sizeof(food));
}
if(flag!=‘z‘)
{ cout<<("该商品已被删除!");
getch();
}
file.close();
}
void removef()
{ t=0;searchf();}
}
class makeup:public spbase
{ private:
char pp[10];
public:
void getdatem()
{ spbase::getdate();
cout<<"\n\t\t请输入商品品牌:";
cin>>pp;
}
void showdatem()
{ spbase::showdate();
cout<<"\n\n\t\t商品品牌:";
cout<<pp;
}
void addm()
{ t=1;
ofstream file("HYY2.txt",ios::out|ios::ate);
if(!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
makeup m;
m.getdatem();
file.write(reinterpret_cast<char*>(&m),sizeof(makeup));
file.close();
}
void searchm()
{ char name2[10];
cout<<"\n请输入化妆品名称:";
cin>>name2;
fstream file("HYY2.txt",ios::in);
if (!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
char flag=‘a‘;
makeup m;
file.read(reinterpret_cast<char*>(&m),sizeof(makeup));
while(!file.eof())
{ if((strcmp(m.name,name2)==0))
{m.showdatem();
getch();
flag=‘z‘;
break;
}
file.read(reinterpret_cast<char*>(&m),sizeof(makeup));
}
if(flag!=‘z‘)
{ cout<<("该商品已被删除!");
getch();
}
file.close();
}
void removem()
{ t=0;searchm();}
};
5. 饮料类设计(drink)
class drink:public spbase
{ private:
char factory[10];
public:
void getdated()
{ spbase::getdate();
cout<<"\n\t\t请输入商品生产厂家:";
cin>>factory;
}
void showdated()
{ spbase::showdate();
cout<<"\n\n\t\t商品生产厂家:";
cout<<factory; }
void addd()
{ t=1;
20
file.read(reinterpret_cast<char*>(&m),sizeof(makeup)); }
if(flag!=‘z‘)
{ cout<<("该商品已被删除!"); getch(); }
file.close(); }
void removem() { t=0;searchm();}
};
5. 饮料类设计(drink)
class drink:public spbase { private:
char factory[10]; public:
void getdated()
{ spbase::getdate();
cout<<"\n\t\t请输入商品生产厂家:"; cin>>factory; }
void showdated()
{ spbase::showdate();
cout<<"\n\n\t\t商品生产厂家:";
cout<<factory; }
void addd()
{ t=1;
ofstream file("HYY3.txt",ios::out|ios::ate);
if(!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
drink d;
d.getdated();
file.write(reinterpret_cast<char*>(&d),sizeof(drink));
file.close();
}
void searchd()
{ char name3[10];
cout<<"\n请输入饮料名称:";
cin>>name3;
fstream file("HYY3.txt",ios::in);
if (!file)
{cout<<"文件打开失败!";
getch();
exit(1);
}
char flag=‘a‘;
drink d;
file.read(reinterpret_cast<char*>(&d),sizeof(drink));
while(!file.eof())
{ if((strcmp(d.name,name3)==0))
{d.showdated();
getch();
flag=‘z‘;
break; }
file.read(reinterpret_cast<char*>(&d),sizeof(drink));
}
if(flag!=‘z‘)
{ cout<<("该商品已被删除!");
getch();
}
file.close();
}
void removed()
{ t=0;searchd();
}
};
22
class live:public spbase
{
public:
void getdatel()
{ spbase::getdate();
}
void showdatel()
{ spbase::showdate();
}
void addl()
{ spbase::add();
}
void searchl()
{ spbase::search();
}
void removel()
{spbase::remove();
}
};
23
四.效果及存在问题
4.1 效果截屏
进入主界面
github链接:https://github.com/wangyuefang/chaoshi/blob/master/zhu
https://github.com/wangyuefang/chaoshi/blob/master/lei
标签:
原文地址:http://www.cnblogs.com/tuanduiboke123/p/4574971.html