You are on page 1of 1

Computer Science (083)

Ass #5 - User Defined Functions


1. Write a Math tutor program that generates two random numbers. Pass these random numbers to
a function Tutor (int, int) which returns their sum. The sum is checked against the users
answer, this process is continued fixed number of times or till the user wants. Finally it prints
the score and the count of correct answers.
2. Write a function that uses function Trigno_func ( ) with one argument angle in degrees and
prints its sine and cosine.
3. Write a C++ program that creates a function SUM ( ) to find the sum of the following series.
The function takes no. of terms, N as a parameter and returns a double value.
1 + 1 / 2 + 1/3 + 1 / 4 + 1/5 + ..up to N terms.
4. Write program that creates a function seqsum ( ) in C++ with two arguments, double x and int
N. The function should return a value of type double and it should find the sum of the
following series:
1 + x/2! + x2/4! + x3/6! + x4/8! +.xn/(2n)! up to N terms.
OR
1 + x/1! + x4/2! + x6/3! + x8/4! +.x2n/n! up to N terms.
5. Write a program to print sum of prime numbers from 1 to N with the help of a user defined
function sumprime ( ).
6. Write a menu driven program that creates functions rec_area ( ) and rec_peri( ) to calculate
the area and perimeter respectively of a rectangle. The functions will accept length and breadth
of a rectangle of the type double as parameters and return area and perimeter respectively of
type double .
7. Write a program that creates a function SWAP ( ) to interchanges the value of two integers A
and B without using any extra variable.
8. Write a program that will accept three co-efficient of a quadratic equation and pass these
parameters to a function cal_root ( ).The function should return two roots of a quadratic
equation. The function should have the following prototype:
void cal_root (int a, int b, int c, float& root1, float& root2);
9. Write a C++ program that creates a function convert () which will take the height of the person
in inches and return the height in feet and inches in two separate variables. The function should
have the following prototype:
void convert(int& feet, int& inches);
10. Write a function called zero_small() that has two integer arguments being passed by reference
and sets the smaller of the two numbers to 0.Write the main program to access the function.

You might also like