Question: The programming language is C++ Below are my readChar and readDouble functions: char readChar (string errorMsg, char first, char second) { char someChar; //stores each

 The programming language is C++ Below are my readChar and readDouble

functions: char readChar(string errorMsg, char first, char second) { char someChar; //stores

each char entered bool valid = false; // loop control flag indicating

The programming language is C++

Below are my readChar and readDouble functions:

char readChar(string errorMsg, char first, char second) { char someChar; //stores each char entered bool valid = false; // loop control flag indicating validity of entry // initially assume not valid do { cin >> someChar; someChar = toupper(someChar); char one = toupper(first); char two = toupper(second);

valid = someChar == one || someChar == two;

if (cin.fail() || !valid || !isspace(cin.peek())) { cin.ignore(100, ' '); //Clears input stream before displaying errorMsg //Reason: so that the error message is displayed only once cout

valid = false; /o valid entry has been read }

} while (!valid); //loop again, prompting usere to re-enter a valid char

cin.ignore(100, ' '); return someChar; //return a valid char to calling enviroment }

double readDouble(string errorMsg, double min, double max) { double someDouble; //stores each double entered bool valid = false; // loop control flag indicating validity of entry // initially assume not valid do { // read a double delimited by a whitespace character cin >> someDouble;

// valid if within min to max range; && is logical AND operator valid = someDouble >= min && someDouble

// if input has failed or is invalid or if next char is invalid clear // fail state and remove invalid input; || is logical OR operator if (cin.fail() || !valid || !isspace(cin.peek())) { cout

cin.clear(); //clear the fail state

// remove up to max number of chars in input stream or up to ' ' cin.ignore(numeric_limits::max(), ' '); valid = false; /o valid entry has been read } } while (!valid); //loop again, prompting usere to re-enter a valid double

// when valid input received, remove from input stream up to 100 remaining // characters or until reaches the ' ' character cin.ignore(100, ' ');

return someDouble; // return a valid double to calling enviroment }

PA7- Water Bill Part A (getting information) Iteration, Selection, And/Or Logical Operators, Data Validation, Value and Reference Parameters, File Processing Write a program that will get the billing information for a local water company and store it in a file The water company has different types of customers and their rates vary depending on how the water is used The company uses letter codes to identify the following types of customers H for home, C for commercial, and I for industrial The information collected for each account includes: the customer name, the account number, the code for the account type (H, C or I) and the amount of water used Input Data: Get the following data from the user by calling your library function:s Customer Name: multiword string class object of max size 20 characters create a generic readName Account Number integer in the range 1000 to 9999 - use readlnt Account Type character H. C. or I-create an overloaded readChar Usage Amount: floating point with a minimum value of 0- use readDouble Specifications for Program Overload your readChar library function to create another generic, reusable function that will read and validate one of three possible characters by adding an extra char parameter. When tested move this function (and its prototype) to your library of reusable functions 1. 2. Modify your readDouble function to add formatting for the min and max parameters such that very large anc very small numbers (perhaps above 1e6 and below 1e-6) are displayed in scientific notation and other numbers and 0 are displayed in fixed decimal format. Use a precision of 6 for both formats. Code by using the ternary conditional operator?: and the logical operators && (and) I (or) in the error message cout statement 3. Create a new value-returning function of type string called readName that will be a generic, reusable function that can be used to read, validate and return a name. The function should only accept alphabetic letters and special characters such as apostrophe, period, comma, hyphen, a blank space, etc. that are typically valid for a name. See more on last page. When tested move this function (and its prototype) to your library Note: you may want to code some driver functions to test the above library functions 4. The main function shall be iterative, processing one record at a time until all data has been entered and valid records are written to a file as described below. Use your readChar function to receive user answers to continue entering records or to quit a. Include the header file b. In main, just below your variable definition area, define an ofstream (output file stream) object, open and attach it to an output text file and check for successful file opening. Note: if the output text file does not exist as in this case, it will by default, be automatically created in the project directory and the file will be overwritten with each execution of the program ofstream fout; fout.open ("Water Bill Records.txt"); // attach the file stream to the physical file if ( fout.fail)) // fout is a user-defined object of type ofstream // if the file is not opened successfully cout header file b. In main, just below your variable definition area, define an ofstream (output file stream) object, open and attach it to an output text file and check for successful file opening. Note: if the output text file does not exist as in this case, it will by default, be automatically created in the project directory and the file will be overwritten with each execution of the program ofstream fout; fout.open ("Water Bill Records.txt"); // attach the file stream to the physical file if ( fout.fail)) // fout is a user-defined object of type ofstream // if the file is not opened successfully cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!