LAB 9-In Lab Tasks PDF
LAB 9-In Lab Tasks PDF
Learning Objectives
In today’s lab, you will practice;
1. Writing overloaded functions.
2. Passing arguments by reference and value.
3. Writing recursive functions.
Practice Questions
You can practice the following problems in this lab.
Task 1.1 Function Overloading
Write a C++ program using function overloading. The name of the overloaded function is
‘square’. The different prototypes of this overloaded function are;
• void square(void); // Used to print a solid square of *s with side length of 5
• void square (char); // Used to print a solid square of the character passed as argument
with side length of 6
• void square(char, int); // Used to print a solid square of the character and the side length
passed as arguments to this function
Make calls to these functions one by one in your program.
Task 1.2 Passing by Reference
Write a function ‘swap’ in C++ language that swaps the values of two variables passed as
arguments to this function. Write a C++ program which takes values of two integer variables
from the user and swaps their values using function ‘swap’. Your program should have the
following interface.
Enter the first value : 6
Enter the second value : 9
The two numbers have been swapped.
The first number is now 9.
The second number is now 6.