Enter file name **purchasesl.csv +-- --- ------+ | Customer ID | Product Name | Price | Quantity | Tax Rate | Total | -+---- A134CX2 | A134CX2 | A134СХ2 | shirt | 10.00 | pants | 15.95 | jacket | 24.49 | blouse | 19.99 | pants | 14.98 | mittens | socks | 10.98 | 1 | 2 | 1 | 8.25 | 10.82 | 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 | 8.25 | 54.11 | 4J37121 | 4J37121 | 4J37121 | 3 | 3 1 2 1 9.99 | 4J37121 | gloves | cap | 24.99 | earrings | 49.99 | B834621 | 9.99 | B834621 | 3 1 27G8ZZY | 1 | -+- +- Unique users: 4 Average total: $33.37

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
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.
Transcribed Image 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
**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
Transcribed Image 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education