Docsity

Stage 3 Exam for BEng (Hons) in Electronic Engineering - Computer Science, Exams of Computer Science

Toggle sidebar
bg1
Cork Institute of Technology
Page 1 of 5
Bachelor of Engineering (Honours) in Electronic Engineering -
Stage 3
(NFQ – Level 7)
Spring 2006
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. G. Hurley
Dr. S. Foley
Mr. D. O’Donovan
Mr. F. O’Reilly
Section A
1. (a) Explain the concept and purpose of Function overloading. [5 %]
(b) (i) The program in Figure 1.1 makes use of a Default Argument. Indicate where the default
argument is used and describe its purpose. [5 %]
(ii) A problem of ambiguity exists within this program. Explain why the problem exists and
suggest how it may be corrected.
#include <iostream>
using namespace std;
int myfunc(int i);
int myfunc(int i, int j=1);
int main ()
{
cout << myfunc(4, 5) << “ “;
cout << myfunc(10);
return 0;
}
int myfunc(int i) { return i; }
int myfunc(int i, int j) {return i*j; }
Figure 1.1 [6 %]
pf3
pf4
pf5

Partial preview of the text

Download Stage 3 Exam for BEng (Hons) in Electronic Engineering - Computer Science and more Exams Computer Science in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Engineering (Honours) in Electronic Engineering -

Stage 3

(NFQ – Level 7)

Spring 2006

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. G. Hurley Dr. S. Foley Mr. D. O’Donovan Mr. F. O’Reilly

Section A

  1. (a) Explain the concept and purpose of Function overloading. [5 %]

(b) (i) The program in Figure 1.1 makes use of a Default Argument. Indicate where the default argument is used and describe its purpose. [5 %]

(ii) A problem of ambiguity exists within this program. Explain why the problem exists and suggest how it may be corrected. #include using namespace std; int myfunc(int i); int myfunc(int i, int j=1); int main () { cout << myfunc(4, 5) << “ “; cout << myfunc(10); return 0; } int myfunc(int i) { return i; } int myfunc(int i, int j) {return i*j; }

Figure 1.1 [6 %]

(c) Write the code necessary to overload the abs function such that it may be used as shown in Figure 1.2. int main() { cout << abs(-10) << ‘\n’; cout << abs(-11.0) << ‘\n’; cout << abs(-9L) << ‘\n,’; return 0; } Figure 1.2 [9 %]

  1. (a) What is a copy constructor and how does it differ from the assignment operator? During your discussion, describe the circumstances under which each is called and illustrate using examples. [9 %]

(b) (i) Describe the exception mechanism used for error handling in C++. [3 %] (ii) Write code to illustrate how an int may be tested to see if it is within a valid range e.g. 10 – 100. Any value outside this range should be considered an error and an exception should be generated to deal with this circumstance. [5 %]

(c) How is memory dynamically allocated in C++? During your discussion, mention: o why malloc and free still exist but are no longer in use. o the distinction made between the dynamic allocation of a single and an array of classes giving code examples of each to illustrate your point. [8 %]

  1. (a) Consider the following C++ program. #include using namespace std; class base { int i; public: void set_i(int num); i=num; int get_i() { return i; } };

class derived: public base { int j; public: void set_j(int num) { j=num; } int get_j(){ return j; } };

Section B

Q4 (a) What are the main features of the C Calling Convention? Explain with examples what impacts this has when interfacing C and assembly language programs. [8 %]

(b) Given the following C++ fragment, write a routine AddDivide3 in x86 assembly which takes as parameters three integers and adds the first two parameters together before dividing the result by the third parameter, an integer division is sufficient.

extern AddDivide3(int X, int Y, int Z); int nNewX, nNewY, nNewZ; cin >> nNewX, nNewY, nNewZ; cout < “The Result is “ << AddDivide3(nNewX,nNewY,nNewZ) << endl; [11 %] (c) Compare and contrast the Graphical User Interface system as used in Windows and Unix, describing how they integrate with the operating system and their features. [6 %]

Q5 (a) The following Assembly code fragment of code uses BIOS Interrupt 10 with a value of 14h in ah to print out the single character in al. In this case ‘F’.

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 on one line the alphabet in reverse order and then move to the start of a new line. The ASCII codes 10 and 13 achieve a carriage-return and line feed. [9 %]

(b) Explain the concept of Memory Segmentation as it applies to the Intel x86 family of micro- processors, including what segments there are, how physical addresses can be calculated and the different registers used to support segmentation. Give one way that segments can be specified/identified in x86 assembly programs. [8 %]

(c) Draw a diagram showing the relationship of MFC and Windows 32 API/SDK with Windows and explain what they are and the functionality that they bring. In MFC what is the relationship between CWnd, CDialog and CView? [8 %]

Q6 (a) The following GUI was created using MS-Visual C++. Note no code has yet been written. What tools have been used to create this entire GUI and how do they work? What are the names given to component elements in this GUI? How are they identified in the program? [8 %]

(b)Write the program which will do the above interest calculation, section (a). Describe which tools need to be used and follow the steps which need to be done before writing this code. Provide the C++ code to read in the values from the GUI, perform the calculation and output the results above. [9 %]

(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 %]