Вы находитесь на странице: 1из 7

Programming Fundamentals Final Term Exam Fall 2016

Question # 01 [Output+Error(s)+Fill/ Missing Codes] [20+10+10=40]


A. Find output of following codes? [2x10=20]
I. for (i=1;i<=2;i++) VII. int x[6]={3,7,6,5,4,9};
for (j=5;j<8;j=j+2) int y[5]={4,5,0,3,9};
cout<<i*j<<' '; for (i=0;i<6;i++)
for (j=0;j<5;j++)
if (x[i]==y[j])
cout<<x[i]<<':'<<j<<',';

II. int x[10]={3,7,6,5,4,9,0,1,2};


cout<<x[3]<<' '<<x[8]<<' ';
cout<<x[6]<<' '<<x[1]<<' ';
VIII. int x[5]={3,7,6,5,4};
int y[5]={4,7,5,6,9};
for (i=0;i<5;i++)
for (j=0;j<5;j++)
if (x[i]+y[j]==10)
III. int x[10]={3,7,6,5,4,9}; cout<<i<<' '<<j<<',';
for (i=0;i<4;i=i++)
cout<<x[i]+x[i+1]+x[i+2]<<' ';

IX. int v[]={3,7,6,5}, x[]={4,7,0,6};


int y[]={2,9,1,8}, z[]={6,3,2,5};
IV. int x[2][4]={{3,7,6,5},{4,9,2,1}}; int *p[4];
for (i=1;i>=0;i--) p[0]=y; p[1]=v; p[2]=x; p[3]=z;
for (j=1;j<3;j++) for (i=1;i<3;i++)
cout<<x[i][j]<<' '; cout<<p[i][3]<<' '<<p[i][1]<<' ';

V. int x[10]={3,7,6,5,4,9,0,2,1,8}; X. int v[]={3,7,6,5}, x[]={4,7,0,6};


int *p=&x[3]; int y[]={2,9,1,8}, z[]={6,3,2,5};
cout<<*p<<' '<<p[2]<<' '; int *p[4];
p=p+2; p[0]=y; p[1]=v; p[2]=x; p[3]=z;
cout<<p[-2]<<' '<<*p<<' '; for (i=0;i<2;i++)
cout<<p[2][i]<<' '<<p[i][2]<<'\n';

VI. int x[2][4]={{3,7,6,5},{4,9,2,1}};


for (i=0;i<2;i++)
for (j=3;j>0;j=j-2)
cout<<x[i][j]<<' ';

B. Find syntax or logical error(s) in following codes? Write reason only or "No Error" if there is no error in
the code. In case code has error then writing "No Error" has negative marking of 0.5 [1x10=10]
Note: Correction not required & correction is not considered as answer. Variable declaration is not error
I. void f1(int a[][], int r, int c){
for (i=0;i<r;i++){ II. int x[2][4]={{3,7,6,5},{4,9,2,1}};
for (j=0;j<c;j++) int *p=x[1];
cout<<a[i][j]<<' '; for(i=0;i<3;i++)
cout<<'\n'; cout<<p[i]<<' ';
}

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 1 of 7


Programming Fundamentals Final Term Exam Fall 2016

delete []a;
III. int x[13]={...};
int *p[2];
p[0]=&x[0];
cout<<p[0][2]<<' '<<p[4]<<'\n';
cout<<p[1][2]<<'\n'; VII. int x[3][4]={...};
int *p=&x[2][2];
cout<<p[0][0]<<' ';

IV. int *a[3];


...
for (i=0;i<3;i++) VIII. int x[10]={...};
delete []a[i]; for(i=0;i<10;i++)//sum of 2 consecutive
delete []a;
cout<<x[i]+x[i+1]<<' ';//elements

V. struct Point{
int x, y; IX. int x[3][4]={...};
}; int *p=&x[2][2];
int main(){ cout<<p[0]<<' ';
Point p; p.x=3; p.y=6;
cout<<"Point:"<<p<<'\n';
return 0;
}
X. string m[]={"Jan", "Feb",...};
cout<<"Enter Date: dd mm yyyy";
VI. int **a; cin>>dd>>mm>>yy;
a=new int[2]; ...//her validity checked
a[0]=new int[5]; cout<<dd<<'-'<<m[mm]<<'-'<<yy;
a[1]=new int[5];
...
delete []a[0];
delete []a[1];

C. Fill/ Complete missing codes according to description: [4+3+3=10]


I. Write missing code to produce given output? [04]
int x[10]={3,7,6,5,4,9,0,1,2}; 3,2
for (
7,1
6,0
5,9
4,4

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 2 of 7


Programming Fundamentals Final Term Exam Fall 2016

Consider this code for part II & III:


int x[4]={15, 37, 11, 16};
int y[4]={19, 22, 13, 73};
int z[4]={71, 18, 20, 40};
int *p[3];
I. Write missing code to produce given output? [03]

13 22 11 37 20 18

for (i=0;i<3;i++)
for (j= )
cout<<p[i][j]<<' ';

II. Complete following code to produce given output? [03]

15 19 7 1
for (i= ){ 37 22 18
11 13 2 0
for (j= ) 16 73 40

cout<<p[i][j]<<' ';

cout<<'\n';
}

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 3 of 7


Programming Fundamentals Final Term Exam Fall 2016

Question # 02 : Write/ complete codes according to description? [40]


I. Complete function to return second highest element of array? [04]
int secondHighest(int a[], cons tint SIZE){

II. Write a function "squares" to receive an integer array having "SEN" sentinel vlaue at the end of the array.
Function is to reurn another dynamic array by placing squares of all the elements of received array, place "SEN"
sentinel vlaue at the end of the array? Note: Array size is determined by the sentinel value. [04]

III. Write code to place zero's on boundary lines. The boundary lines include first row, last row, first column & last
column. you may use any number of loops? [04]
int a[200][200];

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 4 of 7


Programming Fundamentals Final Term Exam Fall 2016

IV. Given first array has some value at every index. Write code to place every alternate value in second array?
Note: By alternate means first, third, fifth ... row and first, third, fifth… column. [03]
int a[200][200], b[100][100];

V. You have to input scores of 11 players of 5 teams. Complete following program you may declare any other variable if
required? [03]
int main(){
int *a[5], i, j;

VI. 2D array has many zero entries. You have to reurn an aray having count of zero's in all rows? [04]
int* count Zeros(int a[][100], int ROWS){

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 5 of 7


Programming Fundamentals Final Term Exam Fall 2016

VII. Write all possible ways of priniting 5th element of array x? [03]
int x[10]={...}, *p=x;

VIII. 2D Array A of size 4x10 has marks of top 10 students of 4 classes in each row. Write code to print "Bingo" if at
any position marks are same in all classes? To secure full marks write minimum code? [05]

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 6 of 7


Programming Fundamentals Final Term Exam Fall 2016

IX. Create a structure Batsman have data elements: [05]


No of matches
Total runs
Best runs
avg (may be real number)
Declare an array of 100 batsman. Initialize their data at random in rnge:
- No of matches (10 to 50)
- Total runs (No of matches * (10 to 50)
- avg (total runs / no of matches)
- best runs (avg + (10 to 50))

Abdul Mateen, PUCIT (NC) – PU. Lahore. Page 7 of 7

Вам также может понравиться