0
0
C++programming~10 mins

Why object-oriented programming is used in C++ - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a class named Car.

C++
class [1] {
public:
    int speed;
};
Drag options to blanks, or click blank then click option'
Acar
BVehicle
CCar
DSpeed
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase or unrelated names for the class.
2fill in blank
medium

Complete the code to create an object named myCar of class Car.

C++
Car [1];
Drag options to blanks, or click blank then click option'
AmyCar
Bcar1
Cspeed
DCar
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the class name instead of the object name.
3fill in blank
hard

Fix the error in the code to access the speed attribute of myCar.

C++
myCar.[1] = 100;
Drag options to blanks, or click blank then click option'
Aspeed()
Bspeed
CSpeed
DgetSpeed
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using uppercase or method-like syntax for attributes.
4fill in blank
hard

Fill both blanks to define a method named accelerate that increases speed by 10.

C++
void [1]() {
    speed [2] 10;
}
Drag options to blanks, or click blank then click option'
Aaccelerate
B+=
C-=
Dspeed
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using subtraction operator or wrong method name.
5fill in blank
hard

Fill all three blanks to create an object and call its accelerate method.

C++
Car [1];
[2].speed = 50;
[3]();
Drag options to blanks, or click blank then click option'
AmyCar
Daccelerate
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different object names or missing parentheses when calling methods.