Question

QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...

QUESTION 1

  1. What does the following code segment output?

    int red, blue;

    red = 7;

    blue = red + 2 * 5

    red++;

    blue = blue + red;

    cout << blue;

4 points   

QUESTION 2

  1. Is the following statement true or false?

    The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values:

    int x;

    if (x >= 10 && x <= 20)

    True

    False

4 points   

QUESTION 3

  1. Give the appropriate order of steps when a C++ function call is made:

          -       1.       2.       3.       4.      

    Function return value is returned


          -       1.       2.       3.       4.      

    Function code runs


          -       1.       2.       3.       4.      

    Call by reference parameter values are returned


          -       1.       2.       3.       4.      

    Parameter passing

4 points   

QUESTION 4

  1. Which of the following C++ statement sequences has legal syntax?

    1.

    double this;

    int that;

    cin >> this >> that;

    2.

    int x, y;

    cin << x << y;

    3.

    int x, y;

    cin << "x = " << x << " y = " << y;

    4.

    int one, two;

    cin >> one, two;

4 points   

QUESTION 5

  1. What is the output from the following C++ code:

    if (7 > 3)

    cout << "Hello";

    cout << "Goodbye":

    HelloGoodbye

    [Nothing will be printed]

    Hello

    Goodbye

4 points   

QUESTION 6

  1. What does the following output?

    int x = 2;

    char letter = 'w';

    cout << letter << "x" << x;

4 points   

QUESTION 7

  1. What is the value of the following expression:

    42 % 6

4 points   

QUESTION 8

  1. Select all of the following which are legal variable names in C++.

    HELLOTHERE

    Hello There

    Hello+There

    HelloThere

    Hello_There

    Hello-There

6 points   

QUESTION 9

  1. How many times will the following code print Hello?

    int x = 2;

    do

    {

       x = x + 4;

    cout << "Hello";

    }

    while (x < 9);

4 points   

QUESTION 10

  1. Match the following variable descriptions to the appropriate C++ type.

          -       A.       B.       C.       D.   

    Baseball score

          -       A.       B.       C.       D.   

    yes or no answer

          -       A.       B.       C.       D.   

    last name initial

          -       A.       B.       C.       D.   

    price of a gallon of gas

    A.

    double

    B.

    bool

    C.

    char

    D.

    int

4 points   

QUESTION 11

  1. Given the following control associated with a for statement, how many times will the loop code execute?

    int x;

    for (x = 2; x < 6; x++)

4 points   

QUESTION 12

  1. Consider the following function call (assume that the call is correct):

    answer = myFun (x, y, z);

    Indicate whether the following statement is true or false:

    Parameters x, y, and z will be passed by position to the three parameters in the function definition of myFun.

    True

    False

4 points   

QUESTION 13

  1. Consider the following function call (assume that the call is correct):

    answer = myFun (x, y, z);

    Indicate whether the following statement is true or false:

    The return value from myFun will be assigned to answer.

    True

    False

4 points   

QUESTION 14

  1. Match the statement type to the description.

          -       A.       B.       C.       D.       E.   

    Assignment

          -       A.       B.       C.       D.       E.   

    do-while

          -       A.       B.       C.       D.       E.   

    while

          -       A.       B.       C.       D.       E.   

    if-else

          -       A.       B.       C.       D.       E.   

    switch

    A.

    Conditional statement that makes choices based on Boolean expressions

    B.

    Conditional statement which makes a choice based on matching

    C.

    Repetitive statement with Boolean expression at the top

    D.

    Repetitive statement which executes at least one

    E.

    Gives a value to a variable

5 points   

QUESTION 15

  1. Show the output for the following code. Use a '$' character to represent each space. Assume all other code is correct and the iomanip library has been included.

    double x = 7.6;

    cout << showpoint << fixed << setprecision (3);

    cout << setw (6) << x;

4 points   

QUESTION 16

  1. What will be the value of x after the following code executes:

    int x;

    x = 3;

    x += 7;

    x = x - 2;

4 points   

QUESTION 17

  1. Is the following statement true or false?

    When we have the following start of a switch statement:

    switch (var)

    it is legal C++ for var to be of type int.

    True

    False

4 points   

QUESTION 18

  1. Here is a C++ function protoype:

    int runOut (double x, int& y);

    Which of the following could possibly be a legal call to the function runOut?

    z = runOut (x, y, z);

    runOut (x, &y);

    cow = runOut (y, x);

    y = runOut (x);

