0% found this document useful (0 votes)
187 views

CC 319 Final Summer 2020

This document contains a final exam paper for an Advanced Programming course. It consists of 5 questions testing concepts like operator overloading, inheritance, interfaces, exceptions, and polymorphism. Question 1 has 6 multiple choice questions on topics like calling methods, operator precedence, and exception handling. Question 2 asks students to write methods for word counting, exception throwing, and string concatenation. Questions 3 and 4 involve determining output for code snippets and implementing a Student class. Question 5 asks students to write an interface for calculating asset maintenance costs and test it polymorphically.

Uploaded by

Manar Abdelmeged
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views

CC 319 Final Summer 2020

This document contains a final exam paper for an Advanced Programming course. It consists of 5 questions testing concepts like operator overloading, inheritance, interfaces, exceptions, and polymorphism. Question 1 has 6 multiple choice questions on topics like calling methods, operator precedence, and exception handling. Question 2 asks students to write methods for word counting, exception throwing, and string concatenation. Questions 3 and 4 involve determining output for code snippets and implementing a Student class. Question 5 asks students to write an interface for calculating asset maintenance costs and test it polymorphically.

Uploaded by

Manar Abdelmeged
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Arab Academy for Science, Technology & Maritime Transport

College of Engineering and Technology


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

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.

2. Consider the code:

Console.WriteLine($"Initial name is: {myAccount.GetName()}");

Which method is called first?


a) WriteLine
b) GetName
c) They execute at the same time.
d) None of the above.

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

5. What does the following code display?


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

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

Page 1 of 5 MPCNQ 2/3


c) a run-time error occurs
d) the program compiles and runs correctly because the instance variables are initialized to their default
values

Question # 2 (12 marks) (ILO A9)

1. Write a C# method that accepts as input :


a paragraph string (Ps) (possibly of multiple sentences)
a query string of one sentence (Qs) from user ,
then determines:
(a) the number of words in the Ps string that are terminated by :' ed ' or ' ing'.
(b) whether Qs is present within Ps or not.
Hint: Phrases in Ps needs to be separated, then compared to Qs. Phrases are 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 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;

Page 2 of 5 MPCNQ 2/3


6. for (a = 0; a < 5; a++)
7. {
8. int i = 200;
9. Console. WriteLine(a * i);
10. }
11. Console. ReadLine();
12. }
13. }

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 ");
}
}

Page 3 of 5 MPCNQ 2/3


class Derived : Baseclass
{
public Derived(int ii) : base(ii)
{
Console.Write("Derived ");
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Derived d = new Derived(10);
}
}
}

Question # 4 (8 marks) (ILO B3 and ABET Outcome 2)

Implement class Student 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 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.

Question # 5 (6 marks) (ILO A3 and ABET Outcome 2)

Page 4 of 5 MPCNQ 2/3


In a company, the finance department would like to control the assets owned by the company. The assets
are Buildings and Machinery.
Write an interface IAssets with a GetMaintenanceCost method. Each of your assets classes should
implement that interface, so that its GetMaintenanceCost method calculates an appropriate maintenance
for each class.
The spent cost on Buildings is calculated based on the number of meters per building and
maintenance price per meter, while the Machinery maintenance amount is calculated using the
original price of the machine and the applied depreciation percentage.
Write a test class that creates an object of each of the two classes, places references to those objects in an
array of IAssets type , then iterates through the array, polymorphically invoking each object’s
GetMaintenanceCost method.

Page 5 of 5 MPCNQ 2/3

You might also like