0% found this document useful (0 votes)
22 views2 pages

Lab 01 - PF Refresher

1. This document provides instructions for a programming lab assignment with 4 tasks. The objective is to practice programming fundamentals like functions, pointers, arrays, and problem solving. 2. The first task involves reading instructions and understanding the provided document. The second task has students write a program to expand an integer array to double its original size. 3. The third task involves creating a square matrix from user input and determining if it is diagonal. The fourth task involves writing a program to store student grades in an array, calculate statistics like maximum, minimum, average, and median grades.

Uploaded by

bsef21m017
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)
22 views2 pages

Lab 01 - PF Refresher

1. This document provides instructions for a programming lab assignment with 4 tasks. The objective is to practice programming fundamentals like functions, pointers, arrays, and problem solving. 2. The first task involves reading instructions and understanding the provided document. The second task has students write a program to expand an integer array to double its original size. 3. The third task involves creating a square matrix from user input and determining if it is diagonal. The fourth task involves writing a program to store student grades in an array, calculate statistics like maximum, minimum, average, and median grades.

Uploaded by

bsef21m017
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/ 2

CMP 142 – Object Oriented Programming

Spring 2022
Issue Date: August 18, 2022
LAB-01

The objective of this lab is to:


1. Revise basic and some advance concepts of programming fundamentals.
2. Reinforce the concepts of functions, pointers, dynamic memory, linear arrays and 2-D arrays with a
focus on problem-solving.
3. Practice good coding conventions e.g commenting, meaningful variable and function names,
properly indented and modular code.

Instructions!

1. Please follow dress code before coming to the lab. Keep your student identity cards with you.
2. This is an individual lab, you are strictly NOT allowed to discuss your solutions with your fellow
colleagues, even not allowed asking how is he/she is doing, it may result in negative marking. You
can ONLY discuss with your TAs or with me.
4. Strictly follow good coding conventions (commenting, meaningful variable and functions names,
properly indented and modular code.
5. Save your work frequently. Make a habit of pressing CTRL+S after every line of code you write.
6. Beware of memory leaks and dangling pointers.

Task 00: [10 Minutes]


Read and understand the README.pdf document provided as part of this lab.

Task 01: [10 Marks]


1. Write a program that should create an array of user-defined size and then expand it. To expand the
array, implement a function resizeArray that will take an array and its size as input. It should return a
new array of double size, the first half of the array should contain the elements of the original array, and
the second half should contain two times the values of the input array. Your function should have the
following prototype:

int* resizeArray (int inArray[], const int size);

Sample Execution:
Enter size of the array: 4
Enter elements of array: 1 2 3 4

Resized array: 1, 2, 3, 4, 2, 4, 6, 8

Task 02: [5 Marks]


Write and program that should create a square matrix of user-defined size, populate the
matrix with user given values, and determine whether the matrix is a diagonal matrix or
not. Where, a diagonal matrix is a matrix in which the entries outside the main diagonal
are all zero. The diagonal entries themselves may or may not be zero.

Task 03: [10 Marks]


1. Write a program that declares a char array of size 30 then takes a string from the user and stores it in a
character array. Display a substring of count letters from left, where the count is given by the user. Print
appropriate message if the user enters out of range count.

Sample Execution:
Enter a string: Equal matrices have equal dimensions
Punjab University College Of Information Technology Page 1 of 2
Madiha Khalid
CMP 142 – Object Oriented Programming
Spring 2022
Issue Date: August 18, 2022
LAB-01

Enter count: 5
Left substring: Equal

Implement the following two functions for this task:


1. char* left(const char* target, const int count ) ;
This function should return a string that contains a copy of the specified range of characters. Where,
target
The target string from which this function will extract characters.
count
The number of characters to extract from the ‘target’ string from left side.

2. void Destructor(char *p);


This function should De-allocate the dynamically allocated memory pointed by ‘p’.

Task 04: [15 Marks]


Recently we have hired a new TA, he doesn’t like manual record keeping and calculating statistics by hand.
You can help him by making a small program that he can be used to store the grades of all students enrolled
in OOP class. The program should perform the following tasks:
a) Ask the number of students enrolled in our course. An array of integers with that many elements
should then be dynamically allocated.
b) Populate the array by taking the marks of each student of the class.
c) Calculate and display the maximum, minimum, average, and median of the marks entered.

You should implement the following functions for this task:


a. int findMin (int inArray[], const int size);
b. int findMax (int inArray[], const int size);
c. int computeAverage (int inArray[], const int size);
d. int computeMedian (int inArray[], const int size); // when a set of values is
sorted in ascending or descending order, its median is the middle value. If the set
contains an even number of values, the median is the average of the two middle values.

Use appropriate prompts for input and output to make your program easy to use. Furthermore, make sure
zero is the minimum score one can get (i.e. do not accept negative numbers for input).

Punjab University College Of Information Technology Page 2 of 2


Madiha Khalid

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