COSC1315 Fundamentals of Programming
Instructor: Prof. Richard G. Baldwin
Assignment Number: 19
Making certain that you comply with the General Requirements, write a C++ program that meets the following specifications:
BEGIN WRITTEN SPECIFICATIONS
This program must use
Object-Based
Programming Syntax.
Without making any changes to the function named doSomething below, other than to enter your name where indicated, and to make the modification specified below, write all of the additional code necessary to create an Object-Based program that will produce the screen output shown below.
This program asks the user to enter a numeric character and continues looping until the user enters a character ranging from 0 through 9. If the user fails to enter a numeric character, the program loops and again asks the user to enter a numeric character. When the user finally enters a numeric character, the program displays a goodbye message and terminates.
Your task is to modify the expression on the line that begins the while loop to cause the program to use a different expression to provide exactly the same behavior. Your new expression may not contain the logical and operator given by && as is the case in the original version shown below.
Once again, other than to insert your name where indicated, do not modify any code in the doSomething function other than the single line that begins the while loop.
//Begin program code
void doSomething(){
cout << "Insert your name here" << endl;
//Do a priming read
char temp = 0;
cout << "Enter a numeric character: ";
cin >> temp;
//End sequence structure
//Begin loop structure
//Note, you are to modify the following line of
// code as described above.
while(!(!(temp < '0') && !(temp > '9'))){
//Outside allowable character range
cout << "Bad input" << endl;
cout << "Enter a numeric character: ";
cin >> temp;
}//end while loop
//End end loop structure
//Good input, display msg and terminate.
cout << "Thanks for the " << temp << endl;
}//end doSomething function
//End program code
Program Output for three separate runs of the program:
Insert your name here Enter a numeric character: a Bad input Enter a numeric character: A Bad input Enter a numeric character: 0 Thanks for the 0 Insert your name here Enter a numeric character: B Bad input Enter a numeric character: b Bad input Enter a numeric character: 5 Thanks for the 5 Insert your name here Enter a numeric character: d Bad input Enter a numeric character: D Bad input Enter a numeric character: 9 Thanks for the 9
END WRITTEN SPECIFICATIONS
As specified in the General Requirements, copy the above specifications, including the two lines of upper-case characters and paste the specifications into a comment block at the beginning of your source code file.
Note: Sometimes when copying C++ source code into HTML documents (like this one) the code will become corrupted. This is particularly true for code that involves left and right angle brackets such as in:
#include <iostream>
if(x <= y){
Although Prof. Baldwin has made an effort avoid such problems, it is possible that some corruption of source code may have occurred during the creation of these HTML documents. If you see anything that you believe might be corrupted source code, please notify Prof. Baldwin so that he can look into the problem, correct the code if necessary, and make all of the students aware of the problem.
-end-