Professional Documents
Culture Documents
Cosc206 Exam 16 - 17 Type 2
Cosc206 Exam 16 - 17 Type 2
Cosc206 Exam 16 - 17 Type 2
Question one:
/ .
I. Wihat are constructors? [3 marks]
ii. ~
1
at are members of a class? · [3marks]
iii. WW.h arc
i t the objects for reading infonnation from keyboard and for sending to the
sc n for display? [3 marks]
iv. G I three examples of header files from C-++ Standard libraries. [3 marks]
V. W.h:at are the stream classes for reading from a file, writing to a tile and also for
'j~? [3 marks]
Question j
/ i. D 1terentiate between arguments and parameters [S marks]
ii. C 1late a class called Employee that includes three pieces of information as data
__ ___.__meQ!.Qe!J;_a first name ( ~ string).t.! last-name (type string} and a.monthly salary
--~( type int)~ the ~lass~ out~r co~ tain the thice data
members ..Yoµ are to providell set iu'id a get function for each data member. If
the° monthly salary is not positive, set it to 0. Write a test program that
demonstrates class Employee's capaoilities. Create two Employee objects and
display ~ach object's yearly salary. (10 marks]
9J1esdon Three
Question Four
_9Jaestion Five
i. WritQ the syntax of two overloaded functions called remitain a
cla~saU~ment. The first function is a void function with two parameters both
of e integer; the second function is a double function with two parameters both
of . doub,le. [5
marks]
ii. Creatb an Account class that a bank might use to represent customers' bank
accoJnts. Include a data member of type int to represent the account balance.
Provi6e a co~ ; -a; initial bal~ and uses it to initialise the
data ~ ember. Provide three member functions. First named credit it adds an
amount to the current balance. The second function named debit withdraws money
from ifue account and ensure that the debit amount does not exceed the account
~ lance~ does, th~;.bal_'1ce. s~ould be-l~_unch.ang~_filld_Jae..nm_ctjon..shoµld_,..
print a m essage indicating"c'J?e_bit amount ex~s account balance". The third
function display returns the current balance. Create two account objects and test
the member functions of the class accoun( [lOmarks]
Question Six
i. Wriu: the syntax of a class called BusTerminalwith two member data payingBus
which of type integer and noPayBus which of type double. The class contains a
copy constructor which is used to initialise their values. [5 marks]
ii. A large company pays its salespeople on commission-basis. The sale_s people each
recei1e $200 per week plus certain % of the grosJ sales per week. Example if a
salesfrson sells up to $5,000 worth of goods, he receives 5% of the $5,000. If a
sales person sells up to $9,000 and above he receives 9% of the sales. Any sales
less tfian $5,000 receive no bonus. Develop a C++ program that accepts the sales
person's gross sales for the week then calculates and displays that sales person's
earnings [ 10 marks]