CS代考 CE221-5-AU

CE221-5-AU

Candidates must answer ALL questions.

Copyright By PowCoder代写 加微信 powcoder

Question 1

(a) Write a C++ main function that will print “hello world” to standard output.

(b) Using object orientation, create a class called ‘hello’ which prints hello world to [15%] standard output. Create an instantiation of hello from a main function. Make sure

you separate the code into three files: one containing the main, one the header file for the class definition and one for the class implementation. Remember to fully document your code.

CE221-5-AU

Question 2

(a) Concisely explain what you understand by operator overloading. Include in your [5%] answer an example of when this might be a useful tool to the programmer.

(b) The code fragment given below uses operator overloading. Give a line by line [5%] explanation of what the code does and ultimately describe what the program will

print to standard output.

How would you separate the program into three separate files: Employee.h, [5%] Employee.cpp and Main.cpp?

(d) Briefly explain the difference between operator overloading and function [5%] overloading giving an example for each.

#include

#include

Using namespace std;

Class Employee

string name;

double wage;

Employee(string title, double salary){

this->name=title;

this->wage=salary;

bool operator+ (Employee &e){

return wage < e.wage; Employee a(“Johny” ,25000.0); Employee b(“Freddy”,30000.0); String name = (a+b)? a.name: b.name; Cout << name << endl; CE221-5-AU Question 3 (a) Computer memory used for a developer’s program has four basic areas: (i) the [5%] code including constants; (ii) the static area; (iii) the stack; and (iv) the heap. Concisely describe what each of these areas does and how a programmer can control which area is used at a particular time. (b) A variable has three major attributes: type; lifetime and scope. Concisely describe [5%] what you understand by these terms giving an example for each. (c) A variable definition can be preceded by the terms extern and static. Explain [5%] what each of these mean giving an example for each one. (d) One often encounters the term Namespace in C++ code. What does Namespace [5%] mean and what function does it perform? Give an example of the use of Namespace. CE221-5-AU Question 4 (a) Briefly describe what you understand by the term Template in C++, include in your answer a definition of the Standard Template Library (STL). (b) The STL has a Vector container which could be argued as being superior to using [5%] an array. Compare and contrast the use of an array and a Vector container. (c) Containers can be categorised as: (i) sequence containers and (ii) associative [5%] containers. What do these two terms mean when referring to C++ containers? (d) Write example code to create a vector of strings and load the following five [5%] strings: “hello”, “and”, “welcome”, “to”, “CE221”. Once you have done this print the contents of the Vector to standard output. Remember to document your code. CE221-5-AU Question 5 (a) Concisely describe what you understand by the two terms: inheritance and virtual [5%] function polymorphism in C++. (b) Two terms regularly used to describe when to and when not to use inheritance in [5%] object oriented programming are: “is-a” and “has-a”. How can these expressions guide the decision whether to use inheritance or whether to use composition when programming in C++? (c) Using a simple piece of example code show the syntax required for the class [5%] “Rectangle” to inherit the attributes of class “Polygon”. (d) How is it possible to prevent some methods and variables from being inherited [5%] from the parent to the child when using inheritance, show this by giving example code. END OF PAPER CE221-5-AU 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com