Chapter4 - Object Oriented Programming A class is a...

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

View Full Document Right Arrow Icon
Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 4 Working with Data Files Object Oriented Programming ± A class is a mechanism that allows a programmer to define new data types. Example: Rectangle ± A class can be used to add functionality to an existing data type or to create a new data type. ± A class definition combines data and functionality. Example: Rectangle class ± class rectangle { public: ± // Default constructor ± rectangle(); ± rectangle(double x, double y, double w, double h); ± // Accessor functions ± double get_x_coord() const; ± // Constructor with four formal parameters ± double get_y_coord() const; ± double get_width() const; ± double get_height() const; ± // Functions for input and output. ± void input(istream& in); ± void print(ostream& out) const; private: ± // Declaration of data members. ± double x_coord, y_coord, width, height; ± }; Object ± An object is a variable of a defined class type, also referred to as an instance of a class . ± int main() ± { ± // Test default constructor. ± rectangle r1; ± } r1 is an object of class rectangle
Background image of page 1

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

View Full DocumentRight Arrow Icon
Inheritance ± An important object-oriented feature of C++ ± Allows a class to inherit the functionality of an existing class ± A derived class can call any member function of the parent class, and can also have additional member function not included in parent function ± For example: a Square class can be derived from class Rectangular Working with Data Files ± Defining File Streams ± Reading and Generating Data Files ± Error Checking Engineering Problem Solving with C++, Second Edition, J. Ingber 6 DEFINING FILE STREAMS stream class hierarcy Engineering Problem Solving with C++, Second Edition, J. Ingber
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 10/23/2011 for the course ECE 224 taught by Professor Wangxin during the Spring '09 term at SUNY Stony Brook.

Page1 / 7

Chapter4 - Object Oriented Programming A class is 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