200 likes | 516 Views
Object Oriented Programming. IN C++. Chapter 1. INTRODUCTION TO C++. Introduction. In this section we are going to give a brief overview of the history of C and C++ a comparison at the key words of C and of C++ a quick revision of C usage an examination of the dangers of traditional C
E N D
Object Oriented Programming IN C++
Chapter 1 INTRODUCTION TO C++
Introduction • In this section we are going to give • a brief overview of the history of C and C++ • a comparison at the key words of C and of C++ • a quick revision of C usage • an examination of the dangers of traditional C • a quick look at the new features of C++ and how they might be used to implement OOD
What Is C++ • Compatible extension of c • Support Object Oriented Programming • Support for Data Abstraction
Background • C++ designed by Bjarne Stroustrup (AT&T Bell Labs) • Originally only meant as a pre-processor to improve on some of the inadequacies of C • First commercial release 1985 • Even today many consider C++ is not an object oriented language but rather an object oriented compiler-linker (subtle difference we'll learn about later).
BPCL C Algol68 Simula67 C++ (Smalltalk) (Ada) (LISP)
Strengths and Weakness of C • Strengths • Flexible (you can make mistakes in a wide variety of ways!) • Efficient (you can make those mistakes very quickly!) • Available (everyone can make mistakes together!) • Portable (you can transport those mistakes to other systems!) • Weaknesses • Very untidy syntax • Lack of type saftey • memory managment not automatic
Philosophy of C++ • Keep the strengths and repair the weaknesses • Efficiency is maintained • Compatability is maintained with C • Operate in all environments C can • Improved typing • Abstraction and Data encapulation vastly improved
Key Words for C and C++ C and C++ Key Words auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while Additional C++ Key Words asm catch class delete friend inline new operator private protected public template this throw try virtual
What You Should Already Know: Programming • Elementary Programming in C • simple declarations including structures • user defined types (typedef) • enumurator types (enum) • expressions • flow control • I/O • functions and modularity • pointers • basic memory allocation • basic data structures (arrays, lists, trees)
Bibliography - main books • Object oriented programming using c++IRA POHL - second edition, ADDISON WESLEY • Effective C++ SCOTT MEYERS, ADDISON WESLEY • Introduction to OOP programming - T.Budd • The C++ programming lenguage - B.Stroustrup
The first c++ program #include <iostream.h> void main(void) { cout << “c++ is an improved c \n” ; } //cout <<“c++ is an improved c “<< endl ;
Input / Output #include<iostream.h> void main(void) { int a=1000; cout << “a is “<<a<<endl; cout <<“enter number”<<endl; int b; cin >>b; a+=b; cout <<“ a is “<<a<<“ and b is “<<b<<endl; }
Classes and Objects • A Class is a static description of a type • It encapsulates the data and all legal operations on that data • It also defines who has access to that data • An object is an instance of a class (sometimes we say an instantiation)
Example of A Class class Coord { public: int x; int y; }; Coord location; location.x = 7; location.y = 8; cout << location.y; struct coord { int x; int y; }; struct coord location; location.x = 7; location.y = 8; printf(“%d”,location.y);