我把程序发上来大家帮忙看下吧
#include<iostream.h>
#include<windows.h>
#include"function.h"
int main()
{
int n;
do
{
desktop();
cin>>n;
system("cls");
if(n==1)
{
input();
}
else if(n==2)
{
sort();
}
else if(n==3)
{
search();
}
else if(n==4)
{
reput();
}
}
while(n!=0);
return 0;
}
Function.h
#include<iostream.h>
#include<windows.h>
struct product
{
int code;
char name[10];
float amount;
float sales;
float stock;
}pro[5];
//……产品输入……
void input()
{
for(int i=0;i<5;i++)
{
cout<<"请输入第"<<i+1<<"种产品代码:";
cin>>pro[i].code;
cout<<"请输入第"<<i+1<<"种产品名称:";
cin>>pro[i].name;
cout<<"请输入第"<<i+1<<"种产品数量:";
cin>>pro[i].amount;
cout<<"请输入第"<<i+1<<"种产品销售量:";
cin>>pro[i].sales;
pro[i].stock=pro[i].amount-pro[i].sales;
system("cls");
}
}
//……产品库存量升序排列
void sort()
{
product temp;
for(int i=0;i<5-1;i++)
for(int j=i+1;j<=5-1;j++)
if(pro[i].stock>pro[j].stock)
{
temp=pro[i];
pro[i]=pro[j];
pro[j]=temp;
}
for(int j=0;j<=5-1;j++)
{
cout<<"库存量排第"<<j+1<<"种产品的库存是"<<pro[j].stock<<endl;
cout<<"代码是"<<pro[j].code<<endl;
cout<<"名称是"<<pro[j].name<<endl;
cout<<"数量是"<<pro[j].amount<<endl;
cout<<"销售量是"<<pro[j].sales<<endl<<endl;
}
system("pause");
system("cls");
}
//……产品代码查找……
void search()
{
int code[5]={1,2,3,4,5};
bool flag=0;
int b;
cout<<"请输入要查询的代码为:";
cin>>b;
for(int i=0;i<5;++i)
if(b==pro[i].code)
{
flag=1;
cout<<"产品代码:"<<pro[i].code<<" "
<<"名称:"<<pro[i].name<<" "
<<"数量:"<<pro[i].amount<<" "
<<"销售量:"<<pro[i].sales<<endl;
}
if(flag==0)
cout<<"此代码不存在!"<<endl;
system("pause");
system("cls");
}
//……修改已输入产品信息
void reput()
{
int code;
cout<<"已输入产品代码分别是:"<<endl;
for(int k=0;k<=5-1;k++)
cout<<pro[k].code<<endl;
cout<<"您要修改的产品代码是多少?"<<endl;
cin>>code;
for(int i=0;i<=4;i++)
{
if (pro[i].code==code)
break;
}
if(i==5)
cout<<"没有您要修改的产品"<<endl;
else
{
cout<<"请输入您要修改的产品的代码"<<endl;
cin>>pro[i].code;
cout<<"请输入您要修改的产品的名字"<<endl;
cin>>pro[i].name;
cout<<"请输入您要修改的产品的数量"<<endl;
cin>>pro[i].amount;
cout<<"请输入您要修改的产品的销售量"<<endl;
cin>>pro[i].sales;
pro[i].stock=pro[i].amount-pro[i].sales;
}
system("pause");
system("cls");
}
//++++++++++++++desktop+++++++++++++++
void desktop()
{
cout<<endl;
cout<<"********************欢迎进入产品管理系统********************"<<endl
<<" ***
请选择您要的服务
***"<<endl
<<" ***
1.输入产品信息
***"<<endl
<<" ***
2.查看产品信息
***"<<endl
<<" ***
3.查找产品信息
***"<<endl
<<" ***
4.修改产品信息
***"<<endl
<<"***
0.退出系统
***"<<endl
<<"***********************************************************"<<endl;
cout<<endl;
cout<<"请输入相应的代码:";
}