Cosc206 Exam 16 - 17 Type 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

BABCOCK UNIVERSITY, ILISHAN REMO, OGUN STATE

sc:ep<>LOF COMPUTING AND ENGINEERING SCIENCE


DEPARTMENT OF COMPUTER SCIENCE
FIN.Ai. !SECOND SEMESTER EXAMINATION FOR 2016/2017 SESSION
COSC 206: PROGRAMMING WITH C-++
E ~: DR. AYANKOYA F.Y AND MR. ADESEGUN 0. A.
DURATio1j lHOURS · TOTAL MARKS: 60 MARKS
INSTRUCJ10N: ATIEMPT QUESTION ONE~ OTHER THREE QUESTIONS

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

i. Explain constructors and destructors with examples [S marks]


ii. Crc~te a class HospitalRec that includes data members patient's first and last
naµ:tes ~ g . followed by the weigh~ eig!!t double, it also reads the
ient's temperature in Celsius. The class contains a function thatoutput the
pa Jent's first name and last n . Another function to returns the body mass
in ex o the patient, and another function to return the temperature in Fahrenheit.
T .edata to be read are stored in a file namedpatielllData.txt; the output should be
stpred in a file named PatientRecord.txt.- Test the functions with two patients
Brenda and Kwame.(Note: BMI = w/h2 ;TempF =TempC • 9/5 + 32).
[l0marks]

Question Four

i. Differentiate between function declaration and function definition [S marks]


ii. Wri~ a simple C++ program that displays a multiplication table in the form
belmr, using any loop of your choose
lxl=~ 2x1=2 '3xl=3 4xl=4 5xl=5
lx2=4 2x2=4 3x2=6 4x2=8 5x2=10

lxl2<=12 2xl2=24 3xl2=36 4x12=48 5xl2=60


[10 marks]

_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]

You might also like