Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 1 : Data visualizationIn this assignment you are going to handle some basic input operations including validation and manipulation, and then some output operations

Lab 1: Data visualizationIn this assignment you are going to handle some basic input operations including validation and manipulation, and then some output operations to take some data and format it in a way thats presentable (i.e. readable to human eyes).Functions that you will need to use:getline(istream&, string&)This function allows you to get input for strings, including spaces. It reads characters up to a newline character (for user input, this would be when the enter key is pressed). The first parameter is typically cin, with the second parameter a string you want to read, like this:string input;getline(cin, input);setw(int)This looks like a function, but is really a stream manipulator. It allows you to specify how many characters the next output should be. This is useful when trying to line things up different outputs. (For more information look at section 12.1 Output formatting)int stoi(string&)This function takes a string, converts it to an integer and returns that integer. For example, the string "-24" returns an integer with the value of -24. If it is unable to convert (i.e. the string contains Batman), an exception of type invalid_argument is thrown, which you will need to catch if you want your program to continue.try/catchNot functions, but keywords, these are used to handle exceptions. Sometimes operations can fail to generate the correct results, while other times they may fail to generate ANY result. This could be due to incorrect input, going out of bounds of an array, and a variety of other cases. For more information, look at section 15.1 Exception basics.Input ProcessingHandling input will require the following steps:Get input from the user in the form of a string (see the getline() function, above)Check to see if that string has ONE comma in itSplit the string based on that comma into two partsConvert the second part into an integerInput ValidationFor strings, validation is typically handled by checking to see if a string is equal to something, or perhaps whether it contains a certain character, or number of characters, etc.For numeric values, though, while we typically validate whether its in a certain range or not, there is the possibility of something not being a number to begin with (for example, the user enters dinosaur when prompted to enter a number).Assignment Details(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data:Number of Novels AuthoredYou entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header:Author nameYou entered: Author nameEnter the column 2 header:Number of novelsYou entered: Number of novels(3) Prompt the user for data points. 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. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in a vector of strings. Store the integer components of the data points in a vector of integers. (4 pts)Ex:Enter a data point (-1 to stop input):Jane Austen, 6Data string: Jane AustenData integer: 6(4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point. For the checking whether the entry after the comma is an integer or not, you will have to use try/catch blocks with the stoi functionIf entry has no commaOutput: Error: No comma in string. (1 pt)If entry has more than one commaOutput: Error: Too many commas in input. (1 pt)If entry after the comma is not an integerOutput: Error: Comma not followed by an integer. (2 pts)Ex:Enter a data point (-1 to stop input):Ernest Hemingway 9Error: No comma in string.Enter a data point (-1 to stop input):Ernest, Hemingway, 9Error: Too many commas in input.Enter a data point (-1 to stop input):Ernest Hemingway, nineError: Comma not followed by an integer.Enter a data point (-1 to stop input):Ernest Hemingway, 9Data string: Ernest HemingwayData integer: 9(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.(3 pts)Ex: Number of Novels AuthoredAuthor name | Number of novels--------------------------------------------Jane Austen |6Charles Dickens |20Ernest Hemingway |9Jack Kerouac |22F. Scott Fitzgerald |8Mary Shelley |7Charlotte Bronte |5Mark Twain |11Agatha Christie |73Ian Flemming |14J.K. Rowling |14Stephen King |54Oscar 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 *Blind Tests (remaining points)These are variations on the previous tests, with hidden input. Your code should work exactly the same in a variety of scenarios. For example, if you were to remove Mark Twain from the previous example, everything else should work just fine and the test would pass without issue.

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

Step: 3

blur-text-image

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

=+ (c) Show that a compact negligible set is trifling.

Answered: 1 week ago

Question

Write a letter asking them to refund your $1,500 down payment.

Answered: 1 week ago