Lab Manual - Virtual University of Pakistan



Lab ManualCS301 – Data Structures2139950-103759000Prepared byTeam CS301 Department of Computer Science, Virtual University of Pakistan Week No.Lab TopicPage No.6Lab 1: Learn to understand and implement function call by value, reference and pointer27Lab 7: Learn to delete nodes from BST4Lab 1Lab Title: Learn to implement function call by value, reference and pointerObjectives: Get the knowledge of implementing function calls for call by value, call by reference and call by pointer.Tool: Dev C++Description:Write C++ program that will demonstrate how the value in a caller function is affected when it is passed to a function by using call by value, by using pointers and by using call by reference methods.#include <iostream.h>//Function 1, call by valueint intMinus1( int oldVal){oldVal = oldVal – 1;return oldVal;}// Function 2, call by using pointersint intMinus2( int* oldVal){*oldVal = *oldVal – 2;return *oldVal;}// Function 3, call by referenceint intMinus3( int& oldVal){oldVal = oldVal – 3;return oldVal;}void main (){int myInt = 31;int retVal;retVal = intMinus1( myInt ); //call by valuecout << “After returning from the called function intMinus1” << endl ;cout << ”The value returned by the called function (retVal) is : ” << retVal ;cout << endl ;cout << ”The value of the calling function’s variable (myInt) is : ” << myInt ;cout << endl << endl;// now pass the argument by using pointer, also initialize the value of myIntmyInt = 31 ;retVal = intMinus2( &myInt ); //call by passing a pointercout << “After returning from the called function intMinus2” << endl;cout << ”The value returned by the called function (retVal) is : ” << retVal ;cout << endl;cout << ”The value of the calling function’s variable (myInt) is : ” << myInt ;cout << endl << endl;// now pass the argument by as reference, also initialize the value of myIntmyInt = 31 ;retVal = intMinus3( myInt ); //call by passing a referencecout << “After returning from the called function intMinus3” << endl;cout << ”The value returned by the called function (retVal) is : ” << retVal ;cout << endl;cout << ”The value of the calling function’s variable (myInt) is : ” << myInt ;}Lab 2Lab Title: Learn to delete nodes from BSTObjectives: Understand to deletion process of nodes in BST Tool: MS Word, MS VisioDescription:Draw Binary Search Tree from the given data. Also draw Binary Search Tree after removal of value ‘9’.9 4 6 17 2 8 4 15 41 47 29Mechanism to Conduct Lab: Students and teacher communicate through Google meet. Students perform the task using the recommended tool given in each lab. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download