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

19 CS 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)
82 views5 pages

19 CS 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 2013

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)

#include <iostream.h>

void DoIt ( int &a , int &b )


{
a = b;
b += a;
}

void OK ( int q[ ] )
{
for (int i=0; i<6; i++)
cout<<q[i]<<" , ";
cout<<endl;
}

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

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


{

z = x[i+1];

DoIt(x[i], z);

OK(x);
}

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

(Q2) (4 marks)

#include <iostream.h>

void Please(char x, char y)


{
x = y;
}

void Pls(char &x, char y)


{
x = y;
}

void Yes( char x[ ] )


{
int i=0;
while( x[i] != 'a' )
{
if (i % 2 == 0)
{
Please(x[i], x[0]);
}
else
{
Pls(x[i] , x[0]);
}
i++;
}
}

void main()
{
char x[ ] = { 'W' , 'E' , 'L' , 'C' , 'O' , 'M' , 'E' , 'a' , 't' , 'm' , 's' , 'a' , '\0' };

Yes(x);
cout<<x<<endl;
}

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

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


Problem 1: (16 marks)
Write a program to do the following:
 Read an array of 100 values (X). 1
 Read a value (N).
e.g. Say N : 5
First N Cells Last N Cells

X 6 2 7 11 23 35 4 75 23 74 20 9 30 14 83 33 81 65 16 3 40 12 60 70
5 4

 Look to (the first N cells + the last N cells), and reverse them. 3
Before the reverse à [ 6 , 25 , 7 , 11 , 23 , 34 , 40 , 12 , 60 , 70 ]

After the reverse à [ 70 , 60 , 12 , 40 , 34 , 23 , 11 , 7 , 25 , 6 ]

X 70 60 12 40 3 35 4 75 23 74 2 9 30 14 83 33 8 65 16 23 11 7 2 6
4 0 1 5
1
 Calculate the average (avg) of the (in-between cells)

in-between cells

X 70 60 12 40 3 35 4 75 23 74 2 9 30 14 83 33 8 65 16 23 11 7 2 6
4 0 1 1 5
1  Add (avg) to each cell in the last N-cells.
 Look to (the first N cells + the last N cells), and reverse them.
 Read new array of 100 values (Y).
1  In (Y) : Calculate the minimum of the odd values only (MinOddY). 1.5
 In (Y) : Look to (the first N cells + the last N cells), and reverse them. 1
 In (Y) : Add (MinOddY) to each cell in the first N-cells.
 In (X) : Calculate the minimum of the odd values only (MinOddX).
 In (X) : Add (MinOddX) to each cell in the first N-cells.
 In (X) : Look to (the first N cells + the last N cells), and reverse them.
 Read new (100) values for the array (X).
 Read new (100) values for the array (Y).
 In (Y) : Calculate the average (avg) of the (in-between cells).
 In (Y) : Add (avg) to each cell in the last N-cells.
 In (Y) : Add (avg) to each cell in the first N-cells. 4
 In (X) : Look to (the first N cells + the last N cells), and reverse them.
 In (Y) : Look to (the first N cells + the last N cells), and reverse them.
 In (X) : Calculate the minimum of the odd values only (MinOddX).
 In (X) : Add (MinOddX) to each cell in the last N-cells.
 Read new array of 100 values (Q).
 In (Q) : Look to (the first N cells + the last N cells), and reverse them.
 In (Q) : Calculate the minimum of the odd values only (MinOddQ).
 In (Q) : Add (MinOddQ) to each cell in the last N-cells.

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

 In (Q) : Calculate the average (avg) of the (in-between cells).


 In (Q) : Add (avg) to each cell in the first N-cells.
SECTION (III): FUNCTION DESIGN (Total: 16 marks)
Function 1: (8 marks)
Design a function according to the following aspects:

Input:
 A string (X).

Output:
 The number of words in (X).
 The same string (X) that modified as the following :
Repeat the word before the last one.

Example:

Input:

W E L C O M E T R A i L H E L L O G O O D \0 ..
X

Output:
The number of words : 4

X’ W E L C O M E T R A i L H E L L O H E L L O G O O D \0

Note : you have no permission to use any temporary array.

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

Input:
 An array of integers (X).
 Number of values in the array (N).

Output:
- How many cells equal to the maximum value in the array.
- How many cells equal to the minimum value in the array.

Example:
Input: N = 10

X 12 80 7 60 25 4 80 30 4 4
0

Since ( the maximum value is : 80 ,and the minimum value is : 4 )


Output:

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

2
3

Page 5 of 5

You might also like