Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <string.h>
- using namespace std;
- class Car {
- protected:
- int pos;
- public:
- Car(); // По умолчанию, позиция машины равна 0
- void move(int direction); // Сдвинуться по числовой прямой на расстояние direction
- // Если direction < 0, то влево
- // Если direction > 0, то вправо
- int get_position(); // Узнать текущую позицию автомобиля
- };
- void Car::move(int direction)
- {
- pos += direction;
- }
- int Car::get_position()
- {
- return pos;
- }
- Car::Car()
- {
- pos = 0;
- }
- int main()
- {
- Car car;
- int cnt; cin >> cnt;
- for (int i=0; i<cnt; i++)
- {
- char com[1024];
- cin >> com;
- if (!strcmp(com, "MOVE"))
- {
- int num; cin >> num;
- car.move(num);
- }
- if (!strcmp(com, "POSITION"))
- {
- cout << car.get_position() << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement