运行 ❯
获取您
自己的
网站
×
更改方向
更改主题,深色/浅色
前往 Spaces
#include <iostream> using namespace std; class Car { // The class public: // Access specifier string brand; // Attribute string model; // Attribute int year; // Attribute Car(string x, string y, int z) { // Constructor with parameters brand = x; model = y; year = z; } }; int main() { // Create Car objects and call the constructor with different values Car carObj1("BMW", "X5", 1999); Car carObj2("Ford", "Mustang", 1969); // Print values cout << carObj1.brand << " " << carObj1.model << " " << carObj1.year << "\n"; cout << carObj2.brand << " " << carObj2.model << " " << carObj2.year << "\n"; return 0; }
BMW X5 1999
福特 Mustang 1969