Lecture180 struct to an object

Lecture180 struct to an object - Example converting a...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 1 -- 1 Computer Science I - Martin Hardwick Example converting a struct to an object We want to convert this struct to an object An object has data and methods An object has public and private sections Good practice puts the data in the private Good practice puts access methods also known as get and put methods in the public section After we have done the conversion we can add other methods to the object. add_funds (double amount) is_bankrupt() struct acct { int acctnum; string name; double balance; };
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
-- 2 Computer Science I - Martin Hardwick Account Class Contents of the acct.h file #include <string> class acct { public: acct (); acct (int num, string name,  double bal); string get_name (); int get_acctnum (); double get_balance (); double put_balance (double bal); private: int  acctnum; string  name; double balance; }; There must be a corresponding account.cpp file with the member functions’ implementations.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/30/2012 for the course CSCI 101 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 4

Lecture180 struct to an object - Example converting a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online