Activity 11
Activity 11
Draw a flowchart and write the equivalent program for each of the ff. problems:
1. A function, computeArea(), takes the length and width of a rectangle as parameters and
computes and returns the area. Use this function in a program that first asks the user for the
length and width of a rectangle.
2. Write a function getCube() that takes an integer parameter and computes and returns its cube.
Use the function in a program that first asks the user for the input number.
3. Write a different version of printMsg() that takes a formal parameter n. Using a loop, the
function prints the message “Hello World” n times. Write a program that first asks how many
times the user wants to display the message, then calls printMsg().
4. Create a menu-driven C++ program that uses functions to perform different arithmetic
operations. The program presents the user with this menu of options:
Arithmetic Operations Menu
------------------------------------
<A>ddition
<S>ubtraction
<D>ivision
<M>ultiplication
M<o>dulus
E<x>it
-------------------------------------
Enter your choice:
From the menu, the user selects the letter that corresponds to a specific operation. For example,
if the user enters ‘A’, the program prompts the user accordingly and performs the desired
operation:
Enter two numbers: 1 2
1+2=3
The program should then redisplay the menu and allow the user to select another
operation. Hitting ‘x’ will cause the program to terminate. Your program should contain
the following functions that perform the arithmetic operations:
int add(int a, int b) – takes two integer parameters and returns their sum
int subtract(int a, int b) – takes two integer parameters and returns their
difference
int multiply(int a, int b) – takes two integer parameters and returns their product
int divide(int a, int b) – takes two integer parameters and returns their quotient
(note: if division by zero, getQuo() arbitrarily returns 0)
int mod(int a, int b) – takes two integer parameters and returns their modulus