CC 319 Final Summer 2020
CC 319 Final Summer 2020
FINAL EXAM
Attempt all the following questions
Question # 1 (6 marks) (ILO A3)
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) Abs(-36);
b) Math.Abs(-36);
c) Both a and b
d) Compilation error as there is no calling object.
3. 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
4. If an exception is thrown in a catch handler, any code in the handler that follows the thrown
exception will:
a) generate a syntax error
b) generate a logic error
c) never be executed
d) run after the finally block is done
6 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
2. Implement a user defined exception class that is thrown in case that the input age is below 18. An
exception message of "Transaction not accepted. Below the legal age"
3. Implement operator overloading for the multiplication operator ' * ' redefined for two strings , which
operates on two strings as operands: s1*s2. The overloaded operator should add exclamation marks (!) to
the shorter string of the two until it reaches the longer string length. Then, the operator returns the
extended string.
Question # 3: (8 marks) (ILO A6)
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.
Snippet 1:
1. class sample
2. {
3. public int i = 10;
4. public int j = 20;
5. public void display()
6. {
7. Console.WriteLine("base method ");
8. }
9. }
10. class sample1 : sample
11. {
12. public int s = 30;
13. }
14. class Program
15. {
16. static void Main(string[] args)
17. {
18. sample1 obj = new sample1();
19. Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s);
20. obj.display();
21. Console.ReadLine();
22. }
23. }
Snippet 2:
1. class Program
2. {
3. public static void Main(string[] args)
4. {
5. int i = 100;
Snippet 3
namespace CC319FinalExam
{
class Baseclass
{
public void fun()
{
Console.WriteLine("Hi" + " ");
}
public void fun(int i)
{
Console.Write("Hello" + " ");
}
}
class Derived: Baseclass
{
public void fun()
{
Console.Write("Bye" + " ");
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Derived d;
d = new Derived();
d.fun();
d.fun(77);
}
}
}
Snippet 4
namespace CC319FinalExam
{
class Baseclass
{
int i;
public Baseclass(int ii)
{
i = ii;
Console.Write("Base ");
}
}
You can use auto-implemented properties in case no validation or formatting is necessary. For
properties:
o YearOfBirth, you need to validate that the student is at least 15 years old. (Hint: you can
use the following code to retrieve the current year : DateTime now = DateTime.Now;
now.Year;)
o TermCreditHours, the maximum allowed number of courses is 6 with a total of 18 hours.
o TermCoursesGrades, there are only five valid course grades A, B, C, D, F.
CalculateTermGPA method computes the term GPA as the sum of the term courses grade points
divided by credit hours. The following shows the correspondence between the letter grades and the
grade points.
A = 4.00 grade points
B = 3.00 grade points
C = 2.00 grade points
D = 1.00 grade points
F = 0.00 grade points
For drop out students, who don't take courses in a term or fresh students during their first term a
DivideByZeroException would be thrown. Handle this exception and output the statement:
"GPA calculation not possible for current term"
PrintStatement method displays the Student Name, Year of Birth and Credit hour achievement.
Implement a TestClass to verify the behavior of the Student class.