/* testKishIO.cpp CIS 250 Dave Klick 2014-01-22 This program demonstrates how some of the functions in the kishio library can be used. Updated 2014-02-11 to add test for: char getChar(const char*, const char*) */ // This was compiled by placing kishio.h and kishio.cpp in the // same directory and using the following command to compile: // g++ -Wall -o testKishIO testKishIO.cpp kishio.cpp // // The program can then be run using this command: // ./testKishIO // // If using an IDE, just add kishio.h, kishio.cpp, and // testKishIO.cpp to the same project and compile and run. // #include "kishio.h" #include /* DBL_MIN, DBL_MAX */ #include /* LONG_MIN, LONG_MAX, INT_MIN, INT_MAX */ #include /* cout */ using std::cout; using kishio::getDouble; using kishio::getInt; using kishio::getLong; using kishio::getChar; int main(int argc, char* argv[]) { int varInt = 0; long varLong = 0L; double varDouble = 0.0; char ch; // Test of getLong functions cout << "\nTesting getLong functions\n"; cout << "Please enter an integer: "; varLong = getLong(); cout << "You entered: " << varLong << '\n'; cout << "Please enter an integer between " << (LONG_MAX/2) << " and " << LONG_MAX << ": "; varLong = getLong(LONG_MAX, LONG_MAX/2); // min and max purposely reversed for testing cout << "You entered: " << varLong << '\n'; varLong = getLong("Please enter an integer: "); cout << "You entered: " << varLong << '\n'; varLong = getLong("Please enter an integer between -10 and -3: ", -10L, -3L); cout << "You entered: " << varLong << '\n'; // Test of getInt functions cout << "\nTesting getInt functions\n"; cout << "Please enter an integer: "; varInt = getInt(); cout << "You entered: " << varInt << '\n'; cout << "Please enter an integer between " << (INT_MAX/2) << " and " << INT_MAX << ": "; varInt = getInt(INT_MAX, INT_MAX/2); // min and max purposely reversed for testing cout << "You entered: " << varInt << '\n'; varInt = getInt("Please enter an integer: "); cout << "You entered: " << varInt << '\n'; varInt = getInt("Please enter an integer between -10 and -3: ", -10, -3); cout << "You entered: " << varInt << '\n'; // Test of getDouble functions cout << "\nTesting getDouble functions\n"; cout << "Please enter a number: "; varDouble = getDouble(); cout << "You entered: " << varDouble << '\n'; cout << "Please enter a number between " << (DBL_MAX/2) << " and " << DBL_MAX << ": "; varDouble = getDouble(DBL_MAX, DBL_MAX/2); // min and max purposely reversed for testing cout << "You entered: " << varDouble << '\n'; varDouble = getDouble("Please enter a number: "); cout << "You entered: " << varDouble << '\n'; varDouble = getDouble("Please enter a number between -10.0 and -3.0: ", -10.0, -3.0); cout << "You entered: " << varDouble << '\n'; // Test of getChar function ch = getChar("Continue (Y/N)? ", "YyNn"); cout << "You entered " << ch << '\n'; cout << "\nTesting complete.\n"; return 0; }