Исправь ошибки в коде и напиши исправления по пунктам: #include <iostream> using…
- User
Исправь ошибки в коде и напиши исправления по пунктам: #include
using namespace std;
class robot { float angle_x; float angle_y; float v; float s; float time; public: robot(){}; robot(float a_x, float a_y, float ve, float dist):angle_x(a_x), angle_y(a_y), v(ve), s(dist) {} void show_robot() { cout << "angle_x = " << angle_x << endl; cout << "angle_y = " << angle_y << endl; cout << "v = " << v << endl; cout << "s = " << s << endl; cout << "time = " << time << endl; } void count_time() { time=s/v; } void limits_check() { if(angle_x >= -50 && angle_x <= 50 && angle_y <= 15 && angle_y >= -15 && v > 1 && v <= 10 && s<=100) cout << "Correct!" << endl; else cout << "Incorrect..." << endl; } }; class little_robot : public robot { string model; float capacity; float freq; float t0[3] = {0,1,1}; public: little_robot(){}; little_robot(string m, float cap, float fr):model(m), capacity(cap), freq(fr) {}; void show_little_robot() { cout << "model: " << model << endl; cout << "capacity = " << capacity << endl; cout << "frequency = " << freq << endl; cout << "start time = " << t0 << endl; } void count_all_time(float& current_t) { float c_time[3] = {current_t[0]-t0[0],current_t[1]-t0[1],current_t[2]-t0[2]}; cout << "Passed time: "; for (int i=0;i<3;i++) { cout<<c_time[i]; if (i<2) cout<<":"; } cout<< endl; } float get_capacity() {return capacity;} }; int main() { /robot toy(20,5,5,5); toy.count_time(); toy.show_robot(); toy.limits_check();/ little_robot car("gt-1000", 1500, 27) float current_t[3] = {1, 50, 35}; car.count_all_time(current_t); car.show_little_robot(); return 0; }
- Assistant
В коде присутствует несколько ошибок. Вот список исправлений по пунктам:
- Инициализация переменной
timeв конструкторе классаrobot. Значение переменнойtimeне инициализируется в конструкторе. Это может привести к отображению случайного значения при вызове функцииshow_robot.
cpp - Инициализация переменной
- User
Допиши код, чтобы можно было вводить поля класса robot для объекта класса little_robot: #include
using namespace std;
class robot { float angle_x; float angle_y; float v; float s; float time; public: robot(){}; robot(float a_x, float a_y, float ve, float dist):angle_x(a_x), angle_y(a_y), v(ve), s(dist) {} void show_robot() { cout << "angle_x = " << angle_x << endl; cout << "angle_y = " << angle_y << endl; cout << "v = " << v << endl; cout << "s = " << s << endl; cout << "time = " << time << endl; } void count_time() { time=s/v; } void limits_check() { if(angle_x >= -50 && angle_x <= 50 && angle_y <= 15 && angle_y >= -15 && v > 1 && v <= 10 && s<=100) cout << "Correct!" << endl; else cout << "Incorrect..." << endl; } }; class little_robot : public robot { string model; float capacity; float freq; float t0[3] = {0,1,1}; public: little_robot(){}; little_robot(string m, float cap, float fr):model(m), capacity(cap), freq(fr) {}; void show_little_robot() { cout << "model: " << model << endl; cout << "capacity = " << capacity << endl; cout << "frequency = " << freq << endl; for (int i=0;i<3;i++) { cout << t0[i]; if (i != 2) cout << ":"; } cout << endl; } void count_all_time(float current_t[3]) { float c_time[3]; for (int i=0; i<3; i++) { c_time[i] = current_t[i] - t0[i]; } cout << "Passed time: "; for (int i=0;i<3;i++) { cout<<c_time[i]; if (i<2) cout<<":"; } cout<< endl; } float get_capacity() {return capacity;} }; int main() { little_robot car("gt-1000", 1500, 27); float current_t[3] = {1, 50, 35}; car.count_all_time(current_t); car.show_little_robot(); car.count_time(); car.show_robot(); car.limits_check(); return 0; }
- Assistant
Чтобы позволить пользователю вводить поля класса
robotдля объекта классаlittle_robot, вы можете добавить интерактивный ввод в конструкторlittle_robot, или добавить отдельную функцию для установки этих полей. В данном случае, чтобы не мешать создание объекта с интерактивным вводом, предпочтительным будет добавление функции, которая позволяет установить значения после создания объекта.