散分!!!!提问。。。。。。。。。。。
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <string>
using namespace std;
class Consumer
{
public:
Consumer ()
:_flag (true)
{
cout<<"consumer"<<endl;
}
void SetFlag (bool flag) { _flag = flag;}
bool GetFlag () {return _flag;}
private:
bool _flag;
};
class Goods
{
public:
Goods (string name, double)
:_name (name),_price (price) {}
string Name () {return _name;}
double Price () {return _price;}
private:
string _name;
double _price;
};
Goods merchandise [5] = {Goods("Apple", 2.0),Goods("orange",1.8),Goods("pig",16.2),
Goods("Cake",6.4),Goods"pear",1.4};
class Shopping
{
public:
Shopping ()
{}
Consumer * GetConsumer () {return _consumer;}
private:
Consumer _consumer [5];
};
class Process
{
public:
Process (Shopping shopping)
: _shopping (shopping)
{}
~Process ();
int Run ( );
private:
Shopping _shopping;
}
int Process::Run ( )
{
while (getch() != 'Q')
{
cout<<"Wellcome our client!"<<endl;
for (int i = 0; i<5; ++i)
{
int j = rand ()*5;
if (_shopping.GetConsumer()[j].GetFlag() != false)
{
cout<<"You are our "<< i <<" client"
<<"Please come in"<<endl;
cout<<"OK,take your time."<<endl;
int kig = rand()*5;
int num = rand()*5;
cout<<"the "<<j<<" client"
<<"have bought" << kig
<<"Kilogram"<<merchandise[num].Name()
<<endl;
cout<<"OK,lets go to the counts!";
cout<<"Your should pay for "
<<kig * merchandise[i].Price ()
<<endl;
cout<<"Wellcome to come again next time!";
_shopping.GetConsumer()[j].SetFlag(false);
}
}
}
return 0;
}
int main()
{
Shopping myClient;
Process process (myClient);
process::Run ();
return 0;
}