Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Topic 7: Functions

Question 1

Correct2.50 points out of 2.50Flag question

Question text

The following is an example of a function stub:

int CountOfAlpha(string input) {

   int count = 0;

   int i = 0;

   for(i = 0; i < input.length(); ++i) {

       if (isalpha(input.at(i))) {

           ++count;

       }

   }

   return count;

}Select one:a. Trueb. False 

Correct

Feedback

The correct answer is: False

Question 2

Correct2.50 points out of 2.50Flag question

Question text

Which function is called in the following code?

double CalcFt(double inches) {

   return inches * 12.0;

}

int CalcFt(int inches) {

   return inches * 12;

}

int main() {

   int inches = 24;

   cout << CalcFt(24);

   return 0;

}Select one:a. double CalcFt(double inches)b. int CalcFt(int inches) 

Correct

c. Both functions are called.d. Error: Cannot given same name to multiple functions.

Feedback

The correct answer is: int CalcFt(int inches)

Question 3

Incorrect0.00 points out of 2.50Flag question

Question text

void PrintName() {

   cout << “First name is Tom.\n”;

   cout << “Last name is Jones.” << endl;

   return;

}

int main() {

   PrintName();

   PrintName();

   return 0;

}

How many output statements would execute in total?Select one:a. 1b. 2 

Incorrect

c. 4d. 8

Feedback

The correct answer is: 4

Question 4

Correct2.50 points out of 2.50Flag question

Question text

What will GetInput return if the user enters 363?

int GetInput() {

   int val = 0;

   cin >> val;

   if( val > 100 ) {

       val = 100;

   }

   return val;

}Select one:a. No return because there will be a compilation error.b. No return because there will be a run-time error.c. 363d. 100 

Correct

Feedback

The correct answer is: 100

Question 5

Incorrect0.00 points out of 2.50Flag question

Question text

Where does the preprocessor look for “std” in the line:

using namespace std;Select one:a. The same directory/folder as the including file.b. The system’s standard library directory/folder. 

Incorrect

c. Custom files cannot be included without < > notation.d. Nowhere, preprocessor only looks at lines starting with #.

Feedback

The correct answer is: Nowhere, preprocessor only looks at lines starting with #.

Question 6

Correct2.50 points out of 2.50Flag question

Question text

Why use modular compilation?Select one:a. To improve the executable’s computation performance.b. To reduce the time required to recompile the executable. 

Correct

c. To save the programmer the hassle of finding all the dependencies.d. Because file linking is necessary.

Feedback

The correct answer is: To reduce the time required to recompile the executable.

Question 7

Correct2.50 points out of 2.50Flag question

Question text

Which of the following functions correctly passes in a constant pass-by-value vector of integers:Select one:a. void myFunction(const vector<int> nums) 

Correct

b. void myFunction(const vector<int>& nums)c. void myFunction(vector<int> const nums)d. void myFunction(vector<const int>& nums)

Feedback

The correct answer is: void myFunction(const vector<int> nums)

Question 8

Correct2.50 points out of 2.50Flag question

Question text

Which warning message best describes the following code:

char GetInput() {

   char usr=’\0’;

   cin >> usr;

   if( !isalpha(usr) ) {

       usr = ‘a’;

   }

}Select one:a. Cannot assign a value inside a branch.b. Control reaches end of non-void function. 

Correct

c. Too many arguments to function ‘isalpha’.d. If-statement expecting else statement.

Feedback

The correct answer is: Control reaches end of non-void function.

Question 9

Incorrect0.00 points out of 2.50Flag question

Question text

Given the following makefile:

driveSim.exe : main.o carFcts.o

    g++ main.o carFcts.o -o driveSim.exe    # (1)

main.o : main.cpp carFcts.h

    g++ -Wall -c main.cpp             # (2)

carFcts.o : carFcts.cpp carFcts.h

    g++ -Wall -c carFcts.cpp            # (3)

Assume that make has already run. Which commands will be executed if carFcts.cpp is changed and make is called?Select one:a. (1), (2), (3) 

Incorrect

b. (2), (3)c. (1), (2)d. (1), (3)

Feedback

