Overview
Welcome to Hank's Donut World (this was a donut shop from the movie Overboard). The movie is rather old so we need to come out of the past and move into the present and have somewhat of an automated donut shop. For this assignment, you will need to populate an array of donuts with values read from a CSV file using C++ structs and then implement a menu to allow a user to purchase donuts.
Data Structure(s) Needed
Functions Needed
ifstream getFileStream(string msg) - function that receives a prompt message, reads a filename, opens a filestream, and returns a valid input filestream variable (re-prompts if needed)
int getDonuts(ifstream infile, donutType donuts[]) - function that reads a CSV file with no more than 50 lines (each line represents a donutType record) and returns the amount of records read from the file. The first line in the CSV file contains a header.
bool continueMenu(string prompt) - function that outputs a prompt message and reads in a string, returns true if "No" (case insensitive), and returns false if "Yes" (case insensitive) is read in, reprompts if any other string entered
void sortByPrice(donutType donuts[], int amtDonuts) - function that sorts an array of donutType[] by the price field in ascending order
int findMinPriceIndex(donutType donuts[], int amtDonuts) - function that returns the index of a donutType object in the array with the minimum price
void removeDonut(donutType donuts[], int& amtDonuts, int removeIndex) - function that removes a donut from the donutType array at removeIndex (by collapsing the array), then decrement the amtDonuts amount by 1
void outputSoldDonuts(ofstream outfile, const donutType soldDonuts[], int amtSold) - outputs the donuts into a CSV file using the outfile filestream variable, each donut in the donutType[] array must output comma separated, each record must be terminated with an end of line character
string allcaps(string str) - a function that returns the string parameter with all of its characters upper cased
void displayAvailableDonuts(const donutType donuts[], int amtDonuts) - outputs all the donut names with its price from the donutType[] to the standard output stream
Contents of Main
1. Initialize a counter for the amount of donuts sold, along with a set of initial variables in a skeleton main.cpp file provided.
2. Call the getDonuts(infile, donuts) and store its result into an amtDonuts counter
3. Call the displayAvailableDonuts(donuts, amtDonuts) function
4. If the variable contains "exit", then go to step 11, otherwise go to the next step "additional choice"
5. Call continueMenu(prompt) function
6. If the function returns true, then go to step 11, otherwise go to the next step
7. Call findMinPriceIndex(soldDonuts, amtSold) function
8. If the function returns -1, then go to step 10, otherwise go to the next step
9. Call removeDonut(soldDonuts, amtSold, minIndex) function
10. Go to step 4
11. Call sortByPrice(soldDonuts, amtSold) function
12. Call outputSoldDonuts(outfile, soldDonuts, amtSold) function
Sample Run
A provided set of input/output files are provided
Both the interactive output and the file redirection output is provided for you in the canvas assignment
Specifications
- You must implement the functions provided
- Do not use any stringstream or getline(fstreamVar, str, ', ') to parse the data in the csv file
- Document all of your functions
- For all input read from the user, use getline(cin, strVar) do not use cin >> strVar