0% found this document useful (0 votes)
11 views4 pages

00 Examinations

The document is a mid-term examination paper for the Fundamentals of Computing II course at the University of Modern Sciences & Arts, covering various programming problems. It includes sections on tracing problems with C++ code and problem-solving tasks involving matrix manipulation and robot structures. The examination allows a total of 20 marks, split between tracing problems and problem-solving tasks.
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)
11 views4 pages

00 Examinations

The document is a mid-term examination paper for the Fundamentals of Computing II course at the University of Modern Sciences & Arts, covering various programming problems. It includes sections on tracing problems with C++ code and problem-solving tasks involving matrix manipulation and robot structures. The examination allows a total of 20 marks, split between tracing problems and problem-solving tasks.
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/ 4

University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2003-2004

Fundmentals of computing II (CS-201) Time Allowed: 2.5 Hours

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


In this section, if there are any Garbage values, then display ‘?’ instead.

(Q1) (4 marks)

Display the output of the following program:

#include <iostream.h>
void main()
void DoIt(int **y) {
{ int **y;
int base = 10; y = new int*[2];
for (int r=0; r<2; r++) for (int i=0; i<2; i++)
{ y[i] = new int[3];
for (int c=0; c<3; c++)
{ DoIt(y);
y[r][c] = base; Come(y);
base += 10;
} y++;
} Come(y);
}
y[0]++;
void Come(int **y) Come(y);
{
for (int r=0; r<2; r++)
{ }
for (int c=0; c<3; c++)
{
cout<<y[r][c]<<" ";
}
cout<<endl;
}
}

Page 1 of 4
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2003-2004
Fundmentals of computing II (CS-201) Time Allowed: 2.5 Hours

(Q2) (4 marks)

Display the output of the following program:

#include <iostream.h>

void Allocate(int *x)


{
x = new int[3];
for (int i=0; i<3; i++)
x[i] = i;
}

void Give(int * & x)


{
x = new int[3];
for (int i=0; i<3; i++)
x[i] = (i+1) * 10;
}

void Modify(int *x)


{
for (int i=0; i<3; i++)
x[i] += 5;
}

void Display(int *x)


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

void main()
{
int *x;

Allocate(x);
Display(x);

Give(x);
Display(x);

Modify(x);
Display(x);

Allocate(x);
Display(x);
}

Page 2 of 4
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2003-2004
Fundmentals of computing II (CS-201) Time Allowed: 2.5 Hours

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

Problem 1: (6 marks)

Write a program to do the followings: -


 Read a squared matrix call it (X), with dimensions (n x n).
 Scan the right diagonal from left-bottom corner up to the right-top corner.
But stop if you reach some negative value.
 Create another irregular matrix (Y) that carries the rows, which scanned from the previous
step.

X
1 6 70 6 3 5 55

2 9 19 21 -6 12 10

5 30 17 30 -4 11 11
Y
17 14 15 20 22 24 10 20 22 24 10

3 5 6 4 12 20 35 6 4 12 20 35

88 18 7 10 16 5 8 18 7 10 16 5 8

5 15 25 11 60 4 3 5 15 25 11 60 4 3

 For each row in the (Y), determine the largest sorted interval.
 Create a third irregular matrix (Z) that carries the largest sorted intervals from (Y).

Y Z
20 22 24 10 20 22 24
6 4 12 20 35 4 12 20 35
18 7 10 16 5 8 7 10 16
5 15 25 11 60 4 3 5 15 25

 Display the irregular matrix (Y) and the irregular matrix (Z).

Problem 2: (6 marks)

Page 3 of 4
University of Modern Sciences & Arts (MSA) Mid-Term Examination-Fall 2003-2004
Fundmentals of computing II (CS-201) Time Allowed: 2.5 Hours

Note:
Assume there is a Robot carries number of balls in each of his arms.

Define a structure to represent the Robot as the followings:


 The location of the Robot (x, y coordinates).
 Number of balls in the right arm.
 Number of balls in the left arm.
 The weight for each ball in the right arm.
 The weight for each ball in the left arm.

Write a program to do the followings:


 Read the information for N Robots.
 Ask the user to select a Robot (the user will identify it using his index), and determine if his
arms are balanced or not.

NOTE:
The arms will be balanced if the difference between the total weights in the left arm
and the total weights in the right arm was < 25.

 Ask the user to select a location (x, y coordinates), and display the information for all Robots
are in this location.
 Ask the user to select 2 Robots, also make him to specify an arm (the left or the right one).
Then your program should swap the balls in the specified arm between the 2 selected Robots.

Page 4 of 4

You might also like