The correct answer is: (1), (3)

Question 10

Incorrect0.00 points out of 2.50Flag question

Question text

What is output by the following code:

char colorsStr[25] = “blue and yellow.”;

cout << strlen(colorsStr);Select one:a. 16b. 17c. 24d. 25 

Incorrect

Feedback

The correct answer is: 16

Question 11

Correct2.50 points out of 2.50Flag question

Question text

Which statement contains a common error or mistake with functions?

double AreaOfCircle(double radius) {

   const double pi = 3.14159265; 

   double area = 0.0;

   double temp = 0.0;

   temp = pow(radius, 2);

   area = pi * temp;

   return radius;  

}Select one:a. const double pi = 3.14159265;b. temp = pow(radius, 2);c. return radius; 

Correct

d. No errors or mistakes.

Feedback

The correct answer is: return radius;

Question 12

Correct2.50 points out of 2.50Flag question

Question text

Given the command-line argument:

myprog.exe “Jane Doe” 23 “Ben Smith” 22

What is the output of the following program myprog.exe?

int main(int argc, char* argv[]) {

   cout << argc;

   return;

}Select one:a. 2b. 3c. 4d. 5 

Correct

Feedback

The correct answer is: 5

Question 13

Incorrect0.00 points out of 2.50Flag question

Question text

What is the output of the following code?

void PrintInches(int ft, int inch) {

   int inches = ft*12 + inch;

   cout << inches;

   return;

}

int main() {

   int feet = 1;

   int inches = 6;

   PrintInches(feet, inches);

   return 0;

}Select one:a. No output. A function cannot have multiple parameters 

Incorrect

b. 7c. 18d. 24

Feedback

The correct answer is: 18

Question 14

Incorrect0.00 points out of 2.50Flag question

Question text

Which of the following functions is most appropriate and most modular for a function that calculates the total and median of three ints: x, y, and z?Select one:a. void MyFct(int x, int y, int z, int &total, int &median) 

Incorrect

b. int MyFct(int x, int y, int z, int &total)c. void MyFct(int x, int y, int z)d. Multiple functions should be used.

Feedback

The correct answer is: Multiple functions should be used.

Question 15

Incorrect0.00 points out of 2.50Flag question

Question text

How many elements are needed to store the string “Thursday” within a char array?Select one:a. 7b. 8 

Incorrect

c. 9d. 12

Feedback

The correct answer is: 9

Question 16

Incorrect0.00 points out of 2.50Flag question

Question text

To what value does the function evaluate? Using 1 for true, 0 for false. Assume str is

“Testing 1 2 3…”.

isspace(str[8])Select one:a. 1 

Incorrect

b. 0c. ‘1’d. ‘g’

Feedback

The correct answer is: 0

Question 17

Correct2.50 points out of 2.50Flag question

Question text

Which of the following is NOT a benefit of separate files:Select one:a. Separate files insures that main does not grow too large.b. Separate files increases compilation speed.c. Separate files allows the separated files to be used in other programs.d. All of the above are benefits. 

Correct

Feedback

The correct answer is: All of the above are benefits.

Question 18

Correct2.50 points out of 2.50Flag question

Question text

Determine whether the following is a valid beginning of a function definition.

void PrintValues(double x, int y)Select one:a. Valid 

Correct

b. Invalid

Feedback

The correct answer is: Valid

Question 19

Correct2.50 points out of 2.50Flag question

Question text

What is the output of the following code?

int ConvertMinSecToSec(int minutes, int seconds=30) {

    return minutes*60 + seconds;

}

int main() {

   cout << ConvertMinSecToSec(3);

   return 0;

}Select one:a. Error: too few arguments to function ‘ConvertMinSecToSec’.b. Inconsistent returned value ‘seconds’ in uninitialized.c. 180d. 210 

Correct

Feedback

The correct answer is: 210

Question 20

Correct2.50 points out of 2.50Flag question

Question text

The function PrintVals is an example of a function prototype:

void PrintVals(int v1, int v2);

int main() {

   PrintVals(5, 7);

   return 0;

}Select one:a. True 

Correct

b. False

Feedback

The correct answer is: True

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"