Question

In C++, Create a class, ShoppingCart. Each ShoppingCart contains a count of the number of items...

In C++, Create a class, ShoppingCart. Each ShoppingCart contains a count of the number of items in each of three categories, produce, meats, others. You will populate the counts of items in each category with the rand() function. Produce with a range of 1 -10, meats with a range of 0 - 3 and other with a range of 1 - 30. You will used the Queue or Dequeue templates from the STL to generate a queue of 10 ShoppingCarts. You then process the queue. Each item in the produce category will take 4 seconds to process. Each item in the meat category will take 3 seconds to process. Each item in the other category will take one second to process. I suggest you include a method in ShoppingCart to report out the total processing seconds for an instance of a ShoppingCart based on the number of items in each category in that instance. Your "processing" will consist of keeping track of the total processing time for the entire queue. When complete, report out the total time in hours, minutes and seconds.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
ShoppingCart.cpp
#include <iostream>
#include <stdlib.h>
 
class ShoppingCart {
public:
    ShoppingCart() {
        produceItems = rand() % 10 + 1;
        meatsItems = rand() % 3 + 0;
        othersItems = rand() % 30 + 1;
    }
 
    int totalProcessingSeconds() {
        return (produceItems*4) + (meatsItems*3) + othersItems;
    }
 
    int produceItems;
    int meatsItems;
    int othersItems;
};
main.cpp
#include <iostream>
#include <queue>
#include "shoppingcart.cpp"
using namespace std;
 
void processQueue(queue<ShoppingCart> queueList) {
    int totalSec=0;
    int hours, minutes;
    for(int i=0; i<10; i++) {
        totalSec += queueList.front().totalProcessingSeconds();
        queueList.pop();
    }
    minutes = totalSec / 60;
    hours = minutes / 60;
    cout << "Total processing time " << int(hours) << " hours " << int(minutes%60)
         << " minutes " << int(totalSec%60) << " seconds.";
    cout<<"Total seconds "<<totalSec;
}
 
int main()
{
    queue<ShoppingCart> list;
    for(int i=0; i<10; i++) {
        list.push(ShoppingCart());
    }
    processQueue(list);
    return 0;
}
 
Add a comment
Know the answer?
Add Answer to:
In C++, Create a class, ShoppingCart. Each ShoppingCart contains a count of the number of items...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title.   Create a use a menu that contains the following items, and calls corresponding methods...

    in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title.   Create a use a menu that contains the following items, and calls corresponding methods that do the tasks the menu describes. Use classes when they're appropriate. Keep the driver class as simple as possible. Give each class, method and property simple, descriptive names using Hungarian notation. Square a number Simply pass a decimal-type number to the object that does this task. Process its...

  • Your assignment is to create and test a class for a queue of objects. You may...

    Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue.   The instances of the class should have at least one field that distinguishes each instance from other instances of the class (key property, also called a key field). You should complete the software to implement and test your queue and submit the software along with a project report. Your queue class...

  • Skills needed to complete this assignment: template metaprogramming. PROGRAMMING LANGUAGE: C++ PROMPT: Write a template version...

    Skills needed to complete this assignment: template metaprogramming. PROGRAMMING LANGUAGE: C++ PROMPT: Write a template version of a class PQueue that implements a priority queue. A priority queue is a list of items that is always ordered by priority. Each item that is added to the list requires an associated priority value, an integer for this problem, where 0 represents the highest priority and larger values are lower in priority. Removing an item from the queue removes the item with...

  • Assume that an imaginary supermarket sells items that are identified by a unique item number which...

    Assume that an imaginary supermarket sells items that are identified by a unique item number which is an integer in range 100 to 499 inclusive. The items are classified in four different categories based on their numbers, and each category defines a different sales tax rate. These four categories along with the range of item numbers included in them, and their specific sales tax rates has been summarized in the following table:    Category Item Numbers Sales Tax Rate A                100...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

  • A priority queue is a collection of items each having a priority. A priority queue supports three...

    A priority queue is a collection of items each having a priority. A priority queue supports three fundamental operations. You can ask a priority queue whether it is empty. You can insert an item into the priority queue with a given priority. You can remove the item from the priority queue that has the smallest priority. For example, suppose that you start with an empty priority queue and imagine performing the following steps. Insert item "one" with priority 10. Insert...

  • Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template ...

    Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template Deque Class (a Linked List based Double Ended Queue, Deque) that you have put together. Starter testDeque.cpp which contains: Timer class holder (you need to go through the LearnCpp Ch15 and import it in) Node class Deque class specification (you need to fill out the definition) here is the testDeque.cpp code: // C++ implementation of doubly linked list Deque doubly linked list...

  • Write a program in C++ that uses a class template to create a set of items....

    Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Be sure to include the number of total swaps in each sort. Create a total_Time variable...

    Be sure to include the number of total swaps in each sort. Create a total_Time variable is the total time it takes all 1000 iterations to run. DO NOT INCLUE THE TIME IT TAKES TO GENERATE A UNIQUE RANDOM ARRAY EACH LOOP. In java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort and create and sort 1000 different arrays of this size,  timing the run to get...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT