Presentation is loading. Please wait.

Presentation is loading. Please wait.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.

Similar presentations


Presentation on theme: "Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24."— Presentation transcript:

1 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24

2 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 2Winter Quarter C++ A better C A superset of C Created at Bell Labs in the 1980's and called C with Classes Adds additional features to improve the language Adds functions and features to support Object Oriented Programming (OOP )

3 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 3Winter Quarter Object Oriented Programming (OOP) Object oriented programming (OOP) models real- world objects with software counterparts. OOP gives us a more natural and intuitive way to view the programming process by modeling the real-world objects, their attributes, their behaviors, and their interactions with each other.

4 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 4Winter Quarter Object Oriented Programming (OOP) OOP also models communication between objects. Just as people send messages to one another, objects communicate via messages. OOP encapsulates data (attributes) and functions (behavior) into packages called objects. Objects have the property of information hiding.

5 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 5Winter Quarter Object Oriented Programming (OOP) cont. Objects (data and functions) are members of user-defined types called classes. A class definition is an extension of a C struct definition. It is made up of declarations of variables and of function prototypes to manipulate those variables. The variables are typically declared to be private or protected and the functions are typically declared to be public. structs and classes actually are the same in C++ (both can have member functions or “methods”), but struct members are public by default and class members are private by default.

6 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 6Winter Quarter Useful Concepts in C++ Inheritance Operator overloading Function templates Virtual functions Polymorphism

7 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 7Winter Quarter New I/O library iostream header file library #include // No “.h” in front of // standard headers using namespace std; // To prevent “std::” // before everything contains definitions for several classes istreamostream fstreamios and their associated objects cincout cerrclog

8 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 8Winter Quarter Some New Operators in C++ >> Extraction Operator extracts data from input stream. << Insertion Operator inserts data into output stream :: Scope Resolution Operator used to: 1. Override the default scope of variables. 2. Specify the scope of member functions.

9 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 9Winter Quarter Some C++ Extensions to C // Single Line Source Code Comments Inline Functions Function overloading Reference parameters

10 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 10Winter Quarter // Single Line Comments // This is a comment that covers // more than one line. It // requires double slashes on // each line.

11 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 11Winter Quarter Inline Functions inline float cube ( float x ) { return x*x*x;} // This solves problems that arise with #define cube(x) x*x*x


Download ppt "Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24."

Similar presentations


Ads by Google