SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Streams And File Io
Exercise:
Programming Projects
Question:24 | ISBN:9780132846813 | Edition: 5

Question

A comma-separated values or CSV file is a simple text format used to store a list of records. A comma is used as a delimiter to separate the fields for each record. This format is commonly used to transfer data between a spreadsheet or database. In this Programming Project, consider a store that sells products abbreviated as A, B, C, D, E, etc. Customers can rate each product from 1–5 where 1 is poor and 5 is excellent. The ratings are stored in a CSV file where each row contains the customer’s rating for each product. Here is a sample file with three customer ratings and five products:

A,B,C,D,E

3,0,5,1,2

1,1,4,2,1

0,0,5,1,3

The first line in this file format lists the products. The digit 0 indicates that a customer did not rate a product. In this case the first customer rated A as 3, C as 5, D as 1, and E as 2. Product B was not rated. The third customer rated C as 5, D as 1, and E as 3. The third customer did not rate A or B.

Create a text file in this format with sample ratings. Then write a program that reads in the text file and uses the first line to determine the number of products. The program should output the average rating for each product. Customers that did not rate a product should not be considered when computing the average rat- ing for that product. The easiest solution to process the data may be to use the getline function with a comma as a delimiter and to create vectors or dynamic arrays to store the count and sum of the ratings. Your program should work with an arbitrary number of products and customer ratings.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.