Passing Arrays as a parameter to the Function
Objective of this lab Manual is to get hands on experience of
Passing Arrays as a parameter to the Function in C++. Get familiar with the
syntax, Errors, and implementations.
Background: Passing Arrays as Function Parameters In C++, arrays
are always passed by reference by default.
Whenever an array is passed as a parameter, its base address is sent to
the called function. Generally, functions that work with arrays require 2 items
of information as actual parameters: the beginning address of the array (in
memory), and the number of elements to process in the array. For example (Function
PrintArray):
void PrintArray(int Array[], int
ArraySize)
{
for (int i = 0; i <= ArraySize - 1; i++)
cout << "array["
<< i << "] = "<< Array[i] << endl;
}
Pre-lab: student should have implemented the Arrays and
functions in C++.
The student must know how to
• Write functions and call them
• Trace and try to find output
Assessment tools:
The assessment is according to the
student participation in the lab if the student solves the exercise, he will
get the participation mark for this lab.
Lab Assignments:
Q1- write a program in C++ to take input in integer array and print
the whole array’s values on the console using functions only?
Q2- write a program in C++ to take input in the array and check using
Functions if there is negative value or not if negative value is found then
your function should return true and if not then return false?
Q3- write a program in C++ to take input in character array using
function and print on the console?
Q4- Write a program to take input in the array and create a function
name find Vowels() which check the whole array and print the vowels founded in
the array?
Q5- Write a program in C++ to take input in the double datatype array
of any size and then pass it to the function and check for the values which is
greater than 10 and print to on the console found or not found?
Q6- Write a program in
C++ to swap to variable’s values using functions?
Note: should pass
values to the functions using value by reference if failed to do so no marks
will be awarded.
Q7- Write a program in C++ to change the value of a variable
declared and initialized in the main function by using function named
changeValue()?
Q8- Write a program in C++ to sum two variables using
function named Sum()?
Q9- Write a program in C++ to solve the equation using functions only?
Q10- Write a program in C++ to solve the Equation using function and your
function should not return anything and the result should print in the main
function only?
Note: use value passing by reference.
Sorry i couldn't understand what you have written?
ReplyDeletePost a Comment