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

03 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)
108 views5 pages

03 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 2005

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

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


Display the output of the following programs:

(Q1) (4 marks)

#include <iostream.h>

void DoIt(int x[])


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

void main()
{
int x[] = {10, 20, 15, 40, 50};

DoIt(x);

for (int i=4; i>1; i-=2)


{
x[i] -= x[i-2];
}

DoIt(x);
}

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

(Q2) (4 marks)

#include <iostream.h>

void Display(int x[])


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

void DoIt(int x[], int &n)


{
for (int i=0; i<4; i++)
{
n += x[i];
}
Display(x);
}

void main()
{

int x[] = {10,20,30,40};

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


{
DoIt(x, x[i]);
}
}

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

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


Problem 1: (15 marks)

Write a program to do the followings:


 Read an array of values with size = 100. (X)
 Ask the user to enter 2 values (N1 , N2).
 Find the minimum value in all intervals that surrounded by N1, N2.

SAY that
N1 : 17
N2 : 5

X 3 13 1 17 4 33 5 22 1 5 80 1 14 30 9 1 5 7 9 8
4 7 2

The minimum of all values (4, 33) à (14, 30, 9, 12) in between is: 4.

 Add this minimum value (4), to all cells in the array.

7 1 18 21 8 37 9 26 5 9 84 21 18 34 13 16 9 11 13 12
7

 Display the average of the array.


 Find the minimum value in all intervals that surrounded by N1, N2.
e.g.
in this state of example the minimum will be: 8.

 Subtract this minimum value (8), from all cells in the array.
 Display the average of the array.

-1 9 10 1 0 2 1 1 -3 1 7 13 10 26 5 8 1 3 5 4
3 9 8 6

 Find the minimum value in all intervals that surrounded by negative values
e.g.
in this state of example the minimum will be: 0.
 Add this minimum value (0), to all cells in the array.
 Display the average of the array.

Page 3 of 5
University of Modern Sciences & Arts (MSA) End-Term Examination-Spring 2005
Fundmentals of computing for engeeris (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:
 A string. (X)
 A string. (Y)
 Index (N) of needed word in X.

Output:
 A third string (Z), that carries all concatenations between the nth word in (X) + each word in
(Y).

Example:

Input:
N=2
X t o r e o n \0 .. .. .. .. .. .. .. .. .. .. ..

Y a d w a r d l Y \0 .. .. .. .. .. .. .. .. ..

Output:

Z r e a d r e w a R d r e l y \0 .. .. ..

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

Function 2: (8 marks)

Design a function according to the following aspects:


Input:
 An array of 30 values (X).
 Another array of 30 values (Y).
 Some index (N).

Output:
 A third array (Z) that contains a copy of the following values:
- Go forward in array (Y) , and go backward in array (X).
- Copy one cell from Y, and one cell from X, and so on.
- Stop coping when you reach some boundary of any array of both.
- Fill reminder cells in (Z) be zeros.
- The number of non-zero cells in (Z).

Example:

Input:

N=3

X 9 14 79 17 8 15 12 16 3 82

Y 7 61 88 12 45 15 8 22 10 58

Output:

Z 45 7 15 1 8 9 0 0 0 0
9 4

Page 5 of 5

You might also like