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

Related documents


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 Engineers Lecture #5 Jeffrey Miller, Ph.D. Object Analogy • To drive a car, you need the accelerator pedal, the brake pedal, the steering wheel, and the ignition (at minimum) • But what actually happens when you turn the key in the ignition? M d i d k b h d d– ost r vers o not now, ut t ey o not nee to know to be able to drive the car • This is the idea behind objects – The code that uses the object knows what the function will do, but does not need to know how it does it Bank Account Object • What is the data that is associated with a bank account? – Name A t N b– ccoun um er – Balance – PIN • What are the functions that can be performed on a bank account? Deposit– – Withdrawal – Transfer – Check Balance – Change PIN Bank Account Class class Bank_Account { private: int account_number, pin; double balance; char *name; public: void set_balance(double bal) { balance = bal; } double get_balance () { return balance; } void withdraw(double amount) { balance -= amount; } }; void main() { Bank_Account ba; ba.set_balance(2000.00); ba.withdraw(100.00); } Access Specifiers • There are two access specifiers in C++ – public i t– pr va e • If a variable or function is declared public, any other piece of code can access the variable or function • If a variable or function is declared private, only the class in which that variable or function is declared can access it l f h b id h d d h• Ru e o T um – H e t e ata an expose t e necessary functions