Created
December 24, 2019 05:21
-
-
Save DNDK/5b2c4ea436cb11ceaa89dfda817b49c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include "petshop.h" | |
#include <ctime> | |
#include <iterator> | |
using namespace std; | |
static int money = 100; | |
int buy(){ | |
srand(time(NULL)); | |
if(money<=100){ | |
return 20+rand()%90; | |
} | |
else if(money<=150){ | |
return 50+rand()%130; | |
} | |
else{ | |
return 90+rand()%150; | |
} | |
} | |
int main(){ | |
string type, sex; | |
int price; | |
string cmd; | |
cout<<"Your current money is $100\n\n"; | |
vector <Animal> pets; | |
int counter = 0; | |
//commandline | |
cout<<"==================================\n" | |
"| WELCOME TO THE PETSHOP_TERMINAL|\n" | |
"==================================\n"; | |
cout<<"Type '/help' to see a commands list\n\n"; | |
while(cmd != "/q"){ | |
cout<<"Enter a command \n >"; | |
cin>>cmd; | |
if(cmd!="/q"){ | |
if(cmd == "/help"){ | |
cout<<"\t\t\t COMMANDS: \t\t\t\n" | |
"/buy - buy a new animal\n" | |
"/sell - try to sell each animal(50% success)\n" | |
"/sellshop - Sell a petshop. (All the animals will be returned to the shelter)"; | |
} | |
else if(cmd == "/buy"){ | |
cout<<" Buy an animal:\n" | |
"Enter a type of animal \n>";cin>>type; | |
cout<<"\nEnter it's sex:\n>";cin>>sex; | |
cout<<"\nEnter it's price(how many you want for it):\n>";cin>>price; | |
int *c = new int; | |
*c = buy(); | |
if(*c > money){ | |
cout<<"Oops.. This animal is too expensive for you. ($"<<*c<<")"; | |
} | |
else{ | |
Animal pet(type,sex,price); | |
pets.push_back(pet); | |
cout<<"Animal was bought sucessfull. It's number: "<<counter +1; | |
counter++; | |
money-=*c; | |
} | |
cout<<"Your money is: "<<money; | |
} | |
else if(cmd == "/sell"){ | |
unsigned int ind; | |
cout<<"Enter a number of animal you want to sell:\n>"; | |
cin>>ind; | |
money+=pets[ind-1]._price(); | |
pets.erase(pets.begin()+(ind-1)); | |
counter--; | |
cout<<"Pet has been sold sucessful..."; | |
} | |
else if(cmd == "/sellpetshop"){ | |
if(pets.size()<=10){ | |
money+=300; | |
} | |
else if(pets.size()<=20){ | |
money+=600; | |
} | |
else{ | |
money += 1199; | |
} | |
cout<<"You've sold petshop...\n\n"; | |
break; | |
} | |
} | |
else{ | |
cout<<"\nBYE"; | |
break; | |
} | |
} | |
cout<<"Your money is "<<money<<" you're so rich! :)"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PETSHOP_H | |
#define PETSHOP_H | |
#include <vector> | |
#include <string> | |
#include <fstream> | |
#include <map> | |
#include <ctime> | |
using namespace std; | |
class Animal{ | |
private: | |
string type; | |
string sex; | |
int price; | |
public: | |
//constructor | |
Animal(string type, string sex, int price){ | |
this->type = type; | |
this->sex = sex; | |
this->price = price; | |
} | |
~Animal(){} | |
string _type(){ | |
return type; | |
} | |
string _sex(){ | |
return sex; | |
} | |
int _price(){ | |
return price; | |
} | |
auto sell(){ | |
srand(time(NULL)); | |
return rand()%2; | |
} | |
auto buy_ware(int x){ | |
return 10*x ; | |
} | |
}; | |
#endif // PETSHOP_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment