02 Prog I Examinations
02 Prog I Examinations
(Q1) (3 marks)
#include <iostream.h>
void main()
{
char x[] = {'a', 'b', 'c', 'd', '\0'};
char y[] = {'k', 'l', 'm', 'n', '\0'};
int i =0;
char t;
while( i <2)
{
t = x[i+2];
x[i+2] = y[i];
y[i] = t;
i++;
}
y[i] = '\0';
cout<<x<<endl;
cout<<y<<endl;
i = 0;
while(i<2)
{
t = y[i+2];
y[i+2] = x[i];
x[i] = t;
i++;
}
cout<<x<<endl;
cout<<y<<endl;
Page 1 of 6
University of Modern Sciences & Arts (MSA) End-Term Examination-Fall 2004-2005
Fundmentals of computing for engeeris (CS-101) Time Allowed: 3 Hours
(Q2) (3 marks)
#include <iostream.h>
(Q3) (3 marks)
#include <iostream.h>
void main()
{
int x[] = {10,20,30,40};
Page 2 of 6
University of Modern Sciences & Arts (MSA) End-Term Examination-Fall 2004-2005
Fundmentals of computing for engeeris (CS-101) Time Allowed: 3 Hours
Y:
0 1 2 3 4 5 6 7
1 60 50 8 12 28 34 7
3
Y:
0 1 2 3 4 5 6 7
6 13 8 50 2 12 7 34
0 8
Pos:
2 0 -1 7 1 6 3 5
Page 3 of 6
University of Modern Sciences & Arts (MSA) End-Term Examination-Fall 2004-2005
Fundmentals of computing for engeeris (CS-101) Time Allowed: 3 Hours
Letters:
A W E S I R Y N T \0 .. .. ..
Garbage
Weights: 8 10 5 7 2 4 3 9 12 0 0 0 0
After reading the Weights array you have to set values that correspond to the garbage to
zero.
Y E S S I R W E W A N T \ .. ..
0
3 5 7 7 2 4 10 5 10 8 9 12
15 11 15 39
Page 4 of 6
University of Modern Sciences & Arts (MSA) End-Term Examination-Fall 2004-2005
Fundmentals of computing for engeeris (CS-101) Time Allowed: 3 Hours
Example:
X:
A E S A A K H M A y \0 .. ..
2 1 4
Function 2: (7 marks)
Output:
How many occurrences of T in X.
The first position of T.
Example:
X:
16 1 10 7 10 1 22 6
0 9
N:8
T : 10
Page 5 of 6
University of Modern Sciences & Arts (MSA) End-Term Examination-Fall 2004-2005
Fundmentals of computing for engeeris (CS-101) Time Allowed: 3 Hours
Page 6 of 6