Lab Mid Past Paper 2
Lab Mid Past Paper 2
Instruction/Notes:
Taking some illegal online/offline help (i.e. cheating) might earn you an F grade in the
entire course.
Question 1:
Write a program that takes in an array named myArray of size 15. The value of
each element in myArray should be less than 10. Your task is to rotate the
elements of myArray to left.
You should also ask user how much rotation is required (i.e. rotation size) and
rotate your array according to user’s entered value.
For Example
Question 2: 15 marks
Write a program that can find intersection of two initially populated arrays.
Declare two int arrays A1 and A2 of size 10, now find the intersection between
these two arrays (i.e. common elements in both arrays) and place the common
values in a third array A3. Note that the arrays A1 and A2 are presorted and you
have to use single loop.
For Example:
A1: 1 3 6 9 10
A2: 2 3 10 12 14
Output:
A3: 3 10
A1: 2 7 8 15 87
A2: 15 63 71 87 91
Output:
A3: 15 87
Note: If there is no element in intersection then your program must display the message
“intersection is null”
Question 3: 10 marks
Write a function that takes in a 6-digit integer and returns true if the number is
equal to its reverse, it should return false if the condition is not satisfied. The
main should then write the number into a file and tells if it is palindrome or not.
The function should be called four times in main and each time the output must
be written in file in appending mode. By the end of execution your “output.txt”
should have four output lines written in it
For Example:
Input:
Number1 : 123010
Number2: 444444
Number3: 101010
Number4: 123321
Output.txt:
123010 is not palindrome
444444 is palindrome
101010 is not palindrome
123321 is palindrome.
GOOD LUCK