4 points   

QUESTION 19

  1. Is the following statement true or false?

    The Boolean expression in the following if statement will be true for all integer values of x in the range from 1 to 3 (including the endpoints) and false for all other values:

    int x;

    if (x == 1 || 2 || 3)

    True

    False

4 points   

QUESTION 20

  1. What is the output for the following code:

    if (!(7 < 10))

    cout << "blue";

    else

    {

    cout << "red";

    cout << "green";

    }

    red

    blue

    redgreen

    green

4 points   

QUESTION 21

  1. What value should a running sum variable be initialized to?

4 points   

QUESTION 22

  1. What will be printed by the following code segment:

    int x = 5;

    while (x < 30)

    {

       x = x + 9;

    }

    cout << x;

4 points   

QUESTION 23

  1. Is the following statement true or false?

    C++ is case sensitive in regards to variable names.

    True

    False

2 points   

QUESTION 24

  1. What is the typical ordering of the following function parts in a C++ program?

          -       1.       2.       3.      

    call


          -       1.       2.       3.      

    prototype


          -       1.       2.       3.      

    definition

3 points   

QUESTION 25

  1. What will be the value of x after the following statements execute:

    int x;

    x = 2 * 3 - 15 / 5 + 2 * 4;

Homework Answers

Answer #1

int red, blue; // Two variable named red and blue is declared

red = 7; // 7 is assigned to red variable

blue = red + 2 *5; // * has higher presedence than +, so blue = 7 + (2 * 5) = 17

red ++ ; // Value of red is incremented by 1, so now red contains 8.

blue = blue + red; // Previously blue = 17, red = 8, Now blue = 17 + 8 = 25

cout<<blue; // This will print the value of blue variable which is 25. So answer is 25.

2. Answer: True

if (x > = 10 && x<=20) // This means x can take any integer value between 10 and 20 and including 10 and 20. So if statement is true for all values of x in range from 10 to 20, including 10 and 20.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item = 0; 4. while (count < 4) { 5.      cout << "Enter item cost: "; 6.      cin >> item; 7.      item_total += item; 8.      ++count; 9. } 10. int average_cost = round(item_total / count); 11. cout << "Total cost: " << item_total << "\nAverage cost: " << average_cost; (Refer to Code Example 8-1.) If the user enters 5, 10, and 15 at the prompts, the output is: Total...
Please find the errors of the following code a) int x[5]; int k = 10; for...
Please find the errors of the following code a) int x[5]; int k = 10; for (k = 0; k <= 5; k++) { x[k] = k -1; } b) int x[5]; for (k = 1; k <= 5; k++) { cout << x[k-1] << endl; } c) int x[5]={1,2,3,4,5}, y[5]; y = x; for (k = 0; k < 5; k++) { cout << y[k] << endl; } d) int size; cin >> size; int myArr[size];
(C++ program) Use the code segment below to answer the two questions that follow. … int...
(C++ program) Use the code segment below to answer the two questions that follow. … int size = 0; cout << “Enter size: “; cin >> size; int sizeCode = size / 10; if (sizeCode == 0)    cout << “extra small”; else if(sizeCode == 1 )    cout << “small”; else if (sizeCode == 2)    cout << “medium”; else if (sizeCode == 3)    cout << “large”; else    cout << “extra large”; //end if … What would...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
C++ question. Please explain the code and how it resulted in the output. Explain each line...
C++ question. Please explain the code and how it resulted in the output. Explain each line along with the aspects of "buffers" if possible. Everything is listed below. Code below: #include <iostream> #include <string> using namespace std; int main() {    cout << boolalpha;    cout << static_cast<bool>(1) << endl;    cout << static_cast<bool>(0) << endl;    string s = "AAARGH!!!";    if (s.find("AAA")) { cout << 1 << endl; }    if (s.find("RGH")) { cout << 2 << endl;...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
How do I make this code not include negative numbers in the total or average if...
How do I make this code not include negative numbers in the total or average if they are entered? (C++) For example, if you enter 4, 2, and -2, the average should not factor in the -2 and would be equal to 3. I want the code to factor in positive numbers only. ----- #include using namespace std; int main() {    int x, total = 0, count = 0;       cout << "Type in first value ";   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT