Read this Entire Document Before Writing Any Code!!! Problem Overview: What happens when your program asks the user to enter a…

Read this Entire Document Before Writing Any Code!!! Problem Overview: What happens when your program asks the user to enter a number and they type something that is all or partly non-numeric? Consider Program 1 below on the left. Five I/O sessions are shown with user input underlined. Recall that the extraction operator (>>) reads from whitespace to whitespace in the input stream. When extracting numeric values from the input stream the extraction operator stops when it encounters a non-whitespace character that canâ€t be interpreted as part of a number. This can result in a failed input operation and it can leave unprocessed characters in the stream. For example the ‘a†in sessions #1 and #3, the “34” characters in #2 and the “- 5” in session #5 are left unprocessed in the input stream. One way to avoid the problems encountered with inputting values into numeric variables is to input them into string variables (objects) using the getline function as shown in Program 2 on the right below. Unfortunately, while this fixes the problem of leaving unprocessed characters in the input stream, it introduces the new problem that you canâ€t perform arithmetic on string objects! You must compute the numeric equivalent of the string value in order to do arithmetic. //PROGRAM 1 //Input numeric variable value directly #include [removed] using namespace std; int main() { long num; cout num; cout s input from the console as a string of characters. The string of characters will then be converted into a corresponding numeric value, or a flag will be set to indicate that the string of characters did not represent a valid numeric value and so could not be converted. Your InputNumber class should meet the specifications given in the UML diagram below. After implementing the no-arg constructor, the input, appropriate setNum and accessor functions, you could write Program 3 as follows: //PROGRAM 3 //Input numeric data using an InputNumber object #include [removed] #include [removed] #include “InputNumber.h” using namespace std; int main() { InputNumber num; cout s input as the argument. 3 pts • The commaString() function returns a string representation of the number containing commas if and where appropriate. E.g. If inString is “1000” commaString() returns a string with the value “1,000”; if inString is “1000000” commaString() returns a string with the value “1,000,000”; etc. Note: commaString() does not change the value of inString! 3 pts • The first setNum() function sets numValue to the newNum parameterâ€s value, inString to the string equivalent of numValue, and validInput to true. 3 pts • The second setNum() function sets inString to the strNum parameter value, and numValue to the best possible numeric equivalent of inString. If there are no errors interpreting inString as a number, validInput is set too true, otherwise it is set to false. Checkpoint Stub Code: Just assume that the strNum parameter represents a valid numeric value. 5 pts • The InputNumber class code correctly identifies whenever inString is set to a non-numeric value as follows: â—‹ Any spaces at the beginning and ending of the string are ok, but… â—‹ …spaces in the middle of the string cause it to be invalid. That is, “ 123 “ is a valid numeric string value, but “1 23” is not. â—‹ Aside from leading and trailing spaces, no other non-digit characters are valid in the string… ○…except that ‘-‘ (minus sign) is allowed to precede the first digit in the string. That is, “-45” is ok, but “4-5” is not. 6 pts • The client testing code exhaustively tests all of the functions of the InputNumber class. How do the functions of the class behave when they are “fed” good data? What about bad data? Checkpoint Tester Code: Just use Program 3 below the InputNumber UML above. 27 pts for Functionality Style Criteria 1 pt • The first lines of each source code file contain comments that include the programmer name(s) and a brief description of the purpose of the code in the file. 1 pt • Use a consistent and appropriate indentation style as discussed in 2.12.3 on page 59. Follow the indentation style used in the sample code throughout the book. 1 pt • Use appropriate spacing and blank lines to enhance program readability as discussed in 2.12.3 on page 59. 1 pt • All code is necessary to the proper functioning of the program; e.g. no unused variable declarations, no unnecessarily complex code. 4 pts for Style Total Lab 9 points possible: 45 Turn in Send your header, implementation and client tester files as email attachments. The subject field of the email should say CS 210 Lab 9. The message field of the email should contain the programmer name(s). If you are programming in a team, be sure to cc your teammates.

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!Use Discount Code “Newclient” for a 15% Discount!
NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.

The post Read this Entire Document Before Writing Any Code!!! Problem Overview: What happens when your program asks the user to enter a… appeared first on The Nursing TermPaper.

Thanks for installing the Bottom of every post plugin by Corey Salzano. Contact me if you need custom WordPress plugins or website design.

Comments are closed.


Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp
%d bloggers like this: