Complete the code to create an object of class Car named myCar.
class Car {}; int main() { Car [1]; return 0; }
The correct way to create an object named myCar of class Car is Car myCar;.
Complete the code to call the startEngine method on the object myCar.
class Car { public: void startEngine() {} }; int main() { Car myCar; myCar.[1](); return 0; }
To call the method startEngine on the object myCar, use myCar.startEngine();.
Fix the error in the code to access the speed attribute of the object car1.
class Car { public: int speed; }; int main() { Car car1; car1.[1] = 100; return 0; }
The attribute speed is accessed directly by car1.speed. Inside main, to assign a value, use car1.speed = 100;. The blank is for the attribute name after the dot.
Fill both blanks to create a method setSpeed that sets the speed attribute.
class Car { public: int speed; void [1](int [2]) { speed = [2]; } };
The method name is setSpeed and the parameter name is newSpeed. Inside the method, speed = newSpeed; sets the attribute.
Fill all three blanks to create an object car2, set its speed to 80, and print it.
#include <iostream> class Car { public: int speed; void setSpeed(int s) { speed = s; } int getSpeed() { return speed; } }; int main() { Car [1]; [1].[2](80); std::cout << [1].[3]() << std::endl; return 0; }
Create the object named car2. Call setSpeed(80) on it to set speed. Then call getSpeed() to get the speed and print it.