PF Functions Tasks
PF Functions Tasks
Introduction
This lab focuses on expanding your understanding of functions in C++, introducing advanced
function concepts that enhance code modularity and flexibility. You'll explore various ways to
define and use functions, including function overloading, different parameter passing methods,
default arguments, and variable scoping.
In order to understand these concepts better, here is a simple example that implements each of
these concepts.
#include <iostream>
using namespace std;
int main() {
// Demonstrating different function concepts
cout << calculate(5, 3) << endl; // Integer addition
cout << calculate(5.5, 3.2) << endl; // Double multiplication
return 0;
}
Lab Tasks
Task 1: Function Overloading
Create a program that demonstrates function overloading for calculating the area of different
shapes.
Requirements:
Sample Input/Output:
Write a program that demonstrates passing arrays to functions for basic statistical calculations.
Requirements:
Develop a program to illustrate the difference between pass by value and pass by reference.
Requirements:
Original Values:
x = 5, y = 10
Create a program that calculates the volume of different 3D shapes using default arguments.
Requirements:
● Implement a volume calculation function: calculateVolume(double side,
double width = -1, double height = -1)
○ Cube (side length)
○ Rectangular prism (length, width, height)
● Use default arguments for some parameters
● Demonstrate calling the function with different numbers of arguments
Write a program demonstrating different variable scopes (local, static, and global) and const
variables.
Requirements:
● Show that const variables cannot be modified (comment out attempt and mention the
error you receive in the comment)
● Demonstrate const with different scopes (global vs local)
● Include at least one function with const parameters
● Show proper use of const return values
Global Variable: 10
Global Const: 100
Note:
Your code should:
Submission instructions: