0% found this document useful (0 votes)
92 views5 pages

29 Prog I Examinations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views5 pages

29 Prog I Examinations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

University of Modern Sciences & Arts (MSA) End-Term Examination-Spring 2018

Fundmentals of computing (CS-101) Time Allowed: 3 Hours

SECTION (I): TRACING PROBLEMS (Total: 8 marks)


Display the output of the following programs:

(Q1) (4 marks)

void DoIt( int x[], int y[], int z[], int i )


{
x[ y[i] ] += x[ z[i] ];
}

void DoThat(int x[])


{
for (int i=0; i< 4; i++)
{
cout<<x[i]<< " , ";
}
cout<<endl;
}

void main()
{
int x[] = {10, 20, 30, 40};
int y[] = {2, 1, 0, 3};
int z[] = {0, 2, 3, 1};

for (int i=0; i<4; i++)


{
DoIt( x , y, z, i);
DoThat(x);
}
}

Page 1 of 5
University of Modern Sciences & Arts (MSA) End-Term Examination-Spring 2018
Fundmentals of computing (CS-101) Time Allowed: 3 Hours

(Q2) (4 marks)

void DoIt(char x[] , char y[] , int i )


{
int a=0;
for (int k=i; k<8; k+=2)
{
y[a] = x[k];
a++;
}
}

void DoThat(char x , char y[] , int N)


{
for (int k=0; k<N; k++)
{
y[k] = x;
}
}

void main()
{

char x[]={'G','C','O','P','\0','U','D','C','Q','D','t','L','\0','R', '\


0','W','\0'};

char y[8];
int N = 8;

cout<<x<<endl;
DoThat(x[4] , y, N);

int a = 3;
N--;
for (int i=0; i<7; i++)
{
DoThat(x[a] , y, N);
N--;
a+=2;
}
cout<<y<<endl;
}

Page 2 of 5
University of Modern Sciences & Arts (MSA) End-Term Examination-Spring 2018
Fundmentals of computing (CS-101) Time Allowed: 3 Hours

SECTION (II): PROBLEM SOLVING (Total: 16 marks)


Problem 2: (16 marks)
Write a program to do the following:
 Read an array of 300 values. ( X ).
 Copy One but Two: from (X) to à (Y)
o from (X): copy one cell to (Y), and ignore two cells , and so on.
o from (X): copy those ignored cells to (Y), after that.
Note : make the size of (Y) by 300.
e.g.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X 4 35 47 12 20 4 10 15 9 70 30 12 33 2 250 14 1 1 90 1 45
3 1 0 7 3

Y 4 1 10 70 33 14 90 35 4 20 43 1 91 30 1 20 250 17 1 1 45
2 7 5 2 3

1st part 2nd part

 in (Y) : calculate the average of the 1st part of the array (a1)
 In (Y) : calculate the average of the 2nd part of the array (a2)
 in (Y) : calculate how many cells < (a1).
 in (Y) : calculate how many cells < (a2).
 Read an array of 300 values. ( Q ).
 Copy One but Two: from (Q) to à (Y) [as explained before].
 in (Y) : calculate the average of the 1st part of the array (a1)
 In (Y) : calculate the average of the 2nd part of the array (a2)
 in (Y) : calculate how many cells < (a1).
 in (Y) : calculate how many cells < (a2).
 In (X) : read new values from the user.
 Copy One but Two: from (X) to à (Y) [as explained before].
 in (Y) : calculate the average of the 1st part of the array (a1)
 In (Y) : calculate the average of the 2nd part of the array (a2)
 in (Y) : calculate how many cells < (a1).
 in (Y) : calculate how many cells < (a2).
 In (Q) : read new values from the user.
 Copy One but Two: from (Q) to à (Y) [as explained before].
 in (Y) : calculate the average of the 1st part of the array (a1)
 In (Y) : calculate the average of the 2nd part of the array (a2)
 in (Y) : calculate how many cells < (a1).
 in (Y) : calculate how many cells < (a2).

Page 3 of 5
University of Modern Sciences & Arts (MSA) End-Term Examination-Spring 2018
Fundmentals of computing (CS-101) Time Allowed: 3 Hours

SECTION (III): FUNCTION DESIGN (Total: 16 marks)


Function 1: (8 marks)
Design a function according to the following aspects:

Input: à means given parameter(s), which already entered before passing it to the function
 A string (X).
 Integer value that represents the nth word. (N).

Output: à means returned value(s) from the function


 A string (Y), that carries
o copy of the nth word
o copy of the word after the nth word , but in reveres.

Example:

Input:
N=4

X w e w a y h e a l t h a l y w e a t h e r y e s \0 …

Output:

Y a l y r e h t a e w \0

Function 2: (8 marks)
Design a function according to the following aspects:

Input: à means given parameter(s), which already entered before passing it to the function
 An array of integers (X).
 Number of values in the array (N).

Output: à means returned value(s) from the function


 4 values à The lowest value for each quarter of the array.

Note: Assume that the size of the array is divisible by 4.


Example:

Input: N = 20

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

X 30 12 20 17 18 21 10 8 71 24 90 80 60 50 70 30 9 14 29 10

Output:

Page 4 of 5
University of Modern Sciences & Arts (MSA) End-Term Examination-Spring 2018
Fundmentals of computing (CS-101) Time Allowed: 3 Hours

ß 12 , 8 , 50 , 9

Page 5 of 5

You might also like