Untitled
unknown
plain_text
6 months ago
1.1 kB
1
Indexable
Never
#include <iostream> #include <string> class Car { public: Car(int year, const std::string& color, const std::string& engineModel, float mileage) { this->year = year; this->color = color; this->engineModel = engineModel; this->mileage = mileage; } void printFeatures() { std::cout << "Year: " << year << std::endl; std::cout << "Color: " << color << std::endl; std::cout << "Engine Model: " << engineModel << std::endl; std::cout << "Mileage: " << mileage << std::endl; } private: int year; std::string color; std::string engineModel; float mileage; }; int main() { // Creating car objects int N; std::cin >> N; Car cars[6] = { Car(1921, "Yellow", "Mc07", 67.5), Car(1922, "Red", "Mc01", 63.2), Car(1925, "Black", "Mc03", 69.7), Car(1929, "Orange", "Mc06", 70.5), Car(1932, "Maroon", "Mc04", 37.2), Car(1935, "Grey", "Mc09", 97.7) }; for (int i = 0; i < N; i++) { cars[i].printFeatures(); std::cout << std::endl; } return 0; }