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...
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.
How do I run a lex program written with C on xcode?
How do I run a lex program written with C on xcode?
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...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for Bubble Sort b. Use a dynamic array of integers in a variable size of n. c. Display the following information: 1) Total counts of comparisons 2) Total counts of shifts / moves / swaps, whichever applies d. Write a main() function to test a best, and an average cases in terms of time efficiency i. Fill out the array with random numbers for an...
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT