/*
* FILE: menu.cc
* THIS PROGRAM IS A MENU DRIVEN PROGRAM WHICH TELL IF AN INTEGER IS:
* EVEN, ODD, DIVISIBLE BY ANOTHER INTEGER, PRIME, PERFECT SQUARE,
* PERFECT CUBE.
*
* PROGRAMMER: RiNN
* INSTRUCTOR: Prof. Lee Mosher
* DATE: November 23, 1997
* CLASS: CS101:02
*
*/
#include // iostream LIBRARY
#include // math LIBRARY
// CONST GLOBAL VARIABLE
const char exit_choice = 'q';
// FUNCTION PROTOTYPES or FUNCTION DEFINITION
void display_menu (char & choice); //Menu
void input_int (int & n); //INPUT INT FUNCTION
void do_choice (char); //DO CHOICE FUNCTION
void do_even (); //TEST EVEN INTEGERS
void do_odd (); //TEST ODD INTEGERS
void do_divisible (); //TEST INTEGERS DIVISIBILITY
void do_prime (); //TEST IF INTEGER IS PRIME
void do_square (); //TEST IF INTEGER IS SQUARE
void do_cube (); //TEST IF INTEGER IS CUBED
void do_quit (); //GOOD BYE MSG
bool isprime (int p); //USED IN do_prime FUNCTION
bool IsSquare (int n); //UNED IN do_square FUNCTION
bool IsCube(int n); //USED IN do_cube FUNCTION
void main () //MAIN FUNCTION
{
char choice; //VARABLE FOR CHOICES
int n; //VARABLE FOR INT
cout << "\n\n\n"; //SPACES..
do { //DO-WHILE LOOP
display_menu (choice); //MENU FUNCTION
do_choice (choice); //FUNCTION WHERE EXECUTED CHOICE
} while (choice != exit_choice ); //LOOP UNTILL EXIT
}
void do_even () { //FUNCTION FOR INTEGER IS EVEN
int n;
cout << "\t Please enter an integer. I will tell you if it is even: ";
input_int(n); cout << endl;
if (n%2 == 0) //TEST IF INTEGER IS EVEN
cout << "\t The integer " << n << " is even." << endl;
else //VOID IF NOT EVEN
cout << "\t The integer " << n << " is NOT even." << endl;
}
void do_odd (){ //FUNCTION FOR INTEGER IS ODD
int n;
cout << "\t Please enter an interger. I will tell you if it is odd: ";
input_int (n); cout << endl;
if (n%2 !=0 ) //TEST IF INTEGER IS ODD
cout << "\t The integer " << n << " is odd" << endl;
else //VOID IF NOT ODD
cout << "\t The integer " << n << " is NOT odd" <> n;
}
// MENU FUNCTION
void display_menu (char & choice)
{
cout << "\n\t MENU DRIVEN PROGRAM" << endl
<< "\t +++++++++++++++++++++++" << endl;
cout << "\t e - tell if an integer is even" << endl
<< "\t o - tell if an integer is odd " << endl
<< "\t d - tell is an integer is divisible by another integer"<> choice; cout << endl;
}
void do_quit () { //GOOD BYE MSG
cout << "\n\t Thank you for Using menu.cc Good Bye!"
<< "\n\n\n\n\n\n";
}