Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

please i need c++ programming code for this homework. COSC 1336, M8 PA4 - Library Functions: readChar and getArea Reusable User-Defined Functions, Char Processing, Scope,

image text in transcribedplease i need c++ programming code for this homework.

COSC 1336, M8 PA4 - Library Functions: readChar and getArea Reusable User-Defined Functions, Char Processing, Scope, Default Arguments and Function Overloading First create a new project with a source.cpp file and copy your library.h and library.cpp files to this new project, placing them in the project folder where the main source file is located and ADD them to the project solution, In this assignment you will create two (2) new generic, reusable functions for your library. CODE the function prototypes directly in your library.h file and the function definitions in your library.cpp file. 1. readChar Function a. The readChar function will be a value returning function of type char designed to get a single char value from the user and return it as an upper case character. The function will validate that the character received is one of two possible character entries. Examples of using the function could be to prompt the user to: answer a question by entering 'Y' for yes or 'N' or no select a transportation method by entering 'D' for drive or 'F' for fly select a student classification by entering 'F' for freshman or 'S' or sophomore selecting an object's shape by entering 'R' for rectangle or 'C' for circle b. Model this function's header after the readint function where it has three parameters for an error message and a character 1 and a character 2. Example call; char class = readChar("Classification", 'F','S') when an invalid character is entered the error message would be Error! Invalid input. Classification must be either For S. Try Again: Use three (3) Default Arguments in the prototype replacing the errorMsg empty string with a word. Be prepared to discuss your choice for these default values in class. Default arguments are used where you frequently call functions with the same arguments. Of the examples above which would you most likely use frequently? Use a call with ALL default arguments in this assignment's test driver program. C. Model the function's definition body after the readint function using a post-test do while loop to read the character and validate it displaying an error message when invalid data is read as indicated above. Because valid entries will not typically be in a continuous range of values, but only one of two values, you will need to modify the validating code line to: replace the relational (=) operators with the equality (==) operator replace the logical and (&&) operator with the logical or (I 1) operator Make your program "user friendly" by allowing all user input and programmer calls to be in any case, but converted to upper case at a fairly high level within the function body. The user may enter either lower or upper case characters but the function should return a valid character in upper case. Therefore, after reading in the character, use a call to the cctype library toupper function (Ch6, pg. 350) to convert the user's entry to upper case. eg. SomeChar - toupper (someChar); Note that within the function, all values compared must be in the same case. Therefore, also convert the porometer characters to upper case and use test calls with a lower case character as an argument for one character as shown below. For testing, would enter both cap and lower-case characters for both C and R. eg. char shape - readChar("Object Shape", 'c','') d. Include full function documentation (with description, precondition and postcondition) - again model after the readint function documentation but make necessary modifications that accurately reflect this function. For more examples see the Function Documentation handout in the Week 4 module. e. NOTE: When testing this function, test with invalid full words such as "yes", "FLY", "Freshman", etc. as well as other data types. Scanned with 2/24/2020 CamScanner COSC 1336, M8 PA4 - Library Functions: readChar and getArea Reusable User-Defined Functions, Char Processing, Scope, Default Arguments and Function Overloading First create a new project with a source.cpp file and copy your library.h and library.cpp files to this new project, placing them in the project folder where the main source file is located and ADD them to the project solution, In this assignment you will create two (2) new generic, reusable functions for your library. CODE the function prototypes directly in your library.h file and the function definitions in your library.cpp file. 1. readChar Function a. The readChar function will be a value returning function of type char designed to get a single char value from the user and return it as an upper case character. The function will validate that the character received is one of two possible character entries. Examples of using the function could be to prompt the user to: answer a question by entering 'Y' for yes or 'N' or no select a transportation method by entering 'D' for drive or 'F' for fly select a student classification by entering 'F' for freshman or 'S' or sophomore selecting an object's shape by entering 'R' for rectangle or 'C' for circle b. Model this function's header after the readint function where it has three parameters for an error message and a character 1 and a character 2. Example call; char class = readChar("Classification", 'F','S') when an invalid character is entered the error message would be Error! Invalid input. Classification must be either For S. Try Again: Use three (3) Default Arguments in the prototype replacing the errorMsg empty string with a word. Be prepared to discuss your choice for these default values in class. Default arguments are used where you frequently call functions with the same arguments. Of the examples above which would you most likely use frequently? Use a call with ALL default arguments in this assignment's test driver program. C. Model the function's definition body after the readint function using a post-test do while loop to read the character and validate it displaying an error message when invalid data is read as indicated above. Because valid entries will not typically be in a continuous range of values, but only one of two values, you will need to modify the validating code line to: replace the relational (=) operators with the equality (==) operator replace the logical and (&&) operator with the logical or (I 1) operator Make your program "user friendly" by allowing all user input and programmer calls to be in any case, but converted to upper case at a fairly high level within the function body. The user may enter either lower or upper case characters but the function should return a valid character in upper case. Therefore, after reading in the character, use a call to the cctype library toupper function (Ch6, pg. 350) to convert the user's entry to upper case. eg. SomeChar - toupper (someChar); Note that within the function, all values compared must be in the same case. Therefore, also convert the porometer characters to upper case and use test calls with a lower case character as an argument for one character as shown below. For testing, would enter both cap and lower-case characters for both C and R. eg. char shape - readChar("Object Shape", 'c','') d. Include full function documentation (with description, precondition and postcondition) - again model after the readint function documentation but make necessary modifications that accurately reflect this function. For more examples see the Function Documentation handout in the Week 4 module. e. NOTE: When testing this function, test with invalid full words such as "yes", "FLY", "Freshman", etc. as well as other data types. Scanned with 2/24/2020 CamScanner

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions