Docsity

Functions-Computer Fundamentals-Lab Manuals, Exercises of Computer Fundamentals

Toggle sidebar
bg1
Lab‐10
Computing Fundamental
Itisconsideredthatyouhavecompletedthe
lastlab
Task‐01
Writeafunctionsort(intarr[],intsize);,the
functionshouldhavetwoparameters1)an
integerarray2)sizeofthearraypassed.The
functionwillsortthearrayinascendingorder.
Writeaprogramthattakes10integervalues
fromuserandstorestheminanintegerarray,
thearrayispassedtosort()functionandthe
sortedarrayshouldbedisplayed.
Extension
Modifythesortfunction,anduseonlyone
parameteri.e.intarr[],forsizeofthearrayuse
sizeofoperator.
Task‐02
Writeasimpleprogramthatdeclaresand
initializesacharacterarrayof10elements.(Use
initializelisti.e.singlequotevalues).Displaythe
valuesstoredinarraybyusingaforloop.
Changetheprogramandinitializethearray
withastring,useaforlooptodisplaythevalues
ofthearray.
Changetheprogramandinitializethearray
withyournameasinitializelist,displaythe
valuesstoredinthearrayinreverseorder.
Changetheprogramandinitializethearray
withastring(yourname),displaythestringin
reverseorder.
Extension
Writeafunctionreverse()thathastwo
parameter1)acharacterarray2)sizeofthe
array.Thefunctionprocessesthearraypassed
andreversesit.Writeaprogramto
demonstratetheworkingyourfunction
reverse().
Extension
Overloadthefunctionreverse()sothatitcan
reverseanarrayofintegersorfloatsor
characters.Writeaprogramtodemonstratethe
workingofyouroverloadedreverse()function
Task‐03
Writeafunctionvowel()thattakestwo
parameters1)acharacterarray2)sizeofthe
array.Thefunctionshouldreturnthenumberof
vowelsinthearraypassed.
Writeaprogramtodemonstratetheworkingof
yourfunction
Changethefunctionandpassathirdparameter
choftypecharacter,thefunctionshouldcount
andreturntheinstancesofchinthearray.see
theexamplebelow
charname[]=”Pakistan”;
cout<<vowel(name,9,’a’);
Output:2
Task‐04
WriteafunctionintCopy(intarrA[],intarrB[].int
sizeA,intsizeB).Thefunctiontakestwointeger
arraysalongwiththeirsizes,thefunctioncopies
thecontentsofarrA[]intoarrB[],writea
programtodemonstratetheworkingofthe
function.
ChangetheprogramandwriteintCopywith
onlytwoparametersi.e.arrA[]andarrB[](use
sizeofoperator)
Changetheprogramandwriteanewfunction
strCopy()thattakestwocharacterarraysand
copythecontentsoffirstarrayintosecond
Extension
Writeagenericoverloadedfunctioncopy()that
cancopycontentsoffirstarrayintosecond
regardlessoftypeofthearraypassed
Docsity.com

Partial preview of the text

Download Functions-Computer Fundamentals-Lab Manuals and more Exercises Computer Fundamentals in PDF only on Docsity!

Lab‐ 10

Computing Fundamental

It is considered that you have completed the last lab Task‐ 01 Write a function sort(int arr[],int size);, the function should have two parameters 1)an integer array 2) size of the array passed. The function will sort the array in ascending order. Write a program that takes 10 integer values from user and stores them in an integer array, the array is passed to sort() function and the sorted array should be displayed. Extension Modify the sort function, and use only one parameter i.e. int arr[], for size of the array use sizeof operator. Task‐ 02 Write a simple program that declares and initializes a character array of 10 elements. (Use initialize list i.e. single quote values). Display the values stored in array by using a for loop. Change the program and initialize the array with a string, use a for loop to display the values of the array. Change the program and initialize the array with your name as initialize list, display the values stored in the array in reverse order. Change the program and initialize the array with a string (your name), display the string in reverse order. Extension Write a function reverse() that has two parameter 1) a character array 2) size of the array. The function processes the array passed and reverses it. Write a program to demonstrate the working your function reverse(). Extension Overload the function reverse() so that it can reverse an array of integers or floats or characters. Write a program to demonstrate the working of your overloaded reverse() function Task‐ 03 Write a function vowel() that takes two parameters 1) a character array 2)size of the array. The function should return the number of vowels in the array passed. Write a program to demonstrate the working of your function Change the function and pass a third parameter ch of type character, the function should count and return the instances of ch in the array. see the example below char name[]=”Pakistan”; cout<<vowel(name,9,’a’) ; Output: 2 Task‐ 04 Write a function intCopy(int arrA[],int arrB[].int sizeA,int sizeB). The function takes two integer arrays along with their sizes, the function copies the contents of arrA[] into arrB[], write a program to demonstrate the working of the function. Change the program and write intCopy with only two parameters i.e. arrA[] and arrB[] (use s izeof operator) Change the program and write a new function strCopy() that takes two character arrays and copy the contents of first array into second Extension Write a generic overloaded function copy() that can copy contents of first array into second regard less of type of the array passed

Docsity.com