PF Final 10th Dec 2019
PF Final 10th Dec 2019
PF Final 10th Dec 2019
Instructions:
Return the question paper and make sure to keep it inside your answer sheet.
Read each question completely before answering it. There are 8 questions and 3 pages.
In case of any ambiguity, you may make assumption. But your assumption should not
contradict any statement in the question paper.
You are not allowed to write anything on the question paper (except your ID and group).
Q 1. Observe and try to understand the following programs. There are no syntax errors in the programs.
Write errors (runtime/compile time) with reasons if there are any available or write outputs if the
programs are fine. [Marks 3*4=12, 10 minutes]
(i) (ii)
char* func (char *ptr)
{ void fun(const int *ptr)
ptr+=8; {
return ptr; *ptr = 30;
} }
main() main()
{ {
char *x, *y; int y = 40;
x="Programming Fundamentals"; fun(&y);
y=func(x); printf("%d", y);
printf(" y = %s", y); }
}
(iii) (iv)
main() main()
{ {
int ary[2][2][3] = { char *arr[] = { "ant", "bat", "cat",
{ "dog", "egg", "fly" };
{1,2,3}, function(arr);
{4,5,6}}, }
{{7,8,9}, void function(char **ptr)
{10,11,12} {
} char *ptr1;
}; ptr1 = (ptr += sizeof(int))[-2];
int *p; p = &ary; printf("%s\n", ptr1);
printf("%d %d",*p, *p+11); }
}
1 OF 3
Q 2. Choose the most appropriate answer from given choices. Write answer in the answer sheet.
[Marks 3*4=12, 10 minutes]
(i) (ii)
If x is an one-dimensional array, then Which of the following comments about
arrays and pointers is/are not true?
A. &x [i] is same as x + i - 1
B. * (x + i ) is same as * (&x [i] ) A. Both are exactly same
C. * (x + i) is same as x[i] B. Array is a non constant pointer
D. both (b) & (c) C. Pointer is a 1D and dynamic array
D. All of these
(iii) (iv)
Consider the following program fragment. What will be How can you write a[i][j][k] in an equivalent
the output? pointer expression?
static char wer[3][4] = {"bag", "let", "bud"};
putchar (* (wer [1] + 1)) ; A. ((***(a+i)+j)+k)
B. (**(*(a+i)+j)+k)
A. e C. (*(*(a+i)+j)+k)
B. a D. *(*(*(a+i)+j)+k)
C. 1
D. b
Q 3. Using nested loops, produce given output format: [Marks 5*2=10, 30 minutes]
a. Output sequence: 10, 13, 26, 29, 58, 61
b. Write a 'C' program that reads a string in dynamic array. Then draw the pyramid pattern of a user
provided string.
Sample Input: Zeshan
Sample Output:
Q 4. Ali has stored prices of all his sold products in linear 1D dynamic array. Now, he wants you to
develop a single function which can calculate sum of all the products on odd indexes and even indexes
separately using recursion. [Marks 15, 20 minutes]
Q 5. Junaid wants to store all his customer data in an encrypted text file. Help him by developing a
program which contains two functions that can encrypt and decrypt the file (data.txt). Make sure that
the encrypted file text is completely unreadable. Encryption means that we want to change text
present in a file to look like something else. For example, an encrypted text “abcmno” can look like
“cdeopq”. In decryption, we will get original text back from encrypted text.
[Marks 10+10=20, 25 minutes]
Q 6. Write a 'C' program that have a 2D-array data of 30 players, from where you have to select the
batsmen on given certain criteria.
[Marks 10*2=20, 25 minutes]
ID Matches Runs Fifty’s Hundred’s Four’s Sixes’
1 34 1700 1 1 40 5
a. Write a function to list ID’s of top 3 scorers who scored at least 1 Hundred or 2 Fifty’s
void Top3MostTon( int Player[][7], int Total_rows );
2 OF 3
b. Write a function to list ID’s of top 3 boundary hitter. [boundary = Sixes or Fours]
void Top3BoundaryHitter( int Player[][7], int Total_rows);
Q 7. Write a 'C' program and consider the following two 2D arrays named as CellNameData and
CellExpData as given below. The CellNameData array with 4×2 dimension, contains the cell no. and cell
names, whereas CellExpData array with 5×6 dimension, contains the 4 types of gene expression values
against each cell names. The first row in both array and the first column in CellExpData array are just
row and column heads. Out of the 5 different columns in CellExpData array, select only those columns
that match with the cell names given in CellNameData array. Store these data into new 2D array
named as MergeData. After getting selected columns, expected data in MergeData array are shown
below:
[Marks 15, 25 minutes]
[Hint: You can assume numeric values to represent the each row and column names. No points will be
given on hard-coding except declaration and initialization statements]
CellNameData CellExpData
CellNo. CellName Gnames LungCell SkinCell IntestineCell LiverCell KidneyCell
0.1 LiverCell Gene1 2.3 1.7 4.3 3.4 4.5
0.2 KidneyCell Gene2 1.5 3.6 8.1 5.5 2.9
0.3 LungCell Gene3 4.1 6.6 5.3 3.9 8.1
Gene4 9.9 2.7 6.2 5.8 3.3
MergeData
LiverCell KidneyCell LungCell
Gene1 3.4 4.5 2.3
Gene2 5.5 2.9 1.5
Gene3 3.9 8.1 4.1
Gene4 5.8 3.3 9.9
Q 8. Assume that the 100 academic journals records are stored in a txt file (data.txt) as shown:
[Marks 10*2=20, 25 minutes]
a. Write a function named “Check_Author(…)”. This function searches the data for all the articles
authored by “Robert Tarjan” and changes the author to “Robert Lafore”. If no such articles exist the
function must display “Not Found”.
b. Write a function named “Article_Count(…)”. This function displays all the records for which the totals
pages are 50 or above and year 2000 or above.
BEST OF LUCK!
3 OF 3