#C157. Compute Course Average Ratings from CSV Input
Compute Course Average Ratings from CSV Input
Compute Course Average Ratings from CSV Input
You are given course ratings in CSV format via standard input (stdin). The first line is a header with the columns, and each subsequent line contains a course title and its rating separated by a comma. Your task is to compute the average rating for each course using the formula $\displaystyle \text{average} = \frac{\sum_{i=1}^{n} r_i}{n}$ and then print each course along with its average rating sorted in ascending order by course title. In case of any error (for example, when a rating cannot be converted to a float), the program should output an error message that starts with "An error occurred:" followed by the exception message.
inputFormat
Input is provided through standard input (stdin). The first line is the header "course_title,rating". Each following line contains a course title and a rating separated by a comma. For example:
course_title,rating Python Basics,4.5 Advanced Java,3.8 ...
outputFormat
Output should be printed to standard output (stdout). For each course, print a line in the format "Course: avg" where avg is the average rating printed to two decimal places. The courses must be sorted in ascending order based on their title. In case of an error during data processing, output the error message as specified.## sample
course_title,rating
Python Basics,4.5
Advanced Java,3.8
Python Basics,4.7
Web Development,4.3
Advanced Java,4.1
Data Structures,3.9
Web Development,4.5
Advanced Java: 3.95
Data Structures: 3.90
Python Basics: 4.60
Web Development: 4.40
</p>