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

University of Central Punjab Faculty of Information Technology

The document outlines 6 questions for a C++ programming assignment on arrays and functions. Students are asked to write programs that: 1) implement a sorting function for an integer array, 2) swap the 2nd min and max values of an array, 3) find the median of an odd-sized array, 4) output common values between two arrays, 5) rotate an array by a given number of positions, and 6) print the first and last occurrences of a number in an array. Proper formatting and passing of arguments to functions is emphasized.
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)
21 views2 pages

University of Central Punjab Faculty of Information Technology

The document outlines 6 questions for a C++ programming assignment on arrays and functions. Students are asked to write programs that: 1) implement a sorting function for an integer array, 2) swap the 2nd min and max values of an array, 3) find the median of an odd-sized array, 4) output common values between two arrays, 5) rotate an array by a given number of positions, and 6) print the first and last occurrences of a number in an array. Proper formatting and passing of arguments to functions is emphasized.
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

Lab 1 PF Fall ‘19

University of Central Punjab


Faculty of Information Technology

PF Lab 1
 Use appropriate variable and function names
 Use functions where necessary
 Implement supporting code (such as main etc.) where needed
 Array size should always be passed for arrays (except C-style strings)

Question 1
Write a C++ program that implements a sorting function that sorts an integer array passed
to it. Output array before and after sorting.

Question 2
Write a C++ function that accepts an array, its size, and swaps 2nd min value with 2nd max
value.
Sample input:
Array: 1 4 7 9 12 5 -4
Sample output:
Array: 9 4 7 1 12 5 -4

Question 3
Write a C++ program that passes an array to a function ‘FindMedian’, that returns the value
of median in an array. You may assume the passed array will be odd sized.
Sample input:
Array: 6 8 3 9 1 -4 88 12 0
Sample output:
Median: 6

1
Lab 1 PF Fall ‘19

Question 4
Write a C++ program that passes 2 arrays of possibly unequal sizes to a function that
outputs all values that are common between both arrays.
Sample input:
Array 1: 1 2 3 5 6 8 9
Array 2: 1 4 5 7 8 9 10 11 12 14
Sample output:
Console output: 1 5 8 9

Question 5
Write a C++ program that takes an array and a number ‘N’ and rotates the array by ‘N’, i.e.
The array shifts to the right and the elements at the are moved to the start of the array.
Sample input:
Array: 1 2 3 4 5 6 7 8
N: 2
Sample output:
Array: 7 8 1 2 3 4 5 6

Question 6
Write a C++ program that prints the first and last occurrences of a number ‘N’ entered by
user in an integer array.
Sample input:
Array: 1 2 3 4 5 3 6 7 8 3
N: 3
Sample output:
First occ: 2
Last occ: 9

You might also like