Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class parking
- {
- private:
- string name = "Unecon_Parking";
- string location = "Griboedova_32";
- int space = 50;
- int rate = 25;
- int free_ = space; // для удобного подсчета свободных мест
- public:
- parking()
- {
- string name;
- string location;
- int space;
- int rate;
- };
- parking operator - (int arrived)
- {
- if (free_ - arrived >= 0)
- {
- free_ -= arrived;
- return *this;
- }
- else
- cout << "no parking spaces" << endl;
- }
- parking operator + (int left)
- {
- if (free_ + left <= space)
- {
- free_ += left;
- return *this;
- }
- else
- cout << "can't leave more cars than it was" << endl;
- }
- friend void set(const parking & parking_);
- friend void free_spaces(const parking & parking_);
- ~parking(){}
- };
- void set(const parking & parking_)
- {
- cout << "create new parking ..." << endl;
- cout << "name: " << parking_.name << endl;
- cout << "location: " << parking_.location << endl;
- cout << "space: " << parking_.space << endl;
- cout << "rate: " << parking_.rate << endl;
- }
- void free_spaces(const parking & parking_)
- {
- cout << "free spaces: " << parking_.free_ << endl;
- }
- int main()
- {
- int left;
- int arrived;
- int temp;
- int option = -1;
- parking parking_;
- parking free_;
- set(parking_);
- while (option != 3)
- {
- cout << "enter the option:" << endl;
- cout << "1. car arrived" << endl;
- cout << "2. car left" << endl;
- cout << "3. exit" << endl;
- cin >> option;
- switch (option)
- {
- case 1:
- cout << "cars arrived: "; cin >> arrived;
- parking_ - arrived;
- break;
- case 2:
- cout << "cars left: "; cin >> left;
- parking_ + left;
- break;
- case 3:
- break;
- }
- free_spaces(parking_);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement