Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

objective: To understand the use of functions. write void functions and value-re

ID: 3821447 • Letter: O

Question

objective: To understand the use of functions. write void functions and value-retuming functions. Tasks: Write a program that performs the following tasks: 1) Write a function largest that takes three floating-point numbers and retums the largest number of the three. Call largest function in the main function using three numbers of your choice and output the result. 2) Write a function cylindervolume that accepts a cylinder's radius and height and returns its volume. The volume, V.of a cylinder is given by the formula: V nr 2h, where r is the radius of the cylinder and h is the height. Use 3.1415 for m. In the main function, call cylindervolume using two numbers of your choice (for radius and height) and output the result. 3) Write a function gcd that accepts two integers and returns the greatest common divisor of the two numbers. The greatest common divisor (god) is the largest positive integer that is a divisor of both numbers. In the main function, prompt the user for two integers, read numbers and store them, call gcd using these two numbers, and output the result. 4) Write a function isEven that checks if an integer is an even number. The function retums true if the number is an even number otherwise. it returns false. The function prototype is: bool isEven (int x); In the main function, use the following code to test isEven function: int a; cout "Enter an integer "i cin a; if (is Even (a) is an even number" endl; else cout a is an odd number endl; 5) Write a function showASC that display the characters for ASCII code 32 through 127 on the screen. In the main function, call showASC function twice. The prototype of the function is: void showASC0;

Explanation / Answer

Note : As per chegg T&C the first question is enough to answer and is not treated as incomplete answer.

1.

float largest(float a, float b, float c)

{

if(a > b && a > c) return a;

else if(b > a && b > c) return b;

else return c;

}

void main()

{

float x,y,z;

cout << "Enter three numbers: ";

cin >> x >> y >> z;

x = largest(x,y,z);

cout << x << " is largest." << endl;

}

Output:

Enter three numbers: 1

2

3

3 is largest.