Question

In: Computer Science

C++ for Mac (Xcode) For this exercise, you will write a program that includes four function...

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.

Solutions

Expert Solution

#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:-


Related Solutions

Please use C++ for Mac (XCode) In this program, a user can search for a name...
Please use C++ for Mac (XCode) In this program, a user can search for a name within a list of names. Here are the steps the program will implement: 1. Reads the names from the file names.txt into a vector that stores strings. 2. Sorts the names in alphabetical order using selection sort. 3. The program then prompts the user to enter a name. 4. The program then uses binary search to see if the name is in the list....
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
How do I run a lex program written with C on xcode?
How do I run a lex program written with C on xcode?
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
Write a C++ program that converts an infix expression, which includes (, ), +, -, *,...
Write a C++ program that converts an infix expression, which includes (, ), +, -, *, and / operations to postfix notation. The program should allow the user to enter an infix expression using lower case characters, then it will display the result of conversion on the screen. (Note: Use the STL stack class to accomplish the solution.).
1. Write a program that includes a function search() that finds the index of the first...
1. Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. Name your program .C The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function,...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
For this assignment, you will write a program that consists of four function definitions, including one...
For this assignment, you will write a program that consists of four function definitions, including one main() function. The main function gets inputs from the user, and the other functions show output to the user. When the program is executed, it asks the user to enter a small amount of information, and then shows output based on the user's info. Specification: Here are some specific requirements for this program: The program should consist of four function definitions, written one after...
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT