Answered step by step
Verified Expert Solution
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 : 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 ie readable to human eyesFunctions that you will need to use:getlineistream& 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;getlinecin input;setwintThis 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 Output formattingint stoistring&This function takes a string, converts it to an integer and returns that integer. For example, the string returns an integer with the value of If it is unable to convert ie the string contains Batman an exception of type invalidargument is thrown, which you will need to catch if you want your program to continue.trycatchNot 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 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, aboveCheck 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 numberAssignment Details Prompt the user for a title for data. Output the title. ptEx:Enter a title for the data:Number of Novels AuthoredYou entered: Number of Novels Authored Prompt the user for the headers of two columns of a table. Output the column headers. ptEx:Enter the column header:Author nameYou entered: Author nameEnter the column header:Number of novelsYou entered: Number of novels 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 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. ptsEx:Enter a data point to stop input:Jane Austen, Data string: Jane AustenData integer: 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 trycatch blocks with the stoi functionIf entry has no commaOutput: Error: No comma in string. ptIf entry has more than one commaOutput: Error: Too many commas in input. ptIf entry after the comma is not an integerOutput: Error: Comma not followed by an integer. ptsEx:Enter a data point to stop input:Ernest Hemingway Error: No comma in string.Enter a data point to stop input:Ernest, Hemingway, Error: Too many commas in input.Enter a data point to stop input:Ernest Hemingway, nineError: Comma not followed by an integer.Enter a data point to stop input:Ernest Hemingway, Data string: Ernest HemingwayData integer: Output the information in a formatted table. The title is right justified with a setw value of Column has a setw value of Column has a setw value of ptsEx: Number of Novels AuthoredAuthor name Number of novelsJane Austen Charles Dickens Ernest Hemingway Jack Kerouac F Scott Fitzgerald Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming JK Rowling Stephen King Oscar Wilde Output the information as a formatted histogram. Each name is right justified with a setw value of ptsEx: Jane Austen Charles Dickens Ernest Hemingway Jack Kerouac F Scott Fitzgerald Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming JK Rowling Stephen King Oscar Wilde Blind Tests remaining pointsThese 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started