Unknown model· unknown
from NVIDIA HelpSteer3 Preference
C++ class representing a steam locomotive
- User
C++ class representing a steam locomotive
- Assistant
Certainly! Below is an example of a C++ class representing a steam locomotive. This class includes basic attributes such as the locomotive's name, type, year of manufacture, and some methods to interact with these attributes.
cpp#include <iostream> #include <string> class SteamLocomotive { private: std::string name; std::string type; int yearOfManufacture; double maxSpeed; // in km/h double weight; // in tons public: // Constructor SteamLocomotive(const std::string& name, const std::string& type, int yearOfManufacture, double maxSpeed, double weight) : name(name), type(type), yearOfManufacture(yearOfManufacture), maxSpeed(maxSpeed), weight(weight) {} // Getters std::string getName() const { return name; } std::string getType() const { return type; } int getYearOfManufacture() const { return yearOfManufacture; } double getMaxSpeed() const { return maxSpeed; } double getWeight() const { return weight; } // Setters void setName(const std::string& name) { this->name = name; } void setType(const std::string& type) { this->type = type; } void setYearOfManufacture(int yearOfManufacture) { this->yearOfManufacture = yearOfManufacture; } void setMaxSpeed(double maxSpeed) { this->maxSpeed = maxSpeed; } void setWeight(double weight) { this->weight = weight; } // Method to display locomotive details void displayDetails() const { std::cout << "Name: " << name << std::endl; std::cout << "Type: " << type << std::endl; std::cout << "Year of Manufacture: " << yearOfManufacture << std::endl; std::cout << "Max Speed: " << maxSpeed << " km/h" << std::endl; std::cout << "Weight: " << weight << " tons" << std::endl; } }; int main() { // Create a steam locomotive object SteamLocomotive locomotive("Flying Scotsman", "4-6-2", 1923, 160.9, 96.0); // Display locomotive details locomotive.displayDetails(); // Modify some attributes locomotive.setName("Mallard"); locomotive.setYearOfManufacture(1938); // Display updated details std::cout << "\nUpdated Details:\n"; locomotive.displayDetails(); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.