1.
Can you use the += operator to concatenate strings?
Correct Answer
B. No
Explanation
The += operator in most programming languages is used to add or concatenate values together. However, in some programming languages, like Python, the += operator cannot be used to concatenate strings. Instead, the + operator is used for string concatenation. Therefore, the correct answer is "No".
2.
You can access a string or an array element by providing an index number inside a what?
Correct Answer
B. Subscripting operator
Explanation
The correct answer is "subscripting operator". This is because when accessing a string or an array element, we use square brackets [] to provide the index number. The subscripting operator allows us to retrieve a specific element from a string or an array by specifying its index.
3.
Objects are entities that combine data and functions.example: ship.energyexample: ship.fireWeapons() A data element of an object is called what?
Correct Answer
data member
Data Member
Data member
Explanation
In object-oriented programming, a data element of an object is referred to as a data member. It is a variable that holds data specific to each instance of the object. Data members are used to represent the state or characteristics of an object. They can be accessed and modified using the object's methods or functions. In the given example, "ship.energy" represents a data member that holds the energy level of the ship.
4.
Objects are entities that combine data and functions.example: ship.energyexample: ship.fireWeapons() A function of an object is called what?
Correct Answer
Member Function
member function
Member function
Explanation
The function of an object is called a member function. It is a function that is defined within a class or object and can access the data and other member functions of that class. In the given example, ship.fireWeapons() is a member function of the ship object, which combines the action of firing weapons with the ship's data, such as energy.
5.
Arrays provide a way to store and access sequences of any type.
Correct Answer
A. True
Explanation
Arrays are a data structure that allows for the storage and retrieval of sequences of any type. This means that arrays can be used to store and access multiple values of the same or different data types in a sequential manner. Therefore, the statement that arrays provide a way to store and access sequences of any type is true.
6.
Bounds checking is done when you compile a program.
Correct Answer
B. False
Explanation
Bounds checking is not done when you compile a program. Bounds checking is a runtime feature that checks whether an array index or pointer is within the valid range of memory locations. It is typically performed during program execution to catch potential errors such as accessing memory beyond the allocated space for an array. Compilation, on the other hand, is the process of translating source code into machine code or bytecode, and it does not involve runtime checks like bounds checking. Therefore, the correct answer is False.
7.
for loops are often used for counting or looping through a sequence.
Correct Answer
A. True
Explanation
For loops are commonly used in programming to iterate over a sequence of elements, such as a list or an array. They provide a convenient way to perform repetitive tasks, such as counting or performing operations on each element of the sequence. By using a for loop, you can specify the number of iterations and easily access each element in the sequence. Therefore, the statement "for loops are often used for counting or looping through a sequence" is true.
8.
The empty() member function returns a true value if the string object is empty and false otherwise.example: spaceship.empty()
Correct Answer
A. True
Explanation
The empty() member function is used to check if a string object is empty or not. In this case, the function spaceship.empty() is being called. If the string object spaceship is empty, the function will return true. Therefore, the correct answer is true.
9.
You can use the break; and continue; commands in a for loop.
Correct Answer
A. True
Explanation
In a for loop, the break command is used to exit the loop prematurely, while the continue command is used to skip the current iteration and move to the next one. Therefore, both break and continue commands can be used in a for loop to control the flow of execution based on certain conditions. Hence, the statement "You can use the break and continue commands in a for loop" is true.
10.
To get the number of characters in a string, you could use the ________ function or the ________ function.
Correct Answer
size
length
Explanation
To get the number of characters in a string, you could use the size function or the length function. Both functions can be used to determine the length of a string. The size function returns the number of characters in the string, while the length function also includes any whitespace characters. Therefore, either of these functions can be used to obtain the desired result.