首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导1102UAC语言、讲解program程序、C++编程语言调试 讲解R语言编程|讲解Java程序
项目预算:
开发周期:
发布时间:
要求地区:
Primary Examination, Semester 1, 2019
Object Oriented Programming
COMP SCI 1102, 1102UAC
Official Reading Time: 10 mins
Writing Time: 120 mins
Total Duration: 130 mins
Questions Time Marks
Answer all 9 questions 120 mins 120 marks
120 Total
Instructions for Candidates
• This is a closed-book examination.
• Begin each answer on a new page.
• Examination material must not be removed from the examination room.
Materials
• Calculator without network capability permitted.
• Paper dictionaries and translation dictionaries permitted.
DO NOT COMMENCE WRITING UNTIL INSTRUCTED TO DO SO
COMP SCI 1102, 1102UAC Page 2 of 13
Primary Examination, Semester 1, 2019
Computer Architecture, Memory and Data Representation
Question 1
(a) The basic layout of memory can be divided into four main areas. What are
they and what are they used for?
[6 marks]
(b) Give a short description to explain each of the following statements, including
any terms used.
i. We sometimes have to defragment the heap.
[2 marks]
ii. Local variables within a function do not need to be explicitly deleted when
you return from that function.
[2 marks]
(c) What is the decimal number 126 in binary notation? Note: the most signifi-
cant bit should be on the left hand side. Show your working.
[2 marks]
(d) What is the decimal value of the hexadecimal number 0xFE? Show your working.
[3 marks]
[Total for Question 1: 15 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 3 of 13
Primary Examination, Semester 1, 2019
Pointers
Question 2
(a) Provide a single line of C++ code that will declare a variable that is a pointer
to an int value, where the variable is named i1.
[2 marks]
(b) You have array exam19 declared as
int *exam19[6];
Give the single line of C++ code that will assign the int pointer stored in
variable i1 (from above) to the last element of the array exam19.
[4 marks]
(c) Write a for loop that initialises the contents of each element of the array
exam19 in the previous question to −1.
[2 marks]
(d) Write a C++ expression that will calculate the address of the third element of
the array exam19.
[2 marks]
(e) Given the following declarations, write code to exchange the addresses stored
in x and y. You may add any additional declarations you wish.
int *x = new int(3);
int *y = new int(4);
[5 marks]
[Total for Question 2: 15 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 4 of 13
Primary Examination, Semester 1, 2019
Arrays
Question 3
(a) Using a diagram, show how array values are stored in memory.
[2 marks]
(b) You pass an array to a function as a parameter. What could happen if you do
not pass in the length of the array as well?
[2 marks]
(c) Write the code to declare and initialise an integer array with the values 3, 9,
12, 20.
[2 marks]
(d) Write a function with the signature:
int* initarr(int size1)
That allocates a new array of ints with size1 elements and initialises every
element of an array to the square of its index value. The function should then
return a pointer to the new array.
As an example of how the initialisation should work, the contents of a new
array with four elements would be 0, 1, 4, 9.
[4 marks]
[Total for Question 3: 10 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 5 of 13
Primary Examination, Semester 1, 2019
Object Oriented Programming
Question 4
(a) In the declaration below, identify the class and the object
Dog classyDog;
[2 marks]
(b) Why do we provide accessor methods rather than just making the member
variables public? Which OOP property do accessors support?
[3 marks]
(c) Objects capture state and behaviour. Explain briefly how objects provide this.
[4 marks]
(d) Explain how a static class variable differs from a member variable.
[2 marks]
(e) Explain when each of the access modifiers (public, private, protected) should
be used.
[3 marks]
(f) You have been asked to produce an initial design for a library software catalogue.
The library contains a wide range of books. Patrons borrow books
from the library and have three weeks to return them. Returned books are
held in a storage room until they are returned to the shelves by staff. Produce
a diagram showing the fundamental state and behaviour of the objects in this
system. Only show those elements that are essential to understanding the
system.
[6 marks]
[Total for Question 4: 20 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 6 of 13
Primary Examination, Semester 1, 2019
Classes
Question 5
(a) This piece of code is from a class called Exams. The section marked ... represents
code that has been removed for this example.
Exams::Exams() { ... }
What is the name of this kind of method and what is it used for?
[2 marks]
(b) Write a destructor for the class Panda, which displays “Panda object deleted”
when the destructor is invoked.
[2 marks]
(c) Write a class for an object called cup that represents a coffee cup. cup should
have a function fill() which will set the cup’s state to full and a function
drain() that sets it back to empty. Write the class declaration and the implementation
for the cup class.
[6 marks]
[Total for Question 5: 10 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 7 of 13
Primary Examination, Semester 1, 2019
Inheritance and Abstract Classes
Question 6
Consider the following code defining a hierarchy of Vehicle and Cars:
// class definition of Vehicle
class Vehicle{
public:
Vehicle(string id, int dist);
virtual void travel(int amount)=0;
virtual void print_details();
protected:
string id;
int dist_travelled;
};
// constructor taking id and distance
Vehicle::Vehicle(string id, int dist){
this->id=id;
dist_travelled=dist;
}
void Vehicle::print_details(){
cout << "vehicle id: " << id << " dist travelled: " <<
dist_travelled << endl;
}
// class definition of Car
class Car : public Vehicle{
public:
Car(string id, int dist,string model);
virtual void travel(int amount)=0;
virtual void print_details();
protected:
string model;
};
Car::Car(string id, int dist, string model):Vehicle(id,dist){
this->model=model;
}
void Car::print_details(){
Vehicle::print_details();
cout << " model name: " << model << endl;
}
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 8 of 13
Primary Examination, Semester 1, 2019
Now, answer the following questions:
(a) The implementation of the constructor for Car is:
Car::Car(string id, int dist, string model):Vehicle(id,dist){
this->model=model;
}
Explain precisely what the code: :Vehicle(id,dist) above does.
[2 marks]
(b) The implementation of the print details method for Car is:
void Car::print_details(){
Vehicle::print_details();
cout << " model name: " << model << endl;
}
Explain what the code: Vehicle::print_details(); above does.
[1 mark]
(c) The driver code:
// make a car and make it travel
Car *my_car = new Car("123BRAD",30000,"Velox");
my_car->print_details();
my_car->travel(200);
my_car->print_details();
Has an errors in it. Explain precisely what is wrong with the code above.
[2 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 9 of 13
Primary Examination, Semester 1, 2019
(d) Consider the following class definition, which describes a sub-class of Car
representing electric cars:
// class definition of an electric car
class ECar: public Car{
public:
ECar(string id, int dist,string model,int range);
virtual void travel(int amount);
virtual void print_details();
virtual void fill();
protected:
int range; // range of car in kms
int remaining; // remaining range in kms
};
Answer the following questions
i. Write a C++ implementation of the constructor of ECar. Make sure you
call the constructor of the Car class as appropriate and initialise all the
relevant variables to sensible values.
[4 marks]
ii. Write a C++ implementation of the print details method of ECar. This
method should make use of the print details method of the super-class
as appropriate. In addition to the same details as printed by the Car
classes print details method, your method should also print the range
and the remaining range of the car in a well-formatted way.
[4 marks]
iii. Write a C++ implementation of the travel method of ECar. This method
updates remaining and dist travelled according to the amount parameter.
Note that, if the remaining range of the car is less than amount then
you will only be able to travel for the remaining range – make sure your
code implements this logic.
[6 marks]
[Total for Question 6: 19 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 10 of 13
Primary Examination, Semester 1, 2019
Polymorphism
Question 7
Consider the following C++ code defining an Animal class and a Lion sub-class of
Animal:
class Animal{
public:
Animal(string name);
virtual void speak();
protected:
string name;
};
//constructor for Animal
Animal::Animal(string name){
this->name=name;
}
void Animal::speak(){
cout << name << " makes default sound" << endl;
}
// class for lion
class Lion: public Animal{
public:
Lion(string name, string sound);
virtual void speak();
protected:
string sound;
};
Lion::Lion(string name, string sound):Animal(name){
this->sound=sound;
}
void Lion::speak(){
cout << name << " the lion says " << sound << endl;
}
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 11 of 13
Primary Examination, Semester 1, 2019
Now, given the definition above, answer the following questions:
(a) What is the output of the of the following driver code?
Lion *leo = new Lion("Leo","Ger");
Lion *bella = new Lion("Bella","Roar");
Animal* zoo[2];
zoo[0]=leo;
zoo[1]=bella;
zoo[0]->speak();
zoo[1]->speak();
[4 marks]
(b) What would the output of the driver code from part a) above be if the speak
function were not declared virtual in the Animal class?
[4 marks]
(c) Consider the following driver code for the Animal and Lion classes at the
beginning of this question:
// declare a lion and make it speak
Lion leo("Leo","Ger");
leo.speak();
// make an animal and speak
Animal animal1("generic animal 1");
animal1.speak();
// assign leo to animal1 and speak
animal1=leo;
animal1.speak();
When this code is run it produces the following output:
Leo the lion says Ger
generic animal 1 makes default sound
Leo makes default sound
With the aid of diagrams, explain how the driver code produces the last line
of output above.
[4 marks]
[Total for Question 7: 12 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 12 of 13
Primary Examination, Semester 1, 2019
Standard Template Library
Question 8
(a) Briefly describe two advantages of using the Standard Template Library.
[2 marks]
(b) Briefly describe what is wrong with the following code using the vector template
from the Standard Template Library.
vector
myInts;
myInts.push_back(13);
myInts.push_back(14);
myInts.push_back(15);
myInts[100]=25;
cout << myInts.back() << endl;
cout << myInts[1000] << endl;
[2 marks]
(c) Briefly describe two advantages of vectors over arrays.
[2 marks]
(d) Briefly describe the difference between a set and a map in the Standard Template
Library.
[2 marks]
[Total for Question 8: 8 marks]
PLEASE SEE NEXT PAGE
COMP SCI 1102, 1102UAC Page 13 of 13
Primary Examination, Semester 1, 2019
Complexity and Problem Solving Strategy
Question 9
(a) We have calculated a function of the runtime (measured in terms of basic
instructions executed) of an algorithm for an input of size n to be:
f(n) = 1000 + n + 3n
2 + 2n
3
Demonstrate that this algorithm has a big-O runtime complexity of O(n
3
).
[3 marks]
(b) Give an example of when the use of a Brute Force algorithm might be preferred
over other algorithms.
[2 marks]
(c) You have an unsorted array of 1000 numbers and you want to remove the duplicate
numbers from the array. Precisely describe two alternative algorithmic
approaches to doing this – one of which is, in terms of time complexity, more
efficient than the other.
[6 marks]
[Total for Question 9: 11 marks]
END OF EXAMINATION PAPER
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!