In: Computer Science
C++ for Mac (Xcode)
For this exercise, you will write a program that includes four function definitions. You will also write a main() function that calls these four functions to demonstrate that they work as expected.
The four functions are:
1. printExitMessage() : This function prints a message to the screen saying something like "Thanks for using this software. Goodbye."
2. getMin(): This function takes two float inputs and returns the lesser of the two float values. For example, if the arguments to the function were -1.0f and 1.0f, it would return -1.0f.
3. getAbsoluteValue(): Takes an int argument, and returns the absolute value of that int. If you don't know what absolute value is, search for it on the web (it is really simple). Hint: multiplying by -1 will give you the positive version of a negative number.
4. isEven(): Takes an int argument and returns a bool value: true if the number is even, false if the number is odd. Hint: x % 2 == 0 will be true if the number is even, false if odd.
Don't forget to call each of your four functions in main() to make sure they work.
#include <iostream>
#include <cstdlib>
using namespace std;
void printExitMessage() //printExitMessage Function
{
cout<<"Thanks for using this software.Goodbye"; //Printing
the message
}
float getMin(float a,float b) //getMin Function
{
if(a<b) //Checking for smaller number
return a;
else
return b;
}
int getAbsoluteValue(int n) //getAbsoluteValue Function
{
return abs(n); //Calculating absolute value
}
bool isEven(int num) //isEven Function
{
if(num%2==0) //Checking if no is even
return true;
else
return false;
}
int main()
{
printExitMessage(); //Calling printExitMessage Function
float f = getMin(-1,1); //Calling getMin Function
cout<<"\n"<<f; //Printing the ans
int i = getAbsoluteValue(-18); //Calling getAbsoluteValue
Function
cout<<"\n"<<i; //Printing the ans
bool b = isEven(24); //Calling isEven Function
if(b==1)
cout<<"\nTrue"; //Printing the ans
else
cout<<"\nFalse";
return 0;
}
Output:-