[go: up one dir, main page]

0% found this document useful (0 votes)
33 views5 pages

CS15M2B Exam

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

CS15M2B Exam

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

2023 CS15M2B:

DIPLOMA AND DEGREE EXAMINATION| NOV/DEC Intro to


Object-oriented
Programming FINAL Examination

EWSU WalterSISUUVrm

WALTER SISULU UNIVERSITY


FACULTY OFNATURAL SCIENCEs
DEPARTMENT OF MATHEMATICAL SCIENCESAND COMPUTING

FINAL EXAMINATION

CS15M2B: INTRO TO OBJECT-ORIENTED PROGRAMMING

INTERNAL EXAMINER MS V. BADETSWANA


INTERNAL MODERATOR DR. L. TINARWO

DURATION 3 HOURS
TOTAL MARKS 100

INSTRUCTIONS
1. THIS IS ACLOSED-BOOK EXAMINATION.
2, USE THE ANSWER BOOKS PROVIDED TO ANSWER ALL QUESTIONS. FILL IN
YOUR DETAILS ON THE COVER PAGE OF YOUR ANSWER BOOK.
3. WRITE LEGIBLY AND NEATLY.
4. ANSWER ALL QUESTIONS.
5. READ QUESTIONS CAREFULLY ANDANSWER ONLY WHAT ISASKED.
6. GENERAL WALTER SISULU UNIVERSITY POLICIES, PROCEDURES, AND RULES
PERTAINING TO WRITTEN ASSESSMENTS APPLY TO THIS EXAMINATION.
Intro to Object-oriented
DIPLOMA AND DEGREE EXAMINATION 2023 CS15M2B:
Programming FINAL Examination I NOV/DEC

QUESTION 1 [14]

1. In C++, what is a
class?
A. An instance of an
object.
B. A
blueprint for creating
objects.
C. A function that
initializes objects.
D. An array of data.
whlch access specifier in C++ alaue class members to be accessed only
withinthe same class?
A. public
B. private
C. protected
D. internal
3. What is the purpose of a constructor in a C++ class?
To destroy objects.
A.
B. To create objects.
C. To declare class variables.

D. To define static members.


4. In C++, what is an abstract data type (ADT)?
A. A type that cannot be instantiated.

B. A data type that is automatically converted.


C. A data type that is abstracted fsem its implementation.
D. Adata type with abstract mathematical properties.

5. Which keyword is used to create a static member of a class in C++?


A. static
B. class
C. new
D. public

6. What does the addresS-ofoperator'& in C++ do?


A. Retrieves the value stored at a memory address.
B. Returns the memory address of a variable.
C. Copies the value from one pointer to another.
D. Allocates mernory dynamically.

7. Which header file should be included to work with input and output streams
in C++?
A. <iostream>
B. <fstream>
C. <iomanip>
D. <string>
8. In C++,what is inheritance?
A.A mechanism for hiding data members.
B.A way to define new data types.
C. A process of creating a copy of an obJeCt.
D. A mechanism for creating a new class based on an existing class.
program?[9]
following
the
What

of
the

output
code.[4] Explain
is
2.

happen?
object,
Student
on
based
attempt
wll
what
GPA

Tor
4.5
the set
you

of
to

a
If

a
student1?[2]
obiect Student
function
named

displayIno(0
How

for
class? Student
call

the
you

purpose
would

a
provided
[21
what

the
of
is
the

code,
In
e. d.C.

the you

your
how

do

code?
GPA

[41
3.5,

in
it
and

of

"Alice,"
would
object
Student
a

create
20.
age
name
with

the
new
you

want

to
If

a
b.

object? Student
called
display
for
when

function member
[4]
a

displayInfo()
does
What

it
work?
How

does

the
a.

code:
following
Consider
the
1.

QUESTION
[25]
2

struct.
member
array
of
can

be

a
An

operatorl.J.
using accessed
member struct
the
by
ais
E.D.

class.
members
private access directly derived
ofa

base
the
can
class
C.

reference.
value either function parameter passed class
by
to
can
A A by A

or
be

as
B.

a
a

#include.
directive pre-proceSSor
Header
using
CPP
added
are

file
into

false()
true(T) statements
a

following
whether
are

|1"5]
aor
filesthe

operations.
10.

Bitwise
0bjects. pointers
access Member
to
for

pointer.
Dereferencing
a

arithmetic.
Pointer
represent?
primarily
operator
A. State D.C. B. A.

arrow

->
the
does
what
C++,
In
9.

Examination
FINAL
Programming
Object-oriented Intro CS15M2B:
NOV/DEC
EXAMINATION DEGREE DIPLOMA
to
2023
AND

I
class.
integrity
maintaining
32
within
role

programming
data

object-oriented
in

[3]
its

information
concept
Discuss
and
hiding

ain
of
the

example
Provide
inC++?
abstract
[4]

ADT
of
an
an
type
data

members.
(ADT)
What

an

accessibility
visibility
is

control
classes
of

class
and
the

protected)
private,
C++

public, (e.g.,
to

specifiers
access
Explain
used
are

[6]in
how

systems.
programming
object-oriented
applications
real-world
[3]

of
two

programming.
Give

object-oriented
any

advantages
[2]
of

header
two
any

library
List

standard
commonly
examples
(5]
least
files
used

Provide
at
programs.
C++

3.
header
including
purpose
Describe
C++
in
files

operator.
of the

resolution
two

[2]
uses

of

of scope
Give

a
7. 6. 5. 4.3. 2.1.

Question
[25]
3

end1;
tOJte
ta
y

213
aint)t
Examination
Programming
Object-oriented
Intro
FINAL

CS15M2B:
EXAMINATION|
DEGREE
to

DIPLOMA
2023
AND

NOV/DEC.
|
DIPLOMA AND DEGREE
Programming FINAL EXAMINATION
Examination
| NOV/DEC 2023
CS15M2B: Introto
Object-oriented

QUESTION 4 [36
1. Consider
the following:
class
BankAccount

private:
int
acc_number;
double balance;
public:
void open(int
num);
void deposit();
void
withdraw();
double getBalance();

The member function


open sets the account
member function deposit will balance equal to zero.
The
deposit an amount. in the
memberfunctionwithdraw account, and the
will
withdraw an amount from the
that there is sufficient account, provided
balance in the accountto
allow it. Lastly, the function
getBalance returns the balance in
the account.
A. Write the code for
member functions: open, deposit,
getBalance. [3,4,5,2] withdraw and
B. Write a main program
that declares a
variable of type BankAccount,
opens the account, deposits R5000
into the account,
from the account,and prints out withdraws R1500
the balance left in the account.
5]
2. Create a class called Invoice that a
hardware store might use to
invojce for an item sold at the represent an
store. An Invoice should
include four pieces of
information as data members-a part
number (type string), a part description
(type string), a quantity of the item
being purchased (type int) and a
item (int). [Note: Use numbers price per
that contain decimal points (e.g.,
2.75)-called
floating-point values--to represent rand amounts.]
Your class should have a
Constructor that initializes the four data
members. Provide a set and a get
method for each data member. In additon,provide
a member function named
getInvoiceAmount that calculates tne invoice amount (i.e.,
multiplies the
quantity by the price per item), then reurns the amount as an
int value. Jf the
quantity isnot positive, it should be set to 0.IT the
price per item is not positive.
it should be set to 0. Write
a test progidm that demonstrates class
Invoice's
capabilities. It is important to validate your input. [17]

Prruett,

nç Oceunt

You might also like