Question

Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item...

  1. 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 cost: 30
    Average cost: 7
    Which line should be changed to fix this logic error?

    a.

    change line 1 to: int count = 0;

    b.

    change line 10 to: int average_cost = round(item_total / (count - 1));

    c.

    change line 7 to: item_total += item - 1;

    d.

    change line 4 to: while (count <= 4) {

1.5 points   

QUESTION 31

  1. Given the following Product structure:
    struct Product {
        string name;
        double price;
        int quantity;
        bool operator==(const Product& to_compare) {
            return (name == to_compare.name && price == to_compare.price);
        }

    };
    what statement would you use to test if two Product objects named p1 and p2 are equal?

    a.

    bool duplicate = (p1 operator== p2);

    b.

    bool duplicate = p1.==(p2);

    c.

    bool duplicate = p1.operator==(p2);

    d.

    bool duplicate = (p1 == p2);

1.5 points   

QUESTION 32

  1. When you use the Visual Studio or Xcode debugger, you start by setting a breakpoint

    a.

    on the definition for the function that you think is causing the bug

    b.

    on a comment line

    c.

    on the statement you believe is causing the bug

    d.

    on a statement before the statement you think is causing the bug

1.5 points   

QUESTION 33

  1. What are the values of the elements in the queue named products after the following code is executed?
    queue<string> products;
    products.push("hammer");
    products.push("nails");
    products.push("wrench");
    products.pop();

    a.

    hammer, nails, wrench

    b.

    wrench, nails, hammer

    c.

    nails, wrench

    d.

    nails, hammer

1.5 points   

QUESTION 34

  1. When you code a member function for a structure, you must

    a.

    declare it within the structure declaration

    b.

    define it within the structure declaration

    c.

    both a and b

1.5 points   

QUESTION 35

  1. Code Example 8-2
    1. /* This application displays a student's score after a 5-point curve */
    2.
    3. void display_info(string fname, string lname, int score) {
    4.      cout << "Hello, " << fname << ' ' << Lname;
    5.      cout << "Your score on this is " << score;
    6.      score = score + 5;
    7. }
    8.
    9. int main() {
    10.     string first, last;
    11.     int score = 0;
    12.     cout << "first name: ";
    13.     cin >> first;
    14.     cout << "last name: ";
    15.     cin >> last;
    16.     cout << " score: ";
    17.     cin >> grade;

    18.     display_info(first, last, score);
    19. }

    (Refer to Code Example 8-2.) Assuming the compile-time errors have been fixed, what is the logic error in this program?

    a.

    The arguments are listed in the wrong order.

    b.

    The curve is calculated after the score has been displayed.

    c.

    The display_info() function should be called before the input statements that start on line 11.

    d.

    There is no logic error in this program.

1.5 points   

QUESTION 36

  1. Code Example 9-1
    struct Product {
        string name;
        double price;
        int quantity;

    };

    (Refer to Code Example 9-1.) What happens if you try to compare two Product objects using the following code?
    Product p1 = { "hammer", 14.99, 15 };
    Product p2 = { "hammer", 16.29, 12 };
    if (p1 == p2) {
        cout << "The products are equal.";
    }
    else {
        cout << "The products are not equal.";
    }

    a.

    A compile-time error occurs because there is no equality operator for the Product structure.

    b.

    It displays a message that the products are not equal because they have different prices and quantities.

    c.

    It displays a message that the products are equal because the have the same name.

1.5 points   

QUESTION 37

  1. An enumeration contains enumerators that represent

    a.

    the variables for the enumeration

    b.

    the operators for the enumeration

    c.

    the functions for the enumeration

    d.

    the constants for the enumeration

1.5 points   

QUESTION 38

  1. What are the values of the elements in the stack named products after the following code is executed?
    stack<string> products;
    products.push("hammer");
    products.push("nails");
    products.push("wrench");
    products.pop();

    a.

    nails, hammer

    b.

    hammer, nails, wrench

    c.

    wrench, nails, hammer

    d.

    nails, wrench

1.5 points   

QUESTION 39

  1. Which of the following containers is a fixed-size collection of elements that’s stored in contiguous memory?

    a.

    array

    b.

    deque

    c.

    list

    d.

    map

Homework Answers

Answer #1

(30)   
(b) change line 10 to: int average_cost = round(item_total / (count - 1));

(31)
struct Product {
    string name;
    double price;
    int quantity;
    bool operator==(const Product& to_compare) {
        return (name == to_compare.name && price == to_compare.price);
    }
};
(d)bool duplicate = (p1 == p2);

(32)(d)on a statement before the statement you think is causing the bug

(33)the values of the elements in the queue named products
(c)nails, wrench

(34)c.    both a and b

(35)d. There is no logic error in this program.

(36) a. A compile-time error occurs because there is no equality operator for the Product structure.

(37)    d. the constants for the enumeration

(38)a.    nails, hammer

(39) a. array

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
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 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 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 >=...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...