Question: In this lab you will practice using basic input / output , structs, and arrays of structs. Be sure to read this lab thoroughly, especially

In this lab you will practice using basic input/output, structs, and arrays of structs. Be sure to read this lab thoroughly, especially the Hand-in Procedure
Lab
To start your lab you will need a struct to read data into. The struct definition should be placed above main () and below using namespace std. The struct should be called PurchaseType and contain the following fields:
string customerID
string productName
double price
int qtyPurchased
double taxRate
Write a complete program that:
Uses a user defined function:
void openfile (ifstreamk iFile, string prompt)
Which gets the name of a file from the user and opens it into iFile by:
a. Prompting the user for a filename using prompt and reading the filename into a string.
b. Opening the file name obtained in (la) into iFile, and verifying that it opened. If the file does not open the program should output an error message and continue from (1a) until a valid file name is entered. See the example output for error formatting.
i. The file contains strings, integers, and doubles with 5 values per line with 10 lines of data in the file. Each line of data represents a different item purchased by a customer.
Creates an array of instances of the PurchaseType struct to hold the data from the file obtained in (1).
Uses a user defined function:
void readFile(ifstreams iFile, PurchaseType purchases[])
Which reads the data from iFile into purchases by:
a. ifile contains rows of data which correspond to the elements of the PurchaseType struct. Iterate through iFile inserting the rows of data, using str. find () str substr (), into purchases until cor is hit.
Uses a user defined function:
void printPurchaseData (PurchaseType purchases[], int size)
Which prints the data contained in purchases by:
a. Using iomanip to nicely output all the data in a tabular format You will need to calculate the total price for each product purchased by multiplying the price of each product by the quantity purchased, and then multiplying by the (tax rate +1). See the example output for formatting.
b. Keeping track of each total found and outputting the average total at the end of the table.
c. Keeping track of the count of unique customers and outputting the total unique customers at the end of the table.
main () should only contain variable declarations and function calls (to your user-defined functions). All data must be read into an array of PurchaseType structs first, then the required oulput. You must write all of the functions in this lab, failing to do so will result in you receiving a 0 for this lab. Failure to use an array of structs will also result in a 0 for this lab. See the example output for examples and formating.
Prototypes for your user defined functions are:
void openrile (ifstreame, string);
void readpile (ifstreame, PurchaseType[]);
void printPurchaseData (PurchaseType [I, int);
Example Output
An example of an interaction with your program is shown below, your output should mateh these examples exactly. (The words printed in blue are from the computer, based on your commands, the words in red are user input. Note: these colors are simply here to distinguish components and not needed in your program):
Example 1
Example 2
In this lab you will practice using basic input /

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!