Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROGRAM - NOVELS (1) Prompt the user for the name of the input file. Open the file as an input file, and report that the

PROGRAM - NOVELS

(1) Prompt the user for the name of the input file. Open the file as an input file, and report that the file was opened successfully. If the file was not opened successfully, report an error message and exit the program. (3 pts)

Ex:

Enter the name of the input file:

novels.txt

Opened novels.txt successfully.

OR

Enter the name of the input file:

novels.txt

Could not open novels.txt. Goodbye!

(2) Read two column headers from the first two lines of data. Output the column headers. (1 pt)

Ex:

Column headers are:

Author name

Number of novels

(3) Read data points from the input file, until the end of file is reached. Data points must be in this format: string, int Store the information before the comma into a string variable and the information after the comma into an integer. Output the data points as they are read in. Store the string components of the data points in a vector of strings (up to 100). Store the integer components of the data points in a vector of integers (up to 100). Close the input file when you finish reading it. (4 pts)

Ex:

Reading data points:

Jane Austen, 6

Charles Dickens, 20

*** End of file ***

(4) Perform error checking for the data point entries. If any of the following errors occurs, output the data and appropriate error message and skip that data point.

- If entry has no comma

- Output: `Error: No comma in string.` (1 pt)

- If entry has more than one comma

- Output: `Error: Too many commas in input.` (1 pt)

- If entry after the comma is not an integer

- Output: `Error: Comma not followed by an integer.` (2 pts)

Ex:

Ernest Hemingway 9

Error: No comma in string.

Ernest, Hemingway, 9

Error: Too many commas in input.

Ernest Hemingway, nine

Error: Comma not followed by an integer.

(5) Output the information in a formatted table. The title is right justified with a setw() value of 33. Column 1 has a setw() value of 20. Column 2 has a setw() value of 23. (4 pts)

Number of Novels Authored

Author name | Number of novels

--------------------------------------------

Jane Austen | 6

Charles Dickens | 20

Ernest Hemingway | 9

Jack Kerouac | 22

F. Scott Fitzgerald | 8

Mary Shelley | 7

Charlotte Bronte | 5

Mark Twain | 11

Agatha Christie | 53

Ian Flemming | 14

J.K. Rowling | 14

Stephen King | 54

Oscar Wilde | 1

(6) Output the information as a formatted histogram. Each name is right justified with a setw() value of 20. (4 pts)

Ex:

Jane Austen ******

Charles Dickens ********************

Ernest Hemingway *********

Jack Kerouac **********************

F. Scott Fitzgerald ********

Mary Shelley *******

Charlotte Bronte *****

Mark Twain ***********

Agatha Christie *****************************************************

Ian Flemming **************

J.K. Rowling **************

Stephen King ******************************************************

Oscar Wilde *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. How do most insects respire ?

Answered: 1 week ago

Question

Who is known as the father of the indian constitution?

Answered: 1 week ago

Question

1.explain evaporation ?

Answered: 1 week ago

Question

Who was the first woman prime minister of india?

Answered: 1 week ago

Question

Explain the concept of going concern value in detail.

Answered: 1 week ago