0% found this document useful (0 votes)
18 views

Object Oriented Programming

C++ was designed by Bjarne Stroustrup in the early 1980s as an extension of C to support object-oriented programming. Some key strengths of C++ over C include improved type safety, automatic memory management, and support for abstraction and encapsulation through the use of classes. The document provides an overview of object-oriented programming concepts in C++ such as classes, objects, and inheritance, and compares keywords between C and C++. Sample code demonstrates basic input/output and the definition and use of a simple class.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Object Oriented Programming

C++ was designed by Bjarne Stroustrup in the early 1980s as an extension of C to support object-oriented programming. Some key strengths of C++ over C include improved type safety, automatic memory management, and support for abstraction and encapsulation through the use of classes. The document provides an overview of object-oriented programming concepts in C++ such as classes, objects, and inheritance, and compares keywords between C and C++. Sample code demonstrates basic input/output and the definition and use of a simple class.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

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
(Smalltalk)
(Ada)
(LISP)

C++

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
default
do
double
float
for
goto
register
return
short
struct
switch
typedef
volatile
while
Additional C++ Key Words
asm
catch
class
new
operator private
this
throw
try

char
else
if
signed
union

const
enum
int
sizeof
unsigned

delete
friend
protected public
virtual

continue
extern
long
static
void

inline
template

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;
};

struct coord
{
int x;
int y;
};

Coord location;

struct coord location;

location.x = 7;
location.y = 8;
cout << location.y;

location.x = 7;
location.y = 8;
printf(%d,location.y);

You might also like