C++ class representing a steam locomotive
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
C++ class representing a steam locomotive
- Assistant
Here is an example of a C++ class that could represent a steam locomotive:
codeclass SteamLocomotive { public: // Constructor SteamLocomotive(int max_speed, int num_wheels, int max_boiler_pressure); // Member functions void setSpeed(int speed); int getSpeed() const; void setBoilerPressure(int pressure); int getBoilerPressure() const; void blowWhistle(); private: // Member variables int max_speed_; int num_wheels_; int max_boiler_pressure_; int speed_; int boiler_pressure_; }; // Constructor implementation SteamLocomotive::SteamLocomotive(int max_speed, int num_wheels, int max_boiler_pressure) : max_speed_(max_speed), num_wheels_(num_wheels), max_boiler_pressure_(max_boiler_pressure), speed_(0), boiler_pressure_(0) {} // Member function implementations void SteamLocomotive::setSpeed(int speed) { if (speed <= max_speed_) { speed_ = speed; } } int SteamLocomotive::getSpeed() const { return speed_; } void SteamLocomotive::setBoilerPressure(int pressure) { if (pressure <= max_boiler_pressure_) { boiler_pressure_ = pressure; } } int SteamLocomotive::getBoilerPressure() const { return boiler_pressure_; } void SteamLocomotive::blowWhistle() { std::cout << "Toot! Toot!" << std::endl; }This class has a constructor that initializes the maximum speed, number of wheels, and maximum boiler pressure of the steam locomotive. It also has member functions for setting and getting the current speed and boiler pressure, as well as a function for blowing the whistle.
- User
can you add a member variable to represent the amount of fuel and water in the locomotive
- Assistant
Certainly! Here is an updated version of the
SteamLocomotiveclass with member variables for the amount of fuel and water:code - User
instead of number of wheels can we change it to 3 variables for leading wheels, drive wheels, and trailing wheels
- Assistant
Certainly! Here is an updated version of the
SteamLocomotiveclass with member variables for the number of leading wheels, drive wheels, and trailing wheels:code
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.