Question

In: Computer Science

QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;...

QUESTION 60

  1. Given the following Product structure:
    struct Product {
        string name;
        double price;
        int quantity;
        bool equals(const Product&);

    };
    how would you define the equals function so two products are equal if their names and prices are equal?

    a.

    bool equals(const Product& to_compare) {
        return (name == to_compare.name && price == to_compare.price);
    }

    b.

    bool Product::equals(const Product& to_compare) {
        return (name == to_compare.name || price == to_compare.price);
    }

    c.

    bool equals(const Product& to_compare) {
        return (name == to_compare.name || price == to_compare.price);
    }

    d.

    bool Product::equals(const Product& to_compare) {
        return (name == to_compare.name && price == to_compare.price);
    }

1.5 points   

QUESTION 61

  1. What are the values of the keys in the set named years after the following code is executed?
    set<int> years { 2016, 1985, 2001 };
    years.insert(1992);
    years.insert(2001);
    auto iter = years.find(1985);
    if (iter != years.end()) {
        years.erase(iter);
    }

    a.

    2016, 2001, 1992

    b.

    1992, 2001, 2016

    c.

    2016, 2001, 2001, 1992

    d.

    1992, 2001, 2001, 2016

1.5 points   

QUESTION 62

  1. The capacity of a vector indicates

    a.

    the number of elements it can currently store

    b.

    the current size of the vector in bytes

    c.

    the largest number of elements it can store

    d.

    the number of elements it contains

1.5 points   

QUESTION 63

  1. Which of the following is not a limitation of an array when compared with a vector?

    a.

    An array can’t increase its size automatically.

    b.

    The size of an array must be known at compile time.

    c.

    An array doesn’t use memory as efficiently as a vector.

    d.

    An array doesn’t provide functions that let you modify its elements.

1.5 points   

QUESTION 64

  1. A stack container provides

    a.

    last-in, first-out access

    b.

    first-in, last-out access

    c.

    last-in, last out access

    d.

    first-in, first-out access

1.5 points   

QUESTION 65

  1. Code Example 9-2
    struct Phone {
        int area_code;
        int prefix;
        int number;
    };

    struct Contact {
        string name;
        string email;
        Phone phone;
    };

    (Refer to Code Example 9-2.) Given a Contact object named contact, what code would you use to assign values to the the data members of the Phone object for that contact?

    a.

    contact.phone.area_code = 555;
    contact.phone.prefix = 555;
    contact.phone.number = 1212;

    b.

    Phone phone;
    contact.phone.area_code = 555;
    contact.phone.prefix = 555;
    contact.number = 1212;

    c.

    Phone phone;
    Contact::Phone::area_code = 555;
    Contact::Phone::prefix = 555;
    Contact::Phone::number = 1212;
    contact.phone = phone;

    d.

    Phone phone;
    area_code = 555;
    prefix = 555;
    number = 1212;

    contact.phone = phone;

1.5 points   

QUESTION 66

  1. What is the easiest way to deploy a C++ program to a user’s computer?

    a.

    Copy the executable file to the user’s computer

    b.

    Create a batch file that copies the program to the user’s computer and then run it

    c.

    Create an installer program and then run it on the user’s computer

    d.

    Copy the source code to the user’s computer and then compile it

1.5 points   

QUESTION 67

  1. Which of the following statements is not true about structures?

    a.

    They include data members that must be fundamental data types.

    b.

    They can include member functions that operate on the data members.

    c.

    They define a data type.

    d.

    They are typically used to organize related data.

1.5 points   

QUESTION 68

  1. When you dereference an iterator, you get the value of the element that the iterator points to

    True

    False

1 points   

QUESTION 69

  1. A stack container provides last-in, first-out access

    True

    False

1 points   

QUESTION 70

  1. A deque container is a fixed-size collection of elements that’s stored in contiguous memory

    True

    False

Solutions

Expert Solution

60. a. bool equals(const Product& to_compare) {
    return (name == to_compare.name && price == to_compare.price);
}

This function will return true only if both the names and prices of products are equal.

61. b. 1992, 2001, 2016

The elements of set are in sorted order and no duplicate elements are allowed in set. So the order will be 1992, 2001 and 2016. Here 1985 is erased. Duplicate of 2001 is not allowed here.

62. c. the largest number of elements it can store

The capacity of a vector indicates the largest number of elements it can store.

63. d. An array doesn’t provide functions that let you modify its elements.

The array provide functions that let you modify its elements. It is not a limitation

64. a. last-in, first-out access

A stack container provides last-in, first-out access.

65. b.

