In: Computer Science
Question 21
You cannot nest structures.
Question 21 options:
True | |
False |
Question 22
A structure is useful when the program needs to store different values of different types in a single collection.
Question 22 options:
True | |
False |
Question 23
mystring.find(str, x) returns the first position at or beyond position x where the string str is found in mystring. str may be either a string object or a character array
Question 23 options:
True | |
False |
Question 24
Given the code snippet below, What prints?
string str = "C++ Programming is awesome";
for (int i = 0; i < str.size(); i++)
{
if (str[i] == 'a')
{
++ count;
}
if (i% 3 == 0)
{
++ count;
}
}
cout << "count is " << " = " << count;
Question 24 options:
11 |
|
10 |
|
5 |
|
2 |
Question 25
Passing a structure as a constant parameter allows __________________
Question 25 options:
Read-only access |
|
Waste space |
|
Slows down a program |
|
All of the above. |
Question 26
struct CityInfo
{
string cityName;
string state;
long population;
int distance;
};
Question 26 options:
CityInfo location = {"Asheville", "NC", 50000, 28}; |
|
CityInfo location = {"Asheville", "NC}; |
|
CityInfo location = {"Asheville", "NC", , 28}; |
|
CityInfo location = {"Asheville"}; |
Question 27
If one address comes before another address in memory, the second address is considered the “greater than” the first.
Question 27 options:
True | |
False |
Question 28
The code snippet below converts all upper characters to lower characters
for (int i=0; i<strlen(str); i++)
{
if (isupper(str[i]))
str[i] = str[i] - 32;
}
Question 28 options:
True | |
False |
Question 29
Question 29 options:
Use the correct function to read a line of text which is put in by the user.
string fullName;
cout << "Type your full name: ";
(cin, fullName);
cout << "Your name is: " << fullName;
Question 30
string test1 = "This is a string";
string test2 = "This is a string";
if (strcmp(test1, test2) ){ ….}
Question 30 options:
True | |
False |
Question 21:
Correct Answer: False
Explanation:
A structure is a user-defined data type that is a collection of different data types. The structure data member can be accessed by using the structure variable and dot operator or structure pointer variable and arrow operator.
The given statement is false because a structure can be nested.
Question 22:
Correct Answer: True
Explanation:
A structure is a user-defined data type that is a collection of different data types. The structure data member can be accessed by using the structure variable and dot operator or structure pointer variable and arrow operator.
So, the given statement is true.
Question 23:
Correct Answer: True
Explanation:
The method find() is used to return the first occurrence of the string and it may be string object or character array.
So, the given statement is true.
Question 24:
Correct Answer: 11
Explanation:
The string size is 26.
The first if statement as given below:
if (str[i] == 'a')
{
++count;
}
will inceament the count by 2 because the character 'a' is present two times in the given string.
The second if statement as given below:
if (i% 3 == 0)
{
++count;
}
will increment the count nine times.
The final value of count is 9+2=11.
So, only the first option is correct.