You are on page 1of 6

Arab Academy for Science, Technology & Maritime Transport

College of Engineering and Technology


Final Examination Paper
Department: Computer Engineering Date : 9 June 2020
Course Title: Advanced Programming Time : 2 Hours
Course Code: CC319 Marks: 30
Lecturer: Dr. Karma Fathalla

FINAL EXAM
Attempt all the following questions
Question # 1 (6 marks) (ILO A5)
1. Given the following using directive statement
using Systems.Math;
Which of the following correctly calls the Math class method Sqrt with a value of 36?
a) Sqrt(36);
b) Math.Sqrt(36);
c) Both a and b
d) Compilation error as there is no calling object.

2. Let x be a double. How can you typecast a double into a float?


a) implicitly
b) x(float)
c) (float)x
d) x = float

3. Which of the following methods I, II, III and IV are overloaded?


I. public int max (int a, int b) { … }
II. public double max (double a, double b) { … }
III. public int max (int a, int b, int c) { … }
IV. public double max (double a, double b, double c) { … }

a) I and II are overloaded; III and IV are overloaded


b) I and III are overloaded; II and IV are overloaded
c) I, II and III are overloaded
d) All these four methods are overloaded

4.Which of the following initializer lists would correctly set the elements of array n?
a) int[] n = {1, 2, 3, 4, 5};
b) array n[int] = {1, 2, 3, 4, 5};
c) int n[5] = {1; 2; 3; 4; 5};
d) int n = new int(1, 2, 3, 4, 5);

5. Consider the array:


s[0] = 7
s[1] = 0
s[2] = -12
s[3] = 9
s[4] = 10
s[5] = 3
s[6] = 6
The value of s[s[6] - s[5]] is:
a) 0
b) 3

Page 1 of 6 MPCNQ 2/3


c) 9
d) 0
6. When an exception is caught, the program can access the exception object’s built-in ________
property to get the error message and display it.
a) Error
b) Fault
c) Message
d) Note

7. Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is
called with changeArray(items, items[2]), what values are stored in items after the method has
finished executing?
public static void ChangeArray(int[] passedArray, int value)
{
passedArray[value] = 12;
value = 5;
}
a) 0, 2, 5, 6, 12
b) 0, 2, 12, 6, 8
c) 0, 2, 4, 6, 5
d) 0, 2, 4, 6, 12

8. When a derived class constructor calls its base class constructor, what happens if the base
class’s constructor does not assign a value to an instance variable?
a) a syntax error occurs
b) a compile-time error occurs
c) a run-time error occurs
d) the program compiles and runs correctly because the instance variables are initialized to
their default values

9. Which base class members are inherited by all derived classes of that base class?
a) private instance variables and methods
b) protected instance variables and methods
c) protected constructors
d) Both b and c

10. A class that implements an interface but does not declare all of the interface’s methods must
be declared:
a) public
b) interface
c) abstract
d) final

11. A catch block that does not specify an exception type or an identifier ____________
a) is an error
b) cannot catch any exceptions
c) can catch any exceptions
d) None of the above

12. What does the following code display?


string example = “C#_Programming”;
Console.Write(example.Substring(3, 5);
a) _Pr
b) _Prog
c) Pro

Page 2 of 6 MPCNQ 2/3


d) Progr
Question # 2 (8 marks) (ILO A3 and B3)

1. Write a C# method that accepts a string (possibly of multiple sentences), then determines:
(a) the number of phrases in the string.
(b) Verify that the beginning of each word is an alphabet.
If an alphabet is found at the beginning of the word, convert it to upper case. Otherwise, print the
message "Invalid Start Character"
Hint: Phrases can be separated by (.) or (,)
Take care that you don't count decimal number as phrases (Example: 3.96 although contains a (.) should
not be counted a phrase)

2. Implement a user defined exception method overloading the division operator ' / ' redefined for two
strings , which operates on two strings as operands: s1/s2. The overloaded operator should truncate the
longer string of the two and trim it to the shorter string length. Then, the operator returns the trimmed
string.
Question # 3: (5 marks) (ILO A1)
Determine the output of each of the following C# code snippets; show your working steps and/or
the explanation (when needed) for your described Output. Note symbol indicates a new line.

Page 3 of 6 MPCNQ 2/3


Page 4 of 6 MPCNQ 2/3
Question # 4 (7 marks) (ILO A5 and ABET Outcome 2)

Implement class Customer Service (CS) Banker with the shown UML class diagram.

 You can use auto-implemented properties in case no validation or formatting is necessary. For
properties:
o YearOfBirth, you need to validate that the customer service banker is at least 22 years old.
(Hint: you can use the following code to retrieve the current year : DateTime now =
DateTime.Now; now.Year;)
o WeeklyServedClients, the maximum number of clients to be served per week is 30 clients.
o WeeklyClientRating, there are only five valid client ratings E, V, G, S, U.

 CalculateClientSatisfaction method computes the weekly score for client satisfaction attained by this
banker as the sum of the weekly client rating scores divided by the number of served clients per week .
The following shows the correspondence between the client ratings and scores.
E = 10 score
V= 7.5 score
G = 5 score
S = 2.5 score
U = 0 score
For bankers who did not serve any clients, a DivideByZeroException would be thrown. Handle
this exception and output the statement: "Client Satisfaction calculation is not possible"
 PrintStatement method displays the CS banker Name, Year of Birth and number of served clients.
 Implement a TestClass to verify the behavior of the CSBanker class.

Page 5 of 6 MPCNQ 2/3


Question # 5 (4 marks) (ILO A1 and ABET Outcome 2)
In a company, the finance department would like to estimate the expected revenue to be received. The
revenue is to be calculated based on Sold Items and Purchases Discounts.
Write an interface IRevenue with a GetRevenueAmount method. Each of your revenue classes should
implement that interface, so that its GetRevenueAmount method calculates an appropriate revenue
estimate for each class.
The received income on Sold Items is calculated based on the number of items sold and their average
price, while the Purchase Discounts amount is calculated using the number of items times, the price
per item and the applied percentage discount.
Write a test class that creates an object of each of the two classes, places references to those objects in an
array of IRevenue type , then iterates through the array, polymorphically invoking each object’s
GetRevenueAmount method.

Page 6 of 6 MPCNQ 2/3

You might also like