c++ Hi everyone, this is part two of multiple choice question. THERE IS 15 QUEST
ID: 643473 • Letter: C
Question
c++ Hi everyone, this is part two of multiple choice question. THERE IS 15 QUESTION, please indicate the the answear you're not sure of. THANKS IN advance.
17. Consider the implementation of the print_me function that belongs to the class named world. The numbers represent the line numbers, but are not part of the code.
1 void print_me
2 {
3 std::cout << "Hello World ";
4 }
Which line contains errors?
Select one:
a. 1
b. 4
c. 2
d. 3
18. Consider the following function implementation:
void myvariables::getvalues()
{
//local variables
int count = 1;
std::string first, last;
std::cout << ++count;
}
19. The myvariables class contains a private data member called count that is set to the value 100 before this function is called. What will be displayed?
Select one:
a. 2
b. A syntax error
c. Unpredictable
d. 1
e. 100
20. Assume no errors in the following code snippet. Which type of variable is total and what is it used for?
void scores::displayScores()
{
int total = 0;
for (int i = 0; i < numused; i++)
{
std::cout << stats[i] << std::endl;
total = total + stats[i];
}
Select one:
a. An accumulator variable. It is used to store the sum of all elements in the array.
b. A counter variable. It is used to determine the number of times the loop will repeat.
c. An initializer variable. It is used to initialize each element in the vector to a valid value.
d. None of the above
21. Consider the following function implementation. Assume that there are no errors.
void scores::displayScores()
{
for (int i = 0; i < numused; i++)
{
std::cout << stats[i] << std::endl;
}
Which type of variable is i?
Select one:
a. i is not a variable, it is a function
b. private class variable
c. local variable
d. read only variable
22. Consider the following function implementation:
void check::check_input()
{
//initialize class variable
sum = 0;
int n = -1;
}
Which type of function is check_input?
Select one:
a. nonmember function
b. local function
c. check_input is not a function, it is a variable
d. class member function
23. A class definition is typically stored in a file with the ________________filename extension.
Select one:
.header
.cpp
.h
.class
you wish to run (activate) a function called print_me and you get the following error:
error C3861: 'print_me': identifier not found
Which would be a possible reason for this error?
Select one:
a. The function call does not match the function name
b. The function is not found above the function call in the file.
c. The function may belong to a class, but no object was used to call it.
d. Any of the above.
25. Consider the following function definition that has been properly defined in the public area of the class Time in the file time.h. The sethour and setminute functions set the private data members hour and minute values.
void Time::shiftBy(int dh, int dm)
{
hour += dh;
minute += dm;
}
The main program performs the following:
#include
Explanation / Answer
=============================================================================
17. Consider the implementation of the print_me function that belongs to the class named world.
The numbers represent the line numbers, but are not part of the code.
1 void print_me
2 {
3 std::cout << "Hello World ";
4 }
Which line contains errors?
Select one:
a. 1
b. 4
c. 2
d. 3
Answer:
a. 1
Explanation:
1 void print_me is missing systax type of c++ function i.e fun()
==============================================================================
18. Consider the following function implementation:
void myvariables::getvalues()
{
//local variables
int count = 1;
std::string first, last;
std::cout << ++count;
}
Answer:
cout will print the output 2
Explanation:
Initial count value is 1,
Since pre-increment operator is used, It will increment count value to 2
and then prints on the console.
==============================================================================
19. The myvariables class contains a private data member called count that is set to the value 100 before this function is called. What will be displayed?
Select one:
a. 2
b. A syntax error
c. Unpredictable
d. 1
e. 100
Answer:
a. 2
Explanation:
Since, Even class variable is present with count name.
The functions wont consider class varibles. if the local variable with the same name.
Hence the output iwll be 2.
Suppose if you want to refer then you might need to specify this operator.
this is points to current class variable.
==============================================================================
20. Assume no errors in the following code snippet. Which type of variable is total and what is it used for?
void scores::displayScores()
{
int total = 0;
for (int i = 0; i < numused; i++)
{
std::cout << stats[i] << std::endl;
total = total + stats[i];
}
}
Select one:
a. An accumulator variable. It is used to store the sum of all elements in the array.
b. A counter variable. It is used to determine the number of times the loop will repeat.
c. An initializer variable. It is used to initialize each element in the vector to a valid value.
d. None of the above
Answer:
a. An accumulator variable. It is used to store the sum of all elements in the array.
Explanation:
Since it is storing sum of all elements in the array.
==============================================================================
21. Consider the following function implementation. Assume that there are no errors.
void scores::displayScores()
{
for (int i = 0; i < numused; i++)
{
std::cout << stats[i] << std::endl;
}
}
Which type of variable is i?
Select one:
a. i is not a variable, it is a function
b. private class variable
c. local variable
d. read only variable
Answer:
c. local variable
Explanation:
i is local variable used to iterate the total elements of array by size.
==============================================================================
22. Consider the following function implementation:
void check::check_input()
{
//initialize class variable
sum = 0;
int n = -1;
}
Which type of function is check_input?
Select one:
a. nonmember function
b. local function
c. check_input is not a function, it is a variable
d. class member function
Answer:
d. class member function
Explanation:
Since it is used as check:: ,every object of class can call this function.
==============================================================================
23. A class definition is typically stored in a file with the ________________filename extension.
Select one:
.header
.cpp
.h
.class
Answer:
.h
Explanation:
Generally The class defination is stored in header file, the file is stored
with .h extenstion.
==============================================================================
24. you wish to run (activate) a function called print_me and you get the following error:
error C3861: 'print_me': identifier not found
Which would be a possible reason for this error?
Select one:
a. The function call does not match the function name
b. The function is not found above the function call in the file.
c. The function may belong to a class, but no object was used to call it.
d. Any of the above.
Answer:
d. Any of the above.
Explanation:
In any of the case the compiler not able to call the functions due to above
mentioned reasons.
==============================================================================
25. Consider the following function definition that has been properly defined in the public
area of the class Time in the file time.h.
The sethour and setminute functions set the private data members hour and minute values.
void Time::shiftBy(int dh, int dm)
{
hour += dh;
minute += dm;
}
The main program performs the following:
#include
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.