Devry Comp122 midterm exam

Question # 00086955 Posted By: neil2103 Updated on: 08/01/2015 08:06 AM Due on: 08/28/2015
Subject Computer Science Topic General Computer Science Tutorials:
Question
Dot Image

Page: 1 2 3

Question 1. Question :

(TCO 1) Which of these is a legal identifier in C++?

: GPD*7

payRate-2

ID_1

3rdVar

Question 2. Question :

(TCO 1) Which of the following identifies syntax errors in programs written in a high-level language?

: Assembler

Compiler

Preprocessor

Linker

Question 3. Question :

(TCO 1) For the values given, what will c contain after executing the following?

int a = 9, b = 4, c = -1;

c -= a % b;

: -1

-2

-3

1

Question 4. Question :

(TCO 1) For the values given, what will c contain after executing the following?

int a = 9, b = 4, c = -1;

c += b++ * a;

: 45

36

44

35

Question 5. Question :

(TCO 1) A percent sign (%) is called

: the percent operator.

the modulo operator.

the divide operator.

None of the above

Question 6. Question :

(TCO 1) What is the result of 66 % 5?

: 13

13.2

1

2

Question 7. Question :

(TCO 1) What is the output for the following code fragment?

int var1 = 20;

cout << var1--;

cout << ++var1;

: 1920

1921

2020

2021

Question 8. Question :

(TCO 1) Which operation in the following expression will be performed first?

c = ++a / b + 5;

: ++a

IN a / b

b + 5

assignment to c

Question 9. Question :

(TCO 2) The endl manipulator _______.

: requires #include <iomanip>

is used with cout to display a new line

only works with cin statements

All of the above

Question 10. Question :

(TCO 2) A user inputs his name in response to a prompt for a numeric value. The subsequent cin statement tries to get a numeric value and store it into an integer variable. How does a program detect this input error and clear it?

: The cin input stream is broken, the application must be restarted.

cin.fail() detects a failure and cin.clear() clears the failure.

IN Use cin.fail() to detect the failure and cin.ignore() to clear the failure.

Use cin.ignore() to detect and clear the failure.

Question 11. Question :

(TCO 2) Which statement outputs a double value in a field of seven characters with four digits after the decimal point?

: cout << 7chars << 4digits << 1.2345678;

cout << fixed << setprecision(4) << 1.2345;

cout << setprecision(7) << setw(4) << 1.2345;

cout << setprecision(4) << setw(7) << 1.2345678;

Page: 1 2 3

Page: 1 2 3

Question 1. Question :

(TCO 2) What are the values of the variables after the code fragment below executes if the input data is 37 86.56 32?

int x, y;

double z;

cin >> x;

cin >> z;

cin >> y;

: x = 37, y = 86.56, z = 32

x = 37, y = 32, z = 86.56

x = 37, y = 86, z = 32

x = 37, y = 86, z = 56

Question 2. Question :

(TCO 10) For readability, all statements inside an if statement body should be

: IN indented the same distance as the if statement.

surrounded by an open and closing parenthesis.

indented by one additional tab stop more than the if statement.

written on the same line.

Question 3. Question :

(TCO 10) Which of the following ly adds a comment to the end of a line of code?

: IN a = b * c; \\ comment here

