We have the following two classes called Receipt and Item.

class Item
{
private:
int ID;
double price;
int units;
public:
Item(int, double, int); //Need to change based on array requirement
void setID(int);
int getID();
void setPrice(double);
double getPrice();
void setUnits(int);
int getUnits();
void displayItemInfo();
double computePricePerItem();
};
class Receipt
{
private:
string shopperName;
Item * shoppingList;
const int maxItems = 20;
int numItems;
public:
Receipt(string);
void setShopperName(string);
string getShopperName();
void setShoppingList(Item *);
Item * getShoppingList() const;
int getNumItems();
void addItem(Item);
void displayTheShoppingList();
double computeTotalCharge();
};

Use the above specifications to create the proper header files/ specification files: Item.h and Receipt.h for these two classes, feel free to define some of the functions of your choice as inline functions.

Define their COMPLETE implementation files: Item.cpp and Receipt.cpp based on these specifications.

Finally create your driver file, the one that contains the main function to write this program that is described below:

You are asked to write a program that helps a small farmer stand in a farmer's market to process their weekly sales data. Here is the list of some specifications about their products:

  • There are total of 10 different products they offer for sale. Each is ID'ed by numbers in the range 1-10 inclusive.
  • They have the list of each item's ID and their unit price in a file called itemsInfo.txt. The following is an example line of this file:
8 2.99
  • This means the item with the ID 8 is priced at 2.99 per unit.
  • They have the list of their weekly sales in a file called weeklySales.txt. Each line of this file follows the following pattern:
[name][tab][# of items ordered][tab][ID][tab][unit]. .[Enter]
  • Following this pattern, the following could be an example line:
Johnson 2 4 3 8 1
  • This means the shopper named Johnson has ordered total of 2 items: 3 units of item with ID 4, 1 unit of item with ID 8.

Each line of the weeklySales.txt file will be used to instantiate an object of type Receipt. Notice that class Receipt has a dynamically allocated array of Item objects.

You are asked to write a program that reads the information in the file itemInfo.txt into an array of size 11, whose each index matches the ID of the item and the element with that index contains the price of that item's ID. So for example based on the above sample line of this file:

8 2.99

We will have in index 8 of this array the value of 2.99. Call this array of type double, pricePerID.

You will use this array as a reference to retrieve the price of different items based on their ID's/ indices.

The plan is to have a vector of type Receipt to store the data in the sales file.

So go ahead and create your vector of type Receipt to be populated via the sales file.

So start reading from the file weeklySales.txt with the goal of creating an object of type Receipt from the data on each line.

This process includes the following general steps:

  • On each line, start by reading the name of the shopper, followed by the total number of items ordered.
  • Set up a loop based on the total number of items ordered, to read the ID followed by the number of units purchased of that item.
  • As you will see later in this document, you are asked to tally the items sold based on their ID. This step of this process would be the good place to implement your tally strategy.
  • Use the ID to find the price in your pricePerID array.
  • With these peices of data: the ID, the price, and the #of units, you are ready to instantiate an object of type Item. So do just that.
  • You have a function that is designed to add an object of type Item to the Receipt' shoppingList array. Call that function here.
  • Keep iterating through this loop as many times as total number of items ordered.
  • When done, you are done with that line of data, you are done with that single object of type Receipt.
  • Push back this single Receipt object to your vector of Receipts.
  • Keep iterating so long as you have lines of data in your sales file.

When you have done the above steps successfully, write segments of code to process the following menu:

1. Display the total charges per receipts.
2. Display the tally result per Item ID’s.
3. What appears to be the most popular item(by ID) of this farmer stand, Based on this sales record?
4. Defective Product: No charge based on Item ID:
Enter the item ID 1-10:
5. BONUS OPTION (+8 points): Apply the following promotion on existing sales records: Buy 5 units or more of the same item and get one item free (i.e. get credit for one item).
6. Exit.

Notice, both options 4 and the BONUS OPTION will alter the individual Receipts of your Receipt vector. So if I choose either option, and then choose option 1 right after, I should be able to see the difference in the total dollar amount charged per Receipt.

Notice that option 4 does not change the original price of that item in our pricePerID array, we assume this only applies to that item's sale in the weekly data we are processing.

For the sake of brevity, you do not need to worry about how the BONUS OPTION affects your tally process. We assume that the sellers have some other accounting provisions to account for the items they give away for free!

Do not change the classes, this should be a promotion that is applied in the main function.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.