虚拟热狗店(骨架)

来源:互联网 发布:excel数据有效性应用 编辑:程序博客网 时间:2024/06/02 11:12

   我自己定义了一个热狗店的类,然后就模仿现实开店经营,每天只有一家店开门,后续会放出升级版(升级版会包括:程序会问你是否开分店,你是老板你做主,还有厨师、原料等问题),你问我为什做这个,我回答你闲的。

代码:

#include <iostream>#include <string.h>#include <time.h>#define random(x) (rand()%x)using namespace std;class HotDogStore{private:string name;static int numOFsell;int eachsell;public:HotDogStore(string n);int sell(int num);int output();static int money ;};int HotDogStore::numOFsell = 0;int HotDogStore::money = 0;int HotDogStore::output(){return numOFsell;}int HotDogStore::sell(int num){eachsell = 0;numOFsell += num;eachsell += num;money = money + eachsell * 10;return eachsell;}HotDogStore::HotDogStore(string n){name = n;}int main(){srand((int)time(NULL));HotDogStore s1("store1"), s2("store2"),s3("store3");int number, whitch,month=0;for (; month <= 12; month++){       whitch=random(4);   number = random(1000)+10;   switch (whitch)   {   case 1:cout << "Today the store whitch is opening is store1 and today sells hotdog :" << s1.sell(number); cout << endl; break;   case 2:cout << "Today the store whitch is opening is store2 and today sells hotdog :" << s2.sell(number); cout << endl; break;   case 3:cout << "Today the store whitch is opening is store3 and today sells hotdog :" << s3.sell(number); cout << endl; break;   }}cout << "This year you have sold hotdog :" << s1.output() <<"   the money that you have got is  "<<s1.money<<"  $"<<endl;system("pause");return 0;}
运行结果:



0 0
原创粉丝点击