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_; // для удобного подсчета свободных мест
- 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;
- }
- void set();
- void free();
- ~parking(){}
- };
- int main()
- {
- int left;
- int arrived;
- int temp;
- int option = -1;
- parking parking_;
- parking free_;
- parking_.set();
- 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;
- }
- parking_.free();
- }
- return 0;
- }
- void parking::free()
- {
- cout << "free spaces: " << free_ << endl;
- return;
- }
- void parking::set()
- {
- cout << "create new parking ..." << endl;
- cout << "name: " << name << endl;
- cout << "location: " << location << endl;
- cout << "space: " << space << endl;
- cout << "rate: " << rate << endl;
- free_ = space;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement