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...


To start your lab you will need a struct to read data into. The struct definition should be placed above main () and below<br>using namespace std. The struct should be called PurchaseType and contain the following fields:<br>1. string customerID<br>2. string productName<br>3. double price<br>4. int qtyPurchased<br>5. double taxRate<br>Write a complete program that:<br>1. Uses a user defined function:<br>void openFile (ifstream& iFile, string prompt)<br>Which gets the name of a file from the user and opens it into iFile by:<br>Prompting the user for a filename using prompt and reading the filename into a string.<br>b. Opening the file name obtained in (la) into iFile, and verifying that it opened. If the file does not open the<br>program should output an error message and continue from (1a) until a valid file name is entered. See the<br>example output for error formatting.<br>a.<br>i.<br>The file contains strings, integers, and doubles with 5 values per line with 10 lines of data in the file.<br>Each line of data represents a different item purchased by a customer.<br>2. Creates an array of instances of the PurchaseType struct to hold the data from the file obtained in (1).<br>3. Uses a user defined function:<br>void readFile (ifstream& iFile, PurchaseType purchases [])<br>Which reads the data from iFile into purchases by:<br>iFile contains rows of data which correspond to the elements of the PurchaseType struct. Iterate through<br>iFile inserting the rows of data, using str.find () str.substr(), into purchases until eof is hit.<br>а.<br>4. Uses a user defined function:<br>void printPurchaseData (PurchaseType purchases [], int size)<br>Which prints the data contained in purchases by:<br>Using iomanip to nicely output all the data in a tabular format. You will need to calculate the total price for<br>each product purchased by multiplying the price of each product by the quantity purchased, and then<br>а.<br>multiplying by the (tax rate + 1). See the example output for formatting.<br>b. Keeping track of each total found and outputting the average total at the end of the table.<br>c. Keeping track of the count of unique customers and outputting the total unique customers at the end of the<br>table.<br>

Extracted text: 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: 1. string customerID 2. string productName 3. double price 4. int qtyPurchased 5. double taxRate Write a complete program that: 1. Uses a user defined function: void openFile (ifstream& iFile, string prompt) Which gets the name of a file from the user and opens it into iFile by: 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. a. 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. 2. Creates an array of instances of the PurchaseType struct to hold the data from the file obtained in (1). 3. Uses a user defined function: void readFile (ifstream& iFile, PurchaseType purchases []) Which reads the data from iFile into purchases by: 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 eof is hit. а. 4. Uses a user defined function: void printPurchaseData (PurchaseType purchases [], int size) Which prints the data contained in purchases by: 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.
Enter file name<br>**purchases1.csv<br>| Customer ID | Product Name | Price | Quantity | Tax Rate | Total |<br>A134CX2 I<br>shirt | 10.00 |<br>1 |<br>8.25 | 10.82 |<br>pants | 15.95 |<br>jacket | 24.49 |<br>blouse | 19.99 |<br>A134CX2 |<br>2 |<br>8.25 | 34.53 |<br>8.25 | 26.51 |<br>8.25 | 21.64 |<br>8.25 | 16.22 |<br>8.25 | 32.44 |<br>8.25 | 35.66 |<br>7.15 | 21.41 |<br>7.15 | 80.33 |<br>A134CX2 I<br>1 |<br>1 |<br>1 |<br>3 |<br>4J3712I |<br>pants | 14.98 |<br>mittens I<br>socks | 10.98 |<br>4J3712I |<br>4J3712I |<br>9.99 |<br>4J3712I |<br>3 1<br>gloves |<br>cap | 24.99 |<br>earrings | 49.99 |<br>B834621 |<br>9.99 |<br>2 |<br>B834621 |<br>3 1<br>1 |<br>27G8ZZY |<br>8.25 | 54.11 |<br>Unique users:<br>4<br>Average total: $33.37<br>

Extracted text: Enter file name **purchases1.csv | Customer ID | Product Name | Price | Quantity | Tax Rate | Total | A134CX2 I shirt | 10.00 | 1 | 8.25 | 10.82 | pants | 15.95 | jacket | 24.49 | blouse | 19.99 | A134CX2 | 2 | 8.25 | 34.53 | 8.25 | 26.51 | 8.25 | 21.64 | 8.25 | 16.22 | 8.25 | 32.44 | 8.25 | 35.66 | 7.15 | 21.41 | 7.15 | 80.33 | A134CX2 I 1 | 1 | 1 | 3 | 4J3712I | pants | 14.98 | mittens I socks | 10.98 | 4J3712I | 4J3712I | 9.99 | 4J3712I | 3 1 gloves | cap | 24.99 | earrings | 49.99 | B834621 | 9.99 | 2 | B834621 | 3 1 1 | 27G8ZZY | 8.25 | 54.11 | Unique users: 4 Average total: $33.37
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here