当前位置:网站首页 / 其它技术 / 正文

饮料贩卖机系统 c++ 开发

时间:2015年06月20日 | 作者 : lovean | 分类 : 其它技术 | 浏览: 3106次 | 评论 0

/*
*类的实现
*
*1:饮料价格,饮料数量,饮料类型
*
*2:进货类构造函数,出货的成员函数
*
*3:对文件的读取,把构造好的对象读入到文件中
*
*4:读取时通过对对象的读取
*
*
*/

#include<iostream>
#include<fstream>
#include <cstdlib>
using namespace std;
static int n=0;//静态累计函数
class yl{
public:
//进货构造函数---需要考虑再次进货的问题
void yl1(string name1,int num1,double jg1){
        name=name1;
        num=num1;
        jg=jg1;
        n++;
}
void display(){
        cout<<"商品名称:"<<name<<"商品价格:"<<jg<<"商品数量:"<<num<<endl;
}
string disname(){
        return name;
}
int disnum(){
        return num;
}
int disjg(){
        return jg;
}
//比较函数
int bj(string name1){
        if(name1==name){
                return 1;
        }else{
                return 0;
        }
}
//修改数量
void xgsl(int i){
        num=num+i;
}
void cl(int i){
        num=num-i;
}
yl(){}
//出货时的成员函数--需要考虑出货不能大于总数
private:
        //是个成员:价格,类型,数量
        string name;//名称
        double jg;//价格
        int num;//数量

}hw[100];//定义100个对象

//新增
void xz(){
         int main();
        fstream both("sp.txt",ios::app);
        int num,i;
        char x;
        string name1;
        double jg1;
        int num1;
        if(!both){
                cout<<"文件打开失败"<<endl;
        }
        cout<<"请输入你要新增的数量"<<endl;
        cin>>num;
        cout<<"请按顺序输入商品名称,价格和数量"<<endl;
        for(i=0;i<num;i++){
                cin>>name1>>jg1>>num1;
                hw[n].yl1(name1,num1,jg1);
                both<<"商品名字:"<<name1<<"商品数量:"<<num1<<"商品价格:"<<jg1<<endl;
        }
        both.close();
        cout<<"****************************"<<endl;
        cout<<"*   输入任意键进入控制台   *"<<endl;
        cout<<"****************************"<<endl;
        cin>>x;
        if(x)main();
}
//加货
void jiah(){
        string name1,name2;
        int i;
        int z;
        int num1;
        cout<<"请输入你要添加的饮料名称"<<endl;
        cin>>name1;
        for(i=0;i<n;i++){
                if(hw[i].bj(name1)==1){
                                cout<<"请输入你要增加的数量"<<endl;
                                cin>>z;
                        hw[i].xgsl(z);
                        break;
                }

        }
        //读入文件
        fstream both1("sp.txt");
        if(!both1){
                cout<<"文件打开失败"<<endl;
        }
        for(i=0;i<n;i++){
                both1<<"商品名字:"<<hw[i].disname()<<"商品数量:"<<hw[i].disnum()<<"商品价格:"<<hw[i].disjg()<<endl;
        }
        both1.close();
        int main();
        main();
}
//显示函数
xs(){
        int main();
        void ch();
        int i;
        int x;
        for(i=0;i<n;i++){
                hw[i].display();
        }
        cout<<"**********************************************"<<endl;
        cout<<"* 1.进入主菜单 * * 2.进入贩卖 * * 3.进入加货 *"<<endl;
        cout<<"**********************************************"<<endl;
        cin>>x;
        switch(x){
                case 1:main();
                break;
                case 2:ch();
                break;
                case 3:jiah();
                break;
                default:cout<<"输入错误,自动进入主菜单"<<endl;main();
        }
        main();
}
//jh()系统是进货系统
/*
进货系统需要解决的问题
1:商品的新增
2:商品的数量的添加
*/
void  jh(){
        cout<<"*****************************************************"<<endl;
        cout<<"           *********************************         "<<endl;
        cout<<"           *   1.新增   2.修改     3.显示  *         "<<endl;
        cout<<"           *********************************         "<<endl;
        cout<<"*****************************************************"<<endl;
        int num;
        cin>>num;
        switch(num){
                case 1:xz();//新增
                break;
                case 2:jiah();//加货
                break;
                case 3:xs();//显示
                break;
                default:cout<<"你输入的内容不存在,请重新输入"<<endl;jh();
        }

}
//出货
void ch(){
        string name1;
        int i;
        int u;
        int num1;
        int p;
        int money;
        //考虑的问题是:需要什么饮料,收钱,找零
        cout<<"请输入你要的饮料"<<endl;
        cin>>name1;
        //查找饮料
        for(i=0;i<n;i++){
                if(hw[i].bj(name1)==1){
                        cout<<"已经找到,请输入需要的数量"<<endl;
                                cin>>num1;
                        if(hw[i].disnum()>=num1){
                                cout<<"有货,请放入现金"<<endl;
                                cin>>money;
                                //判断钱是否够
                                if(hw[i].disjg()*num1<=money){
                                        cout<<"出货成功,找零"<<money-hw[i].disjg()*num1<<endl;
                                        hw[i].cl(num1);
                                        fstream  both2("sp.txt",ios::out);
                                                if(!both2){
                                                        cout<<"文件内容删除失败!"<<endl;
                                                }

                                                both2.close();
                                                 fstream both3("sp.txt");
                                                if(!both3){
                                                        cout<<"文件打开失败"<<endl;
                                                }
                                        for(u=0;u<n;u++){
                                                both3<<"商品名字:"<<hw[u].disname()<<"商品数量:"<<hw[u].disnum()<<"商品价格:"<<hw[u].disjg()<<endl;
                                        }
                                }

                                        cout<<"请按任意键退出"<<endl;
                                        cin>>p;
                                        if(p)exit(0);
                        }else{
                                        cout<<"对不起,付款不成功,请重新选择!"<<endl;
                                        ch();

                                }

                }
        }

        cout<<"货物不存在或者没有这么多货,请选择其他货物"<<endl;
        cout<<"按1键回到查询页面"<<endl;
        cin>>p;
        if(p==1){
                ch();
        }

}



main(){
        int  a;
        //两个功能进货和出货
        cout<<"********************欢迎使用饮料机管理系统********************"<<endl;
        cout<<"*****************制作人:lovean,曹露乙,顾凯燕******************"<<endl;
        cout<<"**********************制作时间:2015-6-16*********************"<<endl;
        cout<<"**************************************************************"<<endl;
        cout<<"                      ********************                    "<<endl;
        cout<<"                      *    请选择功能    *                    "<<endl;
        cout<<"                      ********************                    "<<endl;
        cout<<endl;
        cout<<"            ********                ********                  "<<endl;
        cout<<"            *1.进货*                *2.贩卖*                  "<<endl;
        cout<<"            ********                ********                  "<<endl;
        cout<<endl;
        cout<<"***************************************************************"<<endl;
        cin>>a;
        fstream both3("sp.txt",ios::out);
        if(!both3){
                cout<<"文件打开失败!"<<endl;
        }
        switch(a){
                case 1:jh();break;
                case 2:ch();break;
                default:cout<<"您输入的内容不存在请重新输入!"<<endl;main();
        }
}





本站采用阿里云服务器,如果你也想使用阿里云服务器,可以点击领取代金券/优惠券



猜你喜欢

额 本文暂时没人评论 来添加一个吧

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

友情链接