You are on page 1of 3

Programming Fundamentals

Lab 7
Topic Pointers + 1D Regrow and Shrink

• Pointer Hazards
o Explaining Memory Leak
o Discuss Heap Memory Overflow
o Auto Growing of 1D arrays
o Need of Auto Growing Arrays
Objective o Technique for Growing 1D Arrays Automatically
o Auto Shrink of 1D Arrays
o Need for Auto Shrink Arrays
o Technique for Shrinking 1D Arrays Automatically

Note: Use Pointers and Functions to solve all questions. Also Implement the
Regrow and Shrink Functions.

Lab Tasks
Task 1: Even Numbers Array
Write a program in C++ that takes a number from a user and generate even numbers till that
number. Again, ask a number a from user and removes that number from the array.
Example 1:
Number 1: 20
Array: 0 2 4 6 8 10 12 14 16 18 20
Number 2: 14
Modified Array: 0 2 4 6 8 10 12 16 18 20

1
Example 2:
Number 1: 20
Array: 0 2 4 6 8 10 12 14 16 18 20
Number 2: 13
Modified Array: 0 2 4 6 8 10 12 14 16 18 20

Task 2: Two Digits Numbers Array


Write a program in C++ that reads a number from user and generates random number till that
number into an array of size 20. Delete 1-digit numbers and keep 2-digits number from the array
and shrink the size of array.
Note: Number is in range 0 to 100
Example:
Input:
Number = 50
Array = 34 45 1 43 2 4 10 22 28 8 17 13 7 5 12 49 3 38 25 0
Modified Array = 34 45 43 10 22 28 17 13 12 49 38 25

Task 3: Even Index Values


Write a program in C++ that reads a number from user and generates random number till that
number into an array of size 20. Delete the even index numbers from the array.
Note: Number is in range 0 to 100
Example:
Number = 50
Array = 34 45 1 43 2 4 10 22 28 8 17 13 7 5 12 49 3 38 25 0
Modified Array = 45 43 4 22 8 13 5 49 38 0

2
Task 4: Vowels Characters
Write a program in C++ that reads a sentence from user. Delete the vowels characters from the
sentence.
Example:
Sentence = This is your PF Lab
Modified Sentence = Ths s yr PF Lb

You might also like