/*File: Operators02.cpp
This C++ program illustrates the use of the
following relational and logical operators plus
the negation operator:
!
>=
&&
<=
This program solves the same problem as the
program named Operators01 but uses a different
formulation of the relational/logical test.
The program displays the following output on the
screen for several user input values:
Enter an upper-case letter: @
Bad input
Enter an upper-case letter: ]
Bad input
Enter an upper-case letter: Z
Thanks for the Z
************************************************/
#include
using namespace std;
class Operators02{
public:
static void classMain(){
Operators02* ptrToObject = new Operators02();
ptrToObject -> doSomething();
}//End classMain function
//-------------------------------------------//
//An instance function of the Operators02 class
void doSomething(){
//Begin sequence structure
//Do a priming read
char temp = 0;
cout << "Enter an upper-case letter: ";
cin >> temp;
//End sequence structure
//Begin loop structure
//Note the negation operator in the following
// statement.
while(!((temp >= 'A') && (temp <= 'Z'))){
//Outside allowable character range
cout << "Bad input" << endl;
cout << "Enter an upper-case letter: ";
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 Operators02 class
//---------------------------------------------//
int main(){
Operators02::classMain();
return 0;
}//end main
Listing 6
|