标题:如何做这个课设?
只看楼主
jiekevv520
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-3-17
得分:0 
我知道这对您来说就是小菜啊!但对我这是一个大事,没有实践编程过,一直在记理论,老师布置下来一周内交,还附加5000字论文,又在我们考试周,我快疯了!求救版主大人啊!必重谢!

历史如云,我只是抬头望过,历史如雷,我只是掩耳听过!
2015-07-06 17:16
jiekevv520
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-3-17
得分:0 
我又修改了一下,帮忙看看[/code]
#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 search();//查询功能
void change();//修改功能
void remove();//删除菜品功能
private:
 int id;
string greens,canteen,style;
int windows,number,DurabilityPeriod,year,month,day;
double price;
};

//菜品信息录入功能
void vegetable::set()
{int i,set_id;
string set_canteen,set_greens,set_style;
int set_windows,set_number,set_DurabilityPeriod,set_year,set_month,set_day;
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>>set_id;
    id=set_id;
    outfile<<set_id<<"  ";
    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;
       cout<<"月:";
       cin>>set_month;      
       cout<<"日:";
       cin>>set_day;
       }
}
outfile.close();   //----关闭文件----
}

//查询功能
void vegetable::search()
{
    int i,n,w=0,windows[M],ch;
    string search_greens,c[M],greens[M],canteen[M],price[M],style[M],number[M],DurabilityPeriod[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>>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<<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;
    }

   
    if(ch==2)
    {cout<<"请输入窗口名称:";
    cin>>n;
    for(i=0;i<N;i++)
        if(windows[i]==n)
        {        w=1;
                cout<<"          食堂  窗口      菜品    菜系      数量    价格    上架时间  保质期 "<<endl;
                cout<<"          ";
                cout<<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 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;
    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<<DurabilityPeriod[i]<<"     "<<endl;
    }
    outfile.close();
    cout<<"修改成功!"<<endl;
}

//删除菜品功能
void vegetable::remove()
{
    int k,i;
int 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;
    }
    cout<<"需要删除第几个?"<<endl;
    cin>>k;
    k=k-1;
    infile.close();
    ofstream outfile("v1.txt",ios::out);
    if(!outfile)
    {
        cerr<<"open error"<<endl;
        exit(1); //退出程序
    }
//----将数组存取的信息输出到文件中去----
    for(i=0;i<N;i++)
    {
        if(i!=k)
        {
        outfile<<canteen[i]<<"     ";
        outfile<<windows[i]<<"     ";
        outfile<<greens[i]<<"     ";        
        outfile<<style[i]<<"     ";
        outfile<<number[i]<<"     ";
        outfile<<price[i]<<"     ";
        outfile<<DurabilityPeriod[i]<<"     "<<endl;
        }
    }
    outfile.close();
    N=N-1;
    cout<<"已删除成功!"<<endl;
}

//菜品信息显示功能
void vegetable::display()
{
    int k;
    int windows;
    string greens,canteen,price,style,number,DurabilityPeriod;
    ifstream infile("v1.txt",ios::in);
    if(!infile)
    {
        cerr<<" open error"<<endl;
        exit(1);
    }
    cout<<"          食堂  窗口      菜品    菜系      数量    价格    上架时间  保质期 "<<endl;
    for(k=0;k<N;k++)
    {cout<<"        ";
    infile>>canteen;
    cout<<setw(9)<<canteen;
    infile>>windows;
    cout<<setw(9)<<windows;
    infile>>greens;
    cout<<setw(9)<<greens;
    infile>>style;
    cout<<setw(9)<<style;
    infile>>number;
    cout<<setw(9)<<number;
    infile>>price;
    cout<<setw(9)<<price;
    infile>>DurabilityPeriod;
    cout<<setw(9)<<DurabilityPeriod<<endl;
    }
    infile.close();
}
    vegetable vegetable_1;
    void main()
    {
        char ch;
        void menu();
        menu();
        cin>>ch;
        while(ch!='0')
        {
            system("cls");
            switch(ch)
            {case'1':vegetable_1.set();break;
            case'2':vegetable_1.search();break;
            case'3':vegetable_1.change();break;
            case'4':vegetable_1.remove();break;
            //case'5':vegetable_1.sort();break;
            case'6':vegetable_1.display();break;
            case'0':cout<<"退出系统!";break;
            default:cout<<"没有该选项!"<<endl;break;
            }
            menu();
            cin>>ch;
        }
    }
        void menu()
        {
        cout<<"***************食堂菜品管理信息系统***************"<<endl;
        cout<<"*1.菜品信息录入功能************************"<<endl;
        cout<<"*2.查询功能(按菜品名称查询/按窗口名称查询)*"<<endl;
        cout<<"*3.修改功能********************************"<<endl;
        cout<<"*4.删除菜品功能****************************"<<endl;
        //cout<<"*     5.查询     *"<<endl;
        cout<<"*6.显示全部信息****************************"<<endl;
        cout<<"*0.退出************************************"<<endl;
        cout<<"*******************************************"<<endl;
        }

历史如云,我只是抬头望过,历史如雷,我只是掩耳听过!
2015-07-07 11:22
永夜星辰
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-7-10
得分:0 
好难
2015-07-10 20:41
菜鸟,求帮忙
Rank: 4
等 级:业余侠客
帖 子:197
专家分:267
注 册:2015-7-11
得分:0 
高手啊
2015-07-11 18:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-455113-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.208185 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved