02 Examinations
02 Examinations
(Q1) (4 marks)
#include <iostream.h>
void Make(int **&x, int base) void Foo(int *&x, int *y)
{ {
x = new int*[2]; int *t = x;
for (int r=0; r<2; r++) x = y;
{ y = t;
x[r] = new int[2]; }
for (int c=0; c<2; c++)
{
x[r][c] = base;
base += 10; void main()
} {
} int **x[2];
}
for (int i=0; i<2; i++)
{
void Show(int **x) Make(x[i], 10*i);
{ }
for (int r=0; r<2; r++)
{ for (i=0; i<2; i++)
for (int c=0; c<2; c++) {
{ Show(x[i]);
cout<<x[r][c]<<" "; }
}
cout<<endl;
} Foo(x[0][0], x[1][1]);
}
for (i=0; i<2; i++)
{
Show(x[i]);
}
}
Page 1 of 5
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2004-2005
Fundmentals of computing II (CS-201) Time Allowed: 2 Hours
(Q2) (4 marks)
#include <iostream.h>
struct Point
{
int X, Y;
};
void Display(Point p)
{
cout<<p.X<<" "<<p.Y<<endl;
}
void main()
{
Point *P[3], *T[3];
int vx = 5, vy =7;
T[i] = P[i];
vx += 5;
vy += 3;
}
delete T[1];
for (i=0; i<3; i++)
Display(*P[i]);
delete T[0];
for (i=0; i<3; i++)
Display(*P[i]);
Page 2 of 5
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2004-2005
Fundmentals of computing II (CS-201) Time Allowed: 2 Hours
X
1 8 8 10 11 13
3 2 4 9 12 1
2 4 2 1 15 4
5 1 9 2 15 17
4 7 7 16 2 18
e.g.
1 4 0 1 3 5
3 1 0
2 5 0 1 2 3 4
5 1 0
4 4 0 1 2 5
e.g.
enter a Target : 2.
The results : 2, 5, 0,1,2,3,4.
Page 3 of 5
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2004-2005
Fundmentals of computing II (CS-201) Time Allowed: 2 Hours
X
1 8 8 10 11 13
3 2 4 9 12 1
2 4 2 1 15 4
5 1 9 2 15 17
4 7 7 16 2 18
8 8 10 11 13
7 9 9 12 17
7 16 15 18
15
Problem 2: (4 marks)
Page 4 of 5
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2004-2005
Fundmentals of computing II (CS-201) Time Allowed: 2 Hours
Page 5 of 5