Answer to Question #3012 in C++ for tet

Question #3012
Write a main function that allows the user to insert a number and allows him to test the number where the number is;
1.+ve,-ve.
2.iteger,rational
3.even or odd
4.for all of theabove.
Use an if statement to determine what the user want to do.
what do you want todo.
1.check sign of the number .
2.check rationality .
3.check for allthe above.
1
Expert's answer
2011-06-10T07:54:02-0400
#include <iostream>
#include <math.h>
using namespace std;

// Function definitions
void CheckSign (float num)&
{

if (num > 0)
{
& cout<< "\nGiven number is POSITIVE.\n";
}
else
{
& cout<< "\nGiven number is NEGATIVE.\n";
}
}

void CheckRationality (float num)
{
if ((num - floor(num)) == 0)& // Getting fractional part of the number
{
& cout<< "\nGiven number is INTEGER\n";
}
else
{
& cout<< "\nGiven number is RATIONAL\n";
}
}

void CheckEven (float num)
{
int whole = (int)floor (num);& // Getting whole part of the number
float frac = num - floor (num); // Getting fractional part of the number

if (((whole % 2)==0) && (frac == 0))
{
& cout<< "\nGiven number is EVEN.\n";
}
else
{
& cout<< "\nGiven number is ODD.\n";
}
}

void CheckAll (float num)
{
CheckSign (num);
CheckRationality (num);
CheckEven (num);
}

int main ()
{
float num;& // Number to check
int choice = 0;

& cout<< "** ENTER THE NUMBER FOR TESTING **\n& > ";
& cin >> num;
& system ("cls");
&
& cout<< "& **& MAIN MENU& **\n";
& cout<< "1. Check sign of the number\n";
& cout<< "2. Check rationality\n";
& cout<< "3. Check even or odd\n";
& cout<< "4. Check all the above\n";
&
& cout<< "\nYour choice > ";
& cin >> choice;
&
& system ("cls");
&
& if (choice == 1)
& {
CheckSign (num);
& }else
& if (choice == 2)
& {
CheckRationality (num);
& }else
& if (choice == 3)
& {
CheckEven (num);
& }else
& if (choice == 4)
& {
CheckAll (num);
& }
& else
& cout<< "Incorrect choice!!! Please enter correct value!!!\n";

system ("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
17.06.11, 14:15

You are always welcome.

tet
16.06.11, 12:49

thanks alot.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS