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

28 Prog I Examinations

The document contains details about an exam for a fundamentals of computing course. It includes three sections - tracing problems, problem solving, and function design. For the tracing problems, it provides code snippets and asks to display the output. For problem solving, it provides a complex problem to write a program to manipulate arrays based on user input regions. For function design, it asks to design two functions - one to modify a string and another related to array differences.
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)
106 views5 pages

28 Prog I Examinations

The document contains details about an exam for a fundamentals of computing course. It includes three sections - tracing problems, problem solving, and function design. For the tracing problems, it provides code snippets and asks to display the output. For problem solving, it provides a complex problem to write a program to manipulate arrays based on user input regions. For function design, it asks to design two functions - one to modify a string and another related to array differences.
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-Fall 2017-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 p[] , int j )


{
for (int i=j ; i < 4 ; i++)
{
cout<<p[i]<<" | ";
}
cout<<endl;
}

void DoThat(int &a, int & b)


{
b+=a;
a =b;
}

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

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


{
DoThat(x[i], x[i+1]);
}

DoIt( x , 0);

for (int i=3; i>0; i--)


{
DoThat(x[i], x[i-1]);
DoIt( x , i);
}

DoIt( x , 0);
}

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

(Q2) (4 marks)

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


{

for (int k=i; k<a; k+=2)


{
cout<< x[k];
}
}

void main()
{
char x[] = { 'E', 'T', '|', 'R' , 'i', 'A', 't' , 'C' , '\0'};

DoIt(x , 1 , 8);
DoIt(x , 0 , 8);

Page 2 of 5
University of Modern Sciences & Arts (MSA) End-Term Examination-Fall 2017-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 200 values. ( X ).
 Ask the user to select region.
 Generate another array (Y) with size 200 from array (X) according to the following protocol:
o In selected region of (X), if the value appeared in other regions twice, then copy it at
the start of (Y).
o In selected region of (X), if the value appeared in other regions just one time, then
copy it at the end of (Y).
o Fill the reminder cells of (Y) by (the largest value in the selected region of X).

e.g region >> [S=8 E= 14]

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
X 4 120 70 12 25 43 10 1 90 70 30 55 91 20 25 14 7 1 2 13 30 42 20
5 0 0

Y 70 2 91 9 91 91 9 91 9 91 91 9 91 9 91 91 9 91 9 91 9 25 30
0 1 1 1 1 1 1 1 1

 in (Y) : calculate how many odd values in the 2nd half of the array (A)
 In (X) : calculate how many odd values in the 1st half of the array (B)
 in (Y) :Add (A) to all cells.
 in (X) :Subtract (B) from all cells.
 Read an array of 600 values. ( Q ).
 Using the mentioned protocol: Generate another array (Z) with size 600 from array (Q).
 In (X) : read new values from the user.
 Using the mentioned protocol: Generate another array (Y) from array (X).
 In (Y) : read new values from the user.
 Using the mentioned protocol: Generate another array (X) from array (Y).
 in (Y) : calculate how many odd values in the 2nd half of the array (A)
 In (X) : calculate how many odd values in the 1st half of the array (B)
 in (Y) :Add (A) to all cells.
 in (X) :Subtract (B) from all cells.
 Read an array of 600 values. ( W ).
 Using the mentioned protocol: Generate another array (Z) from array (W).
 in (Z) : calculate how many odd values in the 2nd half of the array (A)
 In (W) : calculate how many odd values in the 1st half of the array (B)
 in (Z) :Add (A) to all cells.
 in (W) :Subtract (B) from all cells.
 In (X) : read new values from the user.
 Using the mentioned protocol: Generate another array (Y) from array (X).
 in (Z) : calculate how many odd values in the 2nd half of the array (A)

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


In (W) : calculate how many odd values in the 1st half of the array (B)

in (Z) :Add (A) to all cells.
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 modified string (X), that carries all words from (X), but with insertion of the non-vowels of
the nth word
Note: the insertion should be at the first of the array
Note: vowels { a , i , o ,u , e}
Note: No permission to use temporary array

Example:

Input:
N=3

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:

X’ H L T H 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 …

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


 The difference between the 1st 2 cells (Diff)
 How many times , there are 2 contiguous cells with difference equals to (Diff)

Example:
Input:
N = 22

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 17 18 19 2 21
X 6 0
3 11 20 10 18 8 10 21 71 4 30 21 29 19 50 1 9 14 29 0 5 13

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

Output:
ß Diff :8 [11 – 3 ]
ßDiff appeared : 5 times

Page 5 of 5

You might also like