Assignment 2 PT

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment # 2

Course: Programming Techniques Total Marks: 100


Section: BS Computer Science, Software Engineering
Semester: 2nd
Due Date:23 -Mar- 24
Late Assignments will be dealt as per policy given in the course outline. Copied
assignment will be getting zero marks and further action will be taken as per
SSCASEIT university policy.

Objective: To reinforce your understanding of basic C++ pointers.


Instructions:
1. Pointer Initialization (10 points):
 Declare an integer variable num and a pointer to an integer ptr.
 Initialize ptr to point to the memory address of num.
 Set num to a value and use ptr to modify the value of num.
2. Pointer Arithmetic (15 points):
 Create an integer variable and a pointer to that variable.
 Use pointer arithmetic to increment and decrement the value of the
variable and print the results.
3. Pointer Comparison and Logical Operators (15 points):
 Create two integer variables a and b.
 Declare a pointer to an integer ptr and make it point to either a or b
based on user input.
 Use conditional statements and pointer comparison to print whether
the pointed value is even or odd.
4. Swapping Values using Pointers (20 points):
 Write a C++ program that uses pointers to swap the values of two
integer variables x and y.
 Use pointer variables to accomplish this without using any temporary
variables.
5. Write a C++ program that utilizes dynamic memory allocation and pointers
to find all unique elements in a 2D array.
Your program should:
 Prompt the user to enter the number of rows and columns for the 2D array.
 Dynamically allocate memory for the 2D array based on the user's input.
 Allow the user to input elements for the array.
 Find and print all unique elements in the array.
 Ensure to properly deallocate memory after usage.

6. Write a C++ program which declares an array of size N using pointer, asks
the user to fill the array with numbers. Your programs will then do two
things:
First, your program will replace the duplicate elements from the array. For
example, let’s say the size of array is 10, and the numbers user entered are 6, 8,
3, 5, 5, 0, 3, 9, 8, 3. Now after removing the duplicate numbers, the array will
become 6, 8, 3, 5, -1, 0, -1, 9, -1, -1. All duplicate elements are replaced with -1.
(Assume that the user never gives -1 as input for the array)
In the second part, your program will shift all -1s toward the
end of the array. 6, 8, 3, 5, 0, 9, -1, -1, -1, -1
Grading Rubric:
 Functionality (50 points): Does the code accomplish the tasks as instructed
without errors or unexpected behavior?
 Pointer Usage (50 points): Are pointers used correctly, including
initialization, arithmetic, comparison, and swapping values?
Bonus: For additional creativity and enhancements beyond the basic requirements.

Best of Luck

You might also like