Phone phone;
contact.phone.area_code = 555;
contact.phone.prefix = 555;
contact.number = 1212;

we need to create a phone object first and then assign the valuesto the the data members of the Phone object.

66. a. Copy the executable file to the user’s computer

The easiest way to deploy a C++ program to a user’s computer? Copy the executable file to the user’s computer.

67. a. They include data members that must be fundamental data types.

They include data members that can both fundamental data types and also the derived data types.

68. True

When you dereference an iterator, you get the value of the element that the iterator points to.

69. True

A stack container provides last-in, first-out access

70. False

A deque container is not fixed-size collection of elements. There is no guarantee of  contiguous storage allocation in dequeues.


Related Solutions

Create a struct MenuItem containing fields for name (a string) and price (a float) of a...
Create a struct MenuItem containing fields for name (a string) and price (a float) of a menu item for a diner. Create a ReadItem() function that takes an istream and a MenuItem (both by reference) and prompts the user for the fields of the MenuItem, loading the values into the struct's fields. Create a PrintItem() function that takes an output stream (by reference) and a MenuItem (by value) and prints the MenuItem fields to the stream in a reasonable one-line...
Given the following Java source code fragment double price[]; price = new double[16]; What's the name...
Given the following Java source code fragment double price[]; price = new double[16]; What's the name of the array? How many elements are in the array? What's the index of the first element in the array? What's the index of the last element in the array? What's the value of the element at index 3 after the last statement executes?
Write  the following functions using the following structure for a point. struct Point { double x, y;...
Write  the following functions using the following structure for a point. struct Point { double x, y; }; (a) A function that passes a point and returns an integer (1, 2, 3, or 4) to indicate in which quadrant the point is located int findQuadrant(struct Point testpoint) { } (b) A function that passes two points and returns the distance between them. float distance(struct Point point1, struct Point point2) { } (c) A function that passes two points and generate the...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20];...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20]; int age; char country[20]; char Position[20]; double Salary; double Rating; }; First, create an array of BarcelonaPlayer structures. Now, write a function that takes an array of BarcelonaPlayer structures as input and find out the highest paid player among all the players. void highestPaidPlayer(struct BarcelonaPlayer *pl, int size); Create another function that finds all the players from Argentina. void findPlayers(struct BarcelonaPlayer *pl, int size);
1. The Item class includes two fields: a String for the name and a double for the price of an item that will be added to the inventory.
  1. The Item class includes two fields: a String for the name and a double for the price of an item that will be added to the inventory. 2. The Item class will require one constructor that takes a name and price to initialize the fields. Since the name and price will be provided through TextFields, the parameters can be two Strings (be sure to convert the price to a double before storing this into the field). 3. Write...
Function Name: medievalFootball​ Inputs: 1. (struct​ ​) A 1xN structure representing the "field" and the players...
Function Name: medievalFootball​ Inputs: 1. (struct​ ​) A 1xN structure representing the "field" and the players on it Outputs: 1. (char​ ​) A short sentence describing what happened. Topics: (​ structures​ ​), (conditionals)​ ​, (iteration​ ​), (cell arrays​ ​) Background: As you are backpacking through Europe during your "life​ changing study abroad experience​", you stop in a small town for a bite to eat and hear about an interesting local tradition similar to a game of football. Only it's not...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should have a public instance method, getBMI() that returns a double reflecting the person's BMI (Body Mass Index = weight (kg) / height2 (m2) ). The class should have a public toString() method that returns a String like Fred is 1.9m tall and is 87.0Kg and has a BMI of 24.099722991689752Kg/m^2 (just print the doubles without special formatting). Implement this class (if you wish you...
Read inputs from console and store in Structure Given a structure of type “struct book” (shown...
Read inputs from console and store in Structure Given a structure of type “struct book” (shown below), read input into struct book from a console. struct book { char name[50]; char author[50] ; float price; }; Write a function: struct book solution() that reads name, author and price into “struct book”. A function return structure variable. Input C Programming: A Modern Approach K.N.King 50.45 where, First line of input represents book name. Second line of input represents book author. Third...
How to name organic molecule given a structure?
How to name organic molecule given a structure?
Question 3: Textbook Product: Textbook Selling price: $60 Sales in January: 500 Price elasticity: 5 The...
Question 3: Textbook Product: Textbook Selling price: $60 Sales in January: 500 Price elasticity: 5 The information above is provided by a bookstore. The store manager wants to determine if $50 is the profit maximization price for this textbook. He also provides the following information: Purchase price from publisher: $40 Question 3.1: Please create a linear demand curve based on the given information. [Please type the equation of the linear demand curve] Question 3.2: Use Excel Solver to find out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT