Exercises - Functions (Programming Fundamentals)
Exercises - Functions (Programming Fundamentals)
FUNDAMENTALS OF PROGRAMMING
LAB 08 – FUNCTIONS/BEHAVIORS
Saif Hassan
Date: 21st October, 2019
READ IT FIRST
Prior to start solving the problems in this assignments, please give full
concentration on following points.
2. It is not bad if you keep your code indented inside the loops, if and
else blocks as well.
Exercises
You can answer all functions asked in this section in a single .cpp file and test them
in main ( ) function.
2. Write a function with the name printFancy which takes two input params
i.e. a character x and an integer n. You have to print x up to n times.
For example, if I use: printFancy (‘*’, 10); it will print on screen *
10 times as **********. You can test in main function as: printFancy
(‘*’, 10);
3. What should be done with the function above to give space after each
character? For example, if I use: printFancy2 (‘-’, 10); it will print
on screen - 10 times as - - - - - - - - - -.
4. Write a function that will take two params as an integer input i.e start
and end and return the sum of all numbers existing in between.
5. Write a function that will take three params as an integer input i.e
start, end and n. And then print the numbers that are divisible by n in
the range defined by start and end.
7. Write a function that take three inputs: x, y and choice and return
value based on user’s choice. Choice may be: (S SQUARE, C CUBIC, ^
POWER, M MAX, N MIN, + ADDITION, * MULTIPLICATION).
Page 2 of 3
Lab08 – Functions CS121 Fundamentals of Programming Instructor: Saif Hassan
9. Write a function that takes one param as integer input taskNo and calls
function accordingly. Let’s say user’s input is 6, then ask user input
x, y then call swap(x, y) function. The prototype of the function is
given as: void execTask (int taskNo)
10. Write a void function named showMenu() in which you have to show user,
all the tasks number and name in proper manner. Output may be:
1- Calculate Distance
2- Fancy
3- Improved Fancy
4- Sum of all numbers in given range
and so on.
Page 3 of 3