在线等,我已做了部分,但有好多错误!
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
#define M 200
//可以存信息总量
int N=0;
//蔬菜总量
class vegetable
{public:
vegetable() {}
void set();//菜品信息录入功能
void display();//菜品信息显示功能
void staff_dispaly();//浏览职工信息
void search();//查询功能
void change();//修改功能
void remove();//删除菜品功能
private:
int id;
string greens,canteen,style,staff_name,staff_telnumber;
int windows,number,DurabilityPeriod,year,month,day,staff_age,staff_sex;
double price;
};
//菜品信息录入功能
void vegetable::set()
{int i,k;
string set_canteen,set_greens,set_style,set_staff_name,set_staff_telnumber;
int set_windows,set_number,set_DurabilityPeriod,set_year,set_month,set_day,set_staff_age,set_staff_sex;
double set_price;
ofstream outfile;
outfile.open("v1.txt",ios::out);//----打开文件----
if(!outfile)
{cerr<<"open error"<<endl;
exit(1);
}
//----依次录入与蔬菜相关的信息----
for(i=0;i<M;i++)
{
cout<<"当输入菜品名称为'0'时,结束输入!"<<endl;
cout<<"请输入菜品名称"<<endl;
cin>>set_greens;
greens=set_greens;
if(set_greens=="0") break;
if(set_greens!="0")
{ N++;
outfile<<set_greens<<"
";
cout<<"請输入id:"<<endl;
cin>>k;
id=k;
outfile<<k<<"
";
cout<<"请输入食堂名称"<<endl;
cin>>set_canteen;
canteen=set_canteen;
outfile<<set_canteen<<"
";
cout<<"请输入窗口名称"<<endl;
cin>>set_windows;
windows=set_windows;
outfile<<set_windows<<"
";
cout<<"请输入该菜品的价格"<<endl;
cin>>set_price;
price=set_price;
outfile<<set_price<<"
";
cout<<"请输入该菜品的菜系"<<endl;
cin>>set_style;
style=set_style;
outfile<<set_style<<"
";
cout<<"请输入该菜品的数量(以份为单位)"<<endl;
cin>>set_number;
number=set_number;
outfile<<set_number<<"
";
cout<<"请输入该菜品的保质期(多少天)"<<endl;
cin>>set_DurabilityPeriod;
DurabilityPeriod=set_DurabilityPeriod;
outfile<<set_DurabilityPeriod<<"
";
cout<<"请输入该菜品的上架时间"<<endl;
cout<<"年:";
cin>>set_year;
year=set_year;
outfile<<set_year<<"—";
cout<<"月:";
cin>>set_month;
month=set_month;
outfile<<set_month<<"—";
cout<<"日:";
cin>>set_day;
day=set_day;
outfile<<set_day<<"
";
cout<<"请输入相关的职工信息"<<endl;
cout<<"姓名:"<<endl;
cin>>set_staff_name;
staff_name=set_staff_name;
outfile<<set_staff_name<<"
";
cout<<"性别:"<<endl;
cin>>set_staff_sex;
staff_sex=set_staff_sex;
outfile<<set_staff_sex<<"
";
cout<<"年龄:"<<endl;
cin>>set_staff_age;
staff_age=set_staff_age;
outfile<<set_staff_age<<"
";
cout<<"手机:"<<endl;
cin>>set_staff_telnumber;
staff_telnumber=set_staff_telnumber;
outfile<<set_staff_telnumber<<"
";
}
}
outfile.close();
//----关闭文件----
}
//浏览职工信息
void vegetable::staff_dispaly()
{cout<<"姓名:"<<vegetable::staff_name<<endl;
cout<<"所在部门"<<vegetable::canteen<<vegetable::windows<<endl;
cout<<"性别:"<<vegetable::staff_sex<<endl;
cout<<"年龄:"<<vegetable::staff_age<<endl;
cout<<"手机::"<<vegetable::staff_telnumber<<endl;
}
//查询功能
void vegetable::search()
{
int i,n,w=0,windows[M],a[M],ch;
string search_greens,c[M],greens[M],canteen[M],price[M],style[M],number[M],DurabilityPeriod[M],time[M],b[M][M];
cout<<"1.按菜品名称查询
2.按窗口名称查询"<<endl;
ifstream infile("v1.txt",ios::in);
if(!infile)
{
cerr<<"open error"<<endl;
exit(1);
}
for(i=0;i<N;i++)
{infile>>canteen[i];c[i]=canteen[i];
infile>>windows[i];b[i][0]=windows[i];
infile>>greens[i];b[i][1]=greens[i];
infile>>style[i];b[i][2]=style[i];
infile>>number[i];b[i][3]=number[i];
infile>>price[i];b[i][4]=price[i];
infile>>time[i];b[i][5]=time[i];
infile>>DurabilityPeriod[i];b[i][6]=DurabilityPeriod[i];
}
cout<<"请输入1或者2来进行查询!"<<endl;
cin>>ch;
if(ch==1)
{
cout<<"请输入菜品名!"<<endl;
cin>>search_greens;
for(i=0;i<N;i++)
if(canteen[i]==search_greens)
{
w=1;
cout<<"
食堂
窗口
菜品
菜系
数量
价格
上架时间
保质期 "<<endl;
cout<<"
";
cout<<setw(9)<<canteen[i];
cout<<setw(9)<<b[i][0];
cout<<setw(9)<<b[i][1];
cout<<setw(9)<<b[i][2];
cout<<setw(9)<<b[i][3];
cout<<setw(9)<<b[i][4];
cout<<setw(9)<<b[i][5];
cout<<setw(9)<<b[i][6];
}
if(w==0)
cout<<"该菜品未上架!"<<endl;
}
else cout<<"选择错误!"<<endl;
if(ch==2)
{cout<<"请输入窗口名称:";
cin>>n;
for(i=0;i<N;i++)
if(a[i]==n)
{
w=1;
cout<<"
食堂
窗口
菜品
菜系
数量
价格
上架时间
保质期 "<<endl;
cout<<"
";
cout<<setw(9)<<canteen[i];
cout<<setw(9)<<b[i][0];
cout<<setw(9)<<b[i][1];
cout<<setw(9)<<b[i][2];
cout<<setw(9)<<b[i][3];
cout<<setw(9)<<b[i][4];
cout<<setw(9)<<b[i][5];
cout<<setw(12)<<b[i][6];
}
if(w==0)
cout<<"该菜品未上架!"<<endl;
}
}
//修改功能
void vegetable::change()
{
int i,k;
int id[M],windows[M];
string greens[M],canteen[M],price[M],style[M],number[M],DurabilityPeriod[M],time[M],b[M][M];
ifstream infile("v1.txt",ios::in);
if(!infile)
{
cerr<<" open error"<<endl;
exit(1);
}
for(i=0;i<N;i++)
{cout<<"
";
infile>>canteen[i];
cout<<setw(9)<<canteen[i];
infile>>windows[i];
cout<<setw(9)<<windows[i];
infile>>greens[i];
cout<<setw(9)<<greens[i];
infile>>style[i];
cout<<setw(9)<<style[i];
infile>>number[i];
cout<<setw(9)<<number[i];
infile>>price[i];
cout<<setw(9)<<price[i];
infile>>time[i];
cout<<setw(9)<<time[i];
infile>>DurabilityPeriod[i];
cout<<setw(9)<<DurabilityPeriod[i]<<endl;
}
infile.close();
ofstream outfile("v1.txt",ios::out);
if(!outfile)
{cerr<<"open erro"<<endl;
exit(1);
}
cout<<"你想修改第几个数据?"<<endl;
cin>>k;
k=k-1;
cout<<"请输入新的数据:"<<endl;
cout<<"请输入食堂名:"<<endl;
cin>>canteen[k];
cout<<"请输入窗口名:"<<endl;
cin>>windows[k];
cout<<"请输入菜品名:"<<endl;
cin>>greens[k];
cout<<"请输入菜系名:"<<endl;
cin>>style[k];
cout<<"请输入该菜品的数量(以份为单位)"<<endl;
cin>>number[k];
cout<<"请输入该菜品的价格"<<endl;
cin>>price[k];
/*cout<<"请输入该菜品的上架时间"<<endl;
cout<<"年:";
cin>>set_year;
year=set_year;
outfile<<set_year<<"—";
cout<<"月:";
cin>>set_month;
month=set_month;
outfile<<set_month<<"—";
cout<<"日:";
cin>>set_day;
day=set_day;
outfile<<set_day<<"
";
cin>>time[k];*/
cout<<"请输入该菜品的保质期"<<endl;
cin>>DurabilityPeriod[k];
for(i=0;i<N;i++)
{
outfile<<canteen[i]<<"
";
outfile<<windows[i]<<"
";
outfile<<greens[i]<<"
";
outfile<<style[i]<<"
";
outfile<<number[i]<<"
";
outfile<<price[i]<<"
";
outfile<<time[i]<<"
";
outfile<<DurabilityPeriod[i]<<"
"<<endl;
}
outfile.close();
cout<<"修改成功!"<<endl;
}