Constructor - Computer Science - Exam, Exams of Computer Science

Main points of this past exam are: Constructor, Destructor, Inheritance, Stored Privately, Class Destructor, Member Function, Inherits

Typology: Exams

2012/2013

Uploaded on 03/30/2013

lallit
lallit 🇮🇳

4

(27)

150 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Page 1 of 4
Bachelor of Engineering (Honours) in Electronic Engineering - Stage 3
(Bachelor of Engineering in Electronic Engineering – Stage 3)
(NFQ – Level 8)
Spring 2005
Computer Science
(Time: 3 Hours)
Read instructions carefully
Section A: Answer any TWO questions
Section B: Answer any TWO questions
Use separate answer books for Sections A and B
All questions carry equal marks
Examiners: Prof. C. Burkley
Mr. J. Ryan
Mr. D. O’Donovan
Mr. F. O’Reilly
Section A
1. (a) Explain the purpose of i) a constructor and ii) a destructor for a class. State and justify the
calling order convention for each during inheritance. [8%]
(b) Define a class called TCharBase which consists of the following:
i. A constructor which dynamically allocates a character. The character’s value should be
supplied as a parameter to the constructor and stored privately.
ii. A member function to return the current contents of a TCharBase object’s character.
iii. An appropriate class destructor. [9%]
(c) Define another class called TCharDerived which inherits the TCharBase as public and
whose member data consists of a character which is dynamically allocated privately.
i.
TCharDerived should have a parameterised constructor which takes two parameters.
Parameter one should initialise the TCharBase constructor and parameter two should
be assigned to the dynamically allocated character in TCharDerived. [5%]
ii. Write a member function for TCharDerived to display both characters. Write
additional member function(s) for the TCharBase class, as required. [3%]
pf3
pf4

Partial preview of the text

Download Constructor - Computer Science - Exam and more Exams Computer Science in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Engineering (Honours) in Electronic Engineering - Stage 3

(Bachelor of Engineering in Electronic Engineering – Stage 3)

(NFQ – Level 8)

Spring 2005

Computer Science

(Time: 3 Hours)

Read instructions carefully Section A : Answer any TWO questions Section B: Answer any TWO questions Use separate answer books for Sections A and B All questions carry equal marks

Examiners: Prof. C. Burkley Mr. J. Ryan Mr. D. O’Donovan Mr. F. O’Reilly

Section A

  1. (a) Explain the purpose of i) a constructor and ii) a destructor for a class. State and justify the calling order convention for each during inheritance. [8%]

(b) Define a class called TCharBase which consists of the following: i. A constructor which dynamically allocates a character. The character’s value should be supplied as a parameter to the constructor and stored privately.

ii. A member function to return the current contents of a TCharBase object’s character. iii. An appropriate class destructor. [9%]

(c) Define another class called TCharDerived which inherits the TCharBase as public and whose member data consists of a character which is dynamically allocated privately. i. TCharDerived should have a parameterised constructor which takes two parameters. Parameter one should initialise the TCharBase constructor and parameter two should be assigned to the dynamically allocated character in TCharDerived. [5%]

ii. Write a member function for TCharDerived to display both characters. Write additional member function(s) for the TCharBase class, as required. [3%]

  1. (a) Describe the purpose of operator overloading and why is it useful? [3%]

(b) What is the purpose of the this pointer? Illustrate its use via an example. [4%]

(c) Define a class called coord, which is capable of representing an x-y coordinate. An example of using such a class is shown in Figure 1. The class should contain the following member functions: i. A parameterised constructor (taking x and y as arguments) with default arguments. [4%] ii. An extractor function to read the x, y coordinates from the keyboard. [5%] iii. An inserter function to display x and y on-screen. [5%] iv. A unary operator, pre-increment ‘++’ i.e. add 1 to x and 1 to y. [4%]

int main(){ coordcin >> a, b(10, 23); a; b++;return 0; } Figure 1

  1. (a) Discuss the benefits of class inheritance. [4%]

(b) #include <iostream.h> class base { public: int i; }; class derived1 : public base { public: int j; }; class derived2 : public base { public: int k; }; class derived3 : public derived1, public derived2 { public: int product() { return i *j * k; } }; main() { derived3 ob; ob.i = 10; ob.j = 3; ob.k = 5; cout << "Product is " << ob.product() << endl;

(b) Explain how in an x86 Processor, Software Interrupts can be used to execute useful library functions. Your answer should describe the Vector Table, format of addresses and registers values read or changed. [8 %]

(c) The following Assembly code fragment of code uses Interrupt 10 with a value of 14h in ah to print out the single character in al.

mov al, ‘F’ push ax mov ah, 14 int 10h pop ax

Write the x86 assembly code placing it in either a macro or procedure, which can be used to print out a line of astrixes (*) 40 chars wide. Show how it would be used. [9 %]

  1. (a) Describe using diagrams the process/sequence by which messages are passed from the Operating System to individual Windows C++ GUI applications. [6 %]

(b) Describe the steps needed to write the following GUI based program in Visual C++. This checks if a string is a palindrome (same when read from both sides) by reversing the string, which was entered in the normal box and outputting the reversed string.

[11 %]

(c) Describe the Graphics Subsystem available in Windows Programming. In particular you answer should explain Device Context, Device Drivers, Virtual Screen, Stock Objects, Viewport. [8 %]