a = b * c; /* comment here

a = b * c; // comment here

a = b * c; \* comment here

Instructor Explanation: Stroustrup, Chapter 3

Points Received: 0 of 5

Comments:

Question 4. Question :

(TCO 3) Based on input of a single digit code, your program must output the full name of a US state plus other information about the state based on its population category. The best selection structure to use to program this situation is _______.

: a SWITCH statement

multiple IF statements

nested IF statements

multiple IF ELSE statements

Question 5. Question :

(TCO 3) Which statement ly tests int variable var to be outside the range from 0 to 100? Note that 0 and 100 are considered to be within the range.

: if(100 < var && var < 0)

if(100 < var || var < 0)

if(0 <= var <= 100)

if(0 <= var && var <= 100)

Question 6. Question :

(TCO 3) Which of the following values of the variable code will produce the same output for the two code fragments?

if(code < 1) if(code < 1)

cout << "First"; cout << "First";

if(code < 2) else if(code < 2)

cout << "Second"; cout << "Second";

if(code < 3) else

cout << "Third"; cout << "Third";

: 0

IN 1

2

None of the above

Question 7. Question :

(TCO 3) What is the value of beta after the following code executes if the input is 3?

int beta;

cin >> beta;

switch(beta)

{

case 3:

beta += 3;

case 1:

beta++;

break;

case 5:

beta += 5;

case 4:

beta += 4;

}

: IN 16

6

7

4

Question 8. Question :

(TCO 4) Your program must repeat a set of tasks exactly 15 times. Which looping construct is best suited for this situation?

: for

IN do while

while

any of the above

Question 9. Question :

(TCO 4) How many times does the following loop body execute?

int count = 52;

for(int i = 26; i >= 0; i--)

{

cout << count << endl;

--count;

}

: 26

IN 52

27

None of the above

Question 10. Question :

(TCO 4) When the ________ statement is executed in a loop body, the remaining statements in the loop body are skipped and control proceeds with the next iteration of the loop.

: continue

break

eof

conditional

Question 11. Question :

(TCO 4) Why is this code snippet an infinite loop?

char answer = 'y';

while (answer == 'y' || answer = 'Y')

{

cout << "Still in loop" << endl;

cout << "Continue? (y for yes, n for no)" << endl;

cin >> answer;

}

: The first line sets the value of answer to 'y' and, once the loop is entered, can never be changed

It is a sentinel-controlled loop, but the user is never asked to enter data.

The test expression always evaluates to TRUE because the value of the right-hand expression is the ASCII code for Y, which is non-zero, and anything other than zero is TRUE.

None of the above: it is not an infinite loop; it repeats until the user enters anything other than the letter y (either upper or lower case).

Page: 1 2 3

Page: 1 2 3

Question 1. Question :

(TCO 4) What is the output from the following loop if the input is 5 10 2 3 -1 ?

Question 2. Question :

(TCO 3) A program has a char variable response that has been assigned a value. Write a switch statement that outputs "Yes" if the variable contains lower or upper case 'y', "No" if it contains lower or upper case 'n', or "Invalid Input" for any other value.

Question 3. Question :

(TCO 3) Create a complete C++ program that prompts the user to enter his or her height in inches and outputs the following:

Output "Height is six feet or more." when the user's height is 6 feet or more.

Output "Height is less than five feet." when the user's height is less than 5 feet.

Output "Height is at least five feet but less than 6 feet" otherwise.

Question 4. Question :

(TCO 3) Write a complete program for Visual C++ to calculate and display the volume of a cylinder, given its radius and height. Your program must meet the following requirements:

· Your program should prompt the user to input the radius and height. The program should output the result with three digits after the decimal point. The output should include some explanatory text.

· Make the value of PI (3.14159) a constant in your program.

· The volume formula is PI * radius2 * height.

· Valid input is any real number greater than 0 for the radius and height of the cylinder. Your program should consider a negative input as an error and output an error statement. Do not do any calculations in this case.

· Make sure you use the appropriate data types for everything.

Question 5. Question :

(TCO 4) Create a C++ program that uses a while-loop to display the odd numbers between 15 and 30 including 15. The numbers should be displayed one per line.

Question 6. Question :

(TCO 4) Write a complete C++ program that meets the following criteria:

· Use the Pythagorean theorem to calculate the length of the hypotenuse of a right triangle given the two sides. (hypotenuse = sqrt( side12 + side22 ) )

· The length of side1 should range from 1 to and including 10 incrementing by 1.

· The length of side2 should be twice the length of side1.

· You must use a for loop for this program.

· Declare all variables you use to be the appropriate type.

· There is no cin in this program!

· Display the value of the hypotenuse with 3 digits after the decimal point.

Dot Image
Tutorials for this Question
  1. Tutorial # 00081455 Posted By: neil2103 Posted on: 08/01/2015 08:06 AM
    Puchased By: 3
    Tutorial Preview
    The solution of Devry Comp122 midterm exam...
    Attachments
    Comp122_mid_term_(1).docx (22.15 KB)
    Recent Feedback
    Rated By Feedback Comments Rated On
    jb...sar Rating Great services and offers 09/01/2015

Great! We have found the solution of this question!

Whatsapp Lisa