定义的外部变量:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int n=0;
int chemise_n=0;
int cabinet_n=0;
int hat_n=0;
定义的货物头文件:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
extern int n;
extern int chemise_n;
extern int cabinet_n;
extern int hat_n;
class Goods
{
public:
char gn[40];
char gi[40];
char* goodsname;
char* goodsId;
float buyin;//当前进货
float sellout;//当前出货
float weight;//当前总库存
float totalbuyin;//总进货
float totalsellout;//总出货
public:
Goods()
{
buyin=0;
weight=0;
sellout=0;
totalbuyin=0;
totalsellout=0;
}
/*Goods(char* gn,char* gi,float gw=0,float b=0,float s=0)
{
strcpy(goodsname,gn);
strcpy(goodsId,gi);
weight=gw;
buyin=b;
sellout=s;
}*/
void setgn();
void buy();
void sell();
float total(); //显示当前货物的库存
void show();
protected:
};
void Goods::setgn()
{
cout<<"请输入货物名:";
cin>>gn;
cout<<"请输入货物条形码:";
cin>>gi;
cout<<"请输入货物重量:";
cin>>buyin;
/*cout<<strlen(gn)+1<<endl;*/
/*cout<<goodsname<<endl;
cout<<goodsId<<endl;
cout<<&goodsname<<endl;
cout<<&goodsId<<endl;
show();*/
weight=buyin;
totalbuyin=buyin;
}
void Goods::buy()
{
float b;
cout<<"请输入卖入货物的重量 :";
cin>>b;
totalbuyin=totalbuyin+b;
weight=weight+b;
cout<<"此次进货"<<b<<"千克"<<endl;
cout<<"到目前为止,总进货量为:"<<totalbuyin<<"千克"<<endl;
}
void Goods::sell()
{
float s;
cout<<"请输入卖出货物的重量 :";
cin>>s;
totalsellout=totalsellout+s;
weight=weight-s;
cout<<"此次卖出货物"<<s<<"千克"<<endl;
cout<<"到目前为止,总销货量为:"<<totalsellout<<"千克"<<endl;
}
float Goods::total()
{
return weight;
}
void Goods::show()
{
cout<<goodsId<<" "<<goodsname<<" "<<weight<<" 千克"<<endl;
}
class chemise
{
public:
char gn[40];
char gi[40];
float price ;
char product_area[50];
char materiel[20];
char* goodsname;
char* goodsId;
int buyin;//当前进货
int sellout;//当前出货
int amount;
int totalbuyin;//总进货
int totalsellout;//总出货
chemise()
{
price=0;
buyin=0;
amount=0;
sellout=0;
totalbuyin=0;
totalsellout=0;
}
void setgn();
void set_materiel();
void buy();
void sell();
float total(); //显示当前货物的库存
void show();
};
void chemise::setgn()
{
cout<<"请输入货物名:";
cin>>gn;
cout<<"请输入货物条形码:";
cin>>gi;
cout<<"请输入单价:";
cin>>price;
cout<<"请输入产地:";
cin>>product_area;
cou