You are on page 1of 1

Question 1 (2 Marks)

Let, fun be a function defined as follows:


void fun(int& alpha, int beta )
{
alpha = beta;
beta = 10;
}
What is the output of the following instructions?
int a = 5;
int b = 5;
fun(a,b);

cout << "a= " << a << ", b= " << b << endl;

Question 2: (2 Marks)

Given the following function definition


int foo(int a, int b)
{ if (a < b)
return a * 10;
else return b
+ 6;
}
What is the output of the following instruction?
cout << foo(foo (9, 5), foo(8, 10)) << endl;

Question 3: (2 Marks)
The following function is supposed to increment a variable, passed to it by reference.
int increment(const int& a){
return a++;
}

• What is wrong with this function?


• How to fix it?

Question 4: Programming (4 Marks)


Write a program to prioritize, and output to the screen, an array of medical emergencies at a hospital. As
individual emergencies arrive, each is placed into the array, with those of higher priority being put in front of
others. Three levels of priority exist, specifically 1 (highest), 2 (medium) and 3 (lowest). When an emergency
is inserted into the array, all those of lower priority must be moved back, using a function, to create a space
for the higher priority emergency. For example, if the array contains, from front to back, the emergencies {2,
2, 3}, and a priority 1 emergency arrives, then the array, after the insertion, would contain the emergencies
{1, 2, 2, 3}.
Your submission should include a screenshot of the execution of the program + the CPP file.

You might also like