0% found this document useful (0 votes)
10 views4 pages

OOP Assignment 1

Uploaded by

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

OOP Assignment 1

Uploaded by

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

National University of Computer and Emerging

Sciences, Lahore Campus

Object Oriented Programming Assignment 1

Section: Due Date: 16th Sept 2023

Instructions:

Please read the following instructions carefully before submitting the assignment.
1. Save your file with your Roll Number and Name
2. Submit your assignment in Google Classroom
3. It should be clear that your assignment will not get any credit if:
● The assignment is submitted after the due date.
● Assignment is copied(partial or full) from any source (websites, forums,
students, etc.)

Important Note:
1. In exercises given below, subscript operator [] is not allowed to traverse the array. Use
only offset notation. i.e instead of using myArray[i] use *(myArray+i) to read/write an
element.
2. There shouldn’t be any memory leakage in your program.
3. Make separate functions for input and output of arrays. Your main should be a sequence
of function calls only
4. You are not allowed to use global variables and goto instruction
5. All allocations of 1D/2D pointers should be dynamic.
6. Delete the array when it is no longer needed.
7. All the data will be given by user.
8. Pass the pointers to functions instead of [].
9. Make proper functions to solve the problems.
10. Debug your code to find errors/bugs.

National University of Computer and Emerging


Sciences, Lahore Campus

Task 1:

Write a function that will take a string and return a count of each letter in the string. For example, "my
dog ate my homework" contains 3 m's, 3 o's, 2 e's, 2 y's and one each of d, g, a, t, h, w, r and k. 2 Your
function should take a single string argument and return a dynamically allocated array of 26 integers
representing the count of each of the letters a . . z respectively. Your function should be case insensitive,
i.e., count 'A' and 'a' as the occurrence of the letter a. [Hint: use the letter to integer conversion
functions.] Do not count non-letter characters (i.e., spaces, punctuation, digits, etc.) Write a program
that will solicit a string from the user using getline, call your letter frequency function and print out the
frequency of each letter in the string. Do not list letters that do not occur at least once. Example:
Enter a string:
my dog at my homework
Letter frequency
a1
d1
e1
g1
h1
k1
m3
o3
r1
t1
w1
y2

Task 2 [2D Array]

Exercise 1: 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.

What is the advantage of sending the two parameters by reference?

Exercise 2: Write a function void InitializeMatrix(int** matrix, const int& rows, const int&
rows) that initializes the matrix elements to 0. You may use subscript operator to initialize
elements of matrix (only for this exercise).

Why are we passing the parameters as const?

Exercise 3: Write a function void DisplayMatrix(int** matrix, const int& rows, const int&
cols) that displays the matrix in proper format.

Exercise 4: 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 The array
is:
000
000
000
000
Task 3:

You are given a 2D array having some elements as shown below. Your task is to remove all zero
elements from the array by making a new 2D array and assign it only the non-zero elements.
Assume that rows and columns of the input array are defined by the user.
2 3 1 0 0 0

0 0 0 1 1 0

1 0 0 0 0 0

1 1 1 2 0 2

5 0 0 0 10 0

Output Array:
2 3 1

1 1

1 1 2 2

5 10

Task 4:

Write a program that creates 2D dynamic array in main function where the columns in each row
should be of different length and both values should be positive. Create a function fillArray.
This function should receive the 2D array from main function and prompt the user to provide
data. Your program should only accept positive values to fill the array. Decide the remaining
parameters and return type of this function at your own. . Create a function twoDimToOneDim.
This function should receive the 2D array from main function and creates a dynamic 1D array
long enough to store the data of 2D array into this 1D array. This function should return the
address of dynamically created 1D array to main function. Decide the remaining parameters of
this function at your own. Create a function SortArr. This function should receive the 1D array
from main function and sort its data in ascending order. Decide the remaining parameters and
return type at your own. Create a function showArr. This function should receive the sorted 1D
array and display its contents of console. Make sure that this function should not update the
contents of array.
Best Of Luck ;)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy