Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Object-Oriented Programming with C++: Understanding Objects, Classes, and Bank Accounts - , Study notes of Engineering

A lecture note from cse294b, object-oriented c++ programming for engineers, focusing on the concept of objects and classes using the example of a bank account. The lecture covers the minimum requirements to operate a car as an object analogy, the difference between objects and classes, the data and functions associated with a bank account object, and access specifiers in c++ for encapsulation. The document also includes a simple bank_account class implementation and a call to action for a programming exercise.

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-84w-1
koofers-user-84w-1 🇺🇸

3

(2)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294B
Object
-
Oriented C++ Programming for Engineers
Object
-
Oriented
C++
Programming
for
Engineers
Lecture #5
Jeffrey Miller, Ph.D.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Object-Oriented Programming with C++: Understanding Objects, Classes, and Bank Accounts - and more Study notes Engineering in PDF only on Docsity!

CSE294B

Object-Oriented C++ Programming for EngineersObject-Oriented C++ Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

Object Analogy

-^

To drive a car, you need the accelerator pedal, thebrake pedal, the steering wheel, and the ignition(at minimum)(at minimum)

-^

But what actually happens when you turn the keyin the ignition?

M

d i

d^

k^

b^

h^

d^

d

  • Most drivers do not know, but they do not need to

know to be able to drive the car

-^

This is the idea behind objects

j

  • The code that uses the object knows

what

the function

will do, but does not need to know

how

it does it

Object Descriptions

• Objects (and in turn, classes) can be

described by two key features

y

y

  • Data– Functions

Functions

• The functions of an object operate on the

data that is part of the object or data that isdata that is part of the object or data that ispassed into the function (possibly inconjunction with the data of the object)conjunction with the data of the object)

Bank Account Object

•^

What is the data that is associated with a bank account?–

NameA

t N

b

-^

Account Number

-^

Balance

-^

PIN

•^

What are the functions that can be performed on a bankaccount?

Deposit

-^

Deposit

-^

Withdrawal

-^

Transfer

-^

Check Balance

-^

Change PIN

Access Specifiers

•^

There are two access specifiers in C++–

public

i^

t

-^

private

•^

If a variable or function is declared public, any other pieceof code can access the variable or function

-^

If a variable or function is declared private, only the classin which that variable or function is declared can access it

l^

f^

h^

b^

id

h^

d^

d^

h

•^

Rule of Thumb – Hide the data and expose the necessaryfunctions

Encapsulation

• A class is considered

encapsulated

if all of

the data is declared private

p

• A class is considered

fully encapsulated

if

all of the data is declared private AND youall of the data is declared private AND youprovide an accessor (getter) andmanipulator (setter) function for each piecemanipulator (setter) function for each pieceof data

Manipulators are also called mutators

  • Manipulators are also called mutators

Homework

• Homework #3 is posted!