You are on page 1of 2

EECE 230 Programming using C++ Sections 1, 2, 3

Lab Assignment 5
Objectives:

To practice functions and recursive functions.

Problems 1, 2, 3, 4 are due on Friday Oct. 17 @ 11:55 pm


1. Write a program that will accept two integers from the user and send them to a
function that will return the power of the first integer to the second integer. For
example; if the user enters 2 and 3 the function will return 8. You cant use the
power function of the system.
2. Write a program that will accept an integer from the random number generator
between 151 and 998. Then call a function that will take that number and returns
a Boolean indicating whether the number is a prime or not. Note that a prime
number is a number that divides by 1 and itself only. Example; if the number is:
19, then the function will return true and the main will print the message 19 is a
prime number.
3. Write a program to prompt the user for two fraction numbers and one of the
arithmetic operations / or *. You are also to write two functions
dividedFractions or multiplyFractions. Your main will call one of the two
functions according to the operation entered. Each function will return the result
of the expression to be printed in the main.
Example: if the user enters 2 3 3 5 * This means he/she wants to multiply
(2/3)*(3/5). You pass the four numbers to the multiplyFractions() and return the
result in fraction 6 and 15 (no simplification is needed) to be printed in the main.
(Hint: how can we return 6 and 15?)
4. Write a program to allow the user to enter a number between 10 and 80 inclusive.
You have to keep asking the user to enter a number in that range if he doesnt (use
do-while). Then call a function that will list all the combinations of two integers
(other than 1*the number itself) that their multiplication is equal to the entered
number. Example; if the user entered 36 then your output will be: <2, 18> <3, 12>
<4, 9> <6, 6>.
Problems 5, 6 are due on Monday Oct. 20 @11:55 pm
5. Write a Recursive function that accumulates the even numbers between any two
given numbers. In the main the user will input the values of the two numbers (you
have to check which is the smaller); you pass them to the function that will return
the result.
Example; if the input is 10 and 3, the output will be 28
6. Write a Recursive function that computes the value of ex by using the formula. In
the main the user will input the values of x and n; you pass them to the function
that will return the result:

n
ex= 1+ x/1! + x2/2! + x3/3! + + x /n!

You might also like