0% found this document useful (0 votes)
185 views3 pages

Pointers Lab

This laboratory manual covers object oriented programming. It contains instructions for two problems. Problem 1 involves dynamic memory allocation for 2D arrays, including functions to allocate, initialize, display, and deallocate a 2D integer array. It also includes functions to input values to the array and find the maximum value in each column. Problem 2 involves implementing functions to tokenize a string based on a delimiter, without using built-in functions. It should store the tokens in a list and return the number of tokens.

Uploaded by

Omar Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views3 pages

Pointers Lab

This laboratory manual covers object oriented programming. It contains instructions for two problems. Problem 1 involves dynamic memory allocation for 2D arrays, including functions to allocate, initialize, display, and deallocate a 2D integer array. It also includes functions to input values to the array and find the maximum value in each column. Problem 2 involves implementing functions to tokenize a string based on a delimiter, without using built-in functions. It should store the tokens in a list and return the number of tokens.

Uploaded by

Omar Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

National University of Computer and Emerging Sciences

Laboratory Manual # 2
for
Object Oriented Programming

Course Instructor Mr. Bismillah Jan


Lab Instructor(s) Mr. Muhammad Saddam
Mr. Abdul Wahab
Date 09/04/2019
Semester Fall 2019

Department of Computer Science


FAST-NU, Lahore, Pakistan
Introduction to Debugging and Pointers Revision
Objectives:
By practicing this lab students will be able to:
 Understand 1D Dynamic arrays.
 Understand 2D Dynamic arrays(char, int)

Problem#1
a. Write a function int** AllocateMemory(int& rows, int& cols) that takes size of matrix (rows and
columns) from user, allocates memory for the matrix and return its pointer.
Write a function void InitializeMatrix(int** matrix, const int& rows, const int& cols) that
initializes the matrix elements to 0.
Write a function void DisplayMatrix(int** matrix, const int& rows, const int& cols) that
displays the matrix in proper format.
Write a function void DeallocateMemory(int** matrix, const int& rows) that deallocates all the
memory.
Test your program. An example run is given below.
Enter total rows:4
Enter total columns:3 void main(){
The array is: int rows=4, cols=3;
000 int ** matrix = AllocateMemory(rows,cols);
000 InitializeMatrix(matrix, rows, cols);
DisplayMatrix(matrix, rows, cols);
000 DeallocateMemory(matrix, rows);
000
}

b. Write a function void InputMatrix(int** matrix, const int rows, const int cols) which takes input
the values in matrix from user(console).
Write a function called maxCol that takes as parameters a pointer to a 2D array and its dimensions.
It should return the largest element in each column of the array. Since there is more than one column
in 2D array, you have to return an array that contains largest of each column.
For example, if the Sample Matrix is
1 4 8
9 1 6
5 7 2

Your function will return array containing maximum elements of all the columns i.e.
9, 7, 8
A Sample main function is given below for your help.

void main(){
int rows, cols;

//take input from user for rows and cols

int ** matrix = AllocateMemory(rows,cols);


InitializeMatrix(matrix, rows, cols);
DisplayMatrix(matrix, rows, cols);
InputMatrix(matrix, rows, cols);
int * maxColValues = maxCol(matrix,rows, cols);
for(int i=0; i<cols; i++)
cout<< *(maxColValues + i) <<”,”;
cout<<endl;

//deallocate matrix
//delete maxColValues

Problem#2
Implement the C++ Functions,

int myTokenizer (char *data, char**& list_tokens, char delim)


void printTokens (const char** list_tokens, int size)

Don’t use any built-in function of tokenization.

The function “myTokenizer” should store the tokens in the list_tokens, every row of list_tokens contains a token
and split the data on the basis of the delimiter (delim). The function returns the number of possible tokens. Call
the function in main and print the list_tokens.

Sample Run
Input: my,name,is,,Mr.,Ali Input: _I_Go_FAST_Nu_
Delim : , Delim: _
Tokens are : Tokens are:
my I
name Go
is FAST
Mr. Nu
Ali

You might also like