c++ part 1

28
1 Continues...

Upload: sharmila-robinson

Post on 14-Apr-2017

176 views

Category:

Education


0 download

TRANSCRIPT

Page 1: C++ part 1

1Continues...

Page 2: C++ part 1

2Continues...

Page 3: C++ part 1

C++ is the high-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

C++ runs on a variety of platforms, such as Windows, Mac OS, and various versions of UNIX.

C++ program runs in turbo C++ . C++ is a statically typed, compiled, case-sensitive, free-

form programming language that supports procedural, object-oriented, and generic programming(graphs,arrays).

3Continues...

Page 4: C++ part 1

C++ follows a bottom-up approach. C++ allows use of functions in structures. C++ directly supports exception handling. Member functions operates on specific object. C++ supports constructors,destructors

templates,Operator overloading,generalization and specialization concepts.

In C++ Classes also be defined inside the functions.

Continues... 4

Page 5: C++ part 1

It contains only procedures. Need to follow all procedures when we are writing programs. So its difficult to implement.

Procedure languages are very lengthy. Real Time Example: How to write algorithm and program for getting into

the car?1. First open the car door.2. Sitting inside the car.

Continues... 5

Page 6: C++ part 1

3. Close the door,4. Insert key in ignition.5. Start the car.6. Then the car will get started.

In this language we need to follow procedure to each and everything.

We need to include all actions so it is very lengthy.

Continues... 6

Page 7: C++ part 1

Continues... 7

Page 8: C++ part 1

Procedure Oriented Programming(POP)

Object Oriented Programming(OOP)

It follows Top Down Programming Technique.

It follows Bottom Up Programming Technique.

Program is divided into small pieces are called as functions.

Here it is called as objects.

Importance is given to functions not to data because sequence of actions to be performed here.

Importance is given to data rather than functions because its work on real world entities.

Doesn’t support protection. It supports protection through access specifiers.

Data can easily move from one function to other function.

objects can move and communicate with each other through member functions.

Doesn’t supports overloading. overloading is possible in the form of Function Overloading and Operator Overloading.

Continues... 8

Page 9: C++ part 1

Procedure Oriented Programming(POP)

Object Oriented Programming(OOP)

Slower than C++ because it doesn’t supports code reusability.

Faster and efficient than C since it supports code reusability through inheritance concept.

It doesn’t provide the feature of namespace.

Namespaces are available in C++.

Exception handling is not easy in C. It has to be done by using other functions.

C++ provides exception handling Mechanism.

Here all variables are must be declared at the beginning of a scope.

C++ allows declaring variables anywhere within the scope.

It doesn’t supports polymorphism. It supports polymorphism.

It supports only built-in data types. It supports both built-in and user-defined data types.

Example:C, VB, FORTRAN, Pascal,COBOL.

Example:C++, JAVA, VB.NET, C#.NET,perl,python.

Continues... 9

Page 10: C++ part 1

Access specifiers are three types. It is otherwise called as visibility mode. They are

1. Public2. Private3. Protected

Private

Public

Protected

Continues... 10

Page 11: C++ part 1

Here the data members cannot be accessed outside of the class if its declared as private.

Continues... 11

Page 12: C++ part 1

Data members can be accessed outside the class or the entire program.

Continues... 12

Page 13: C++ part 1

Here the data members can only be accessed by code in the same class and in a derived class.

Continues... 13

Page 14: C++ part 1

1. Class.2. Object.3. Data abstraction .4. Data encapsulation.5. Inheritance.6. Polymorphism.7. Dynamic binding or Message Passing.

Continues... 14

Page 15: C++ part 1

It is a single unit.Blue print for a data type.Class is a collection of objects.Class should be end with semi colon.The data and functions within a class are

called members of the class.Class starts with the keyword “class”.Class links code and data.

Continues... 15

Page 16: C++ part 1

default members would be assumed as private.

The public data members of a class can be accessed by using dot operator.

operator (.)Syntax:2 types1.Member function inside the class

Continues... 16

Class Classname{Access specifier:Data members;Member Function;};

Page 17: C++ part 1

class student{

public: char* nm; int id,y; void print()

{ -----

------ } };

Continues... 17

Here,classkeywordstudentclassnamepublicaccess specifiersnm,id,yVariablesprint()member functions

Page 18: C++ part 1

2.Member Function outside the class:Syntax:

Continues... 18

class Classname{access specifier:data members;}returntype classname::function name{-----}

Page 19: C++ part 1

This operator is used to access data member function outside of the class.

Used to access global variable inside the main function. Used to access hidden data. If the local and global variables are same name then the

local variable gets first priority. Example:

int m=10;//Global Variablevoid main(){int m=20;//Local Variable cout<<m;

cout<<::m;}

Continues... 19

Page 20: C++ part 1

Dot[.] operator is used for access the member function outside of the class.

It is used for invoke the member functions. Syntax:

Example:classname.Member function(arguments)

S.get();

Continues... 20

Page 21: C++ part 1

Used to access the base class. Used to derive a new class from the base

class. Syntax:

Derived class:public baseclass

Continues... 21

Page 22: C++ part 1

class student {

public: char* nm; int id,y; void print();

};void student : print()

{ cout << "\n" << name << ", " cout << student_id << ", "cout << year << endl; }

Continues... 22

Page 23: C++ part 1

Protect the data Easily we can code Used to bind data and functions which not in structure. We can inherit the class

Continues... 23

Page 24: C++ part 1

Collection of entities or objects are variables. Objects are copy of a class. Allocation of memory space. We can also define objects outside of the class. Each and every objects has properties and behaviors. Properties are defined through data elements. Behavior is defined through member functions called

methods.

Continues... 24

Page 25: C++ part 1

This properties includes Identity and state. Real Time Example: Apple Here,

Apple-Identity(i.e.Name of the object)Apple colour-State(Apple colour is red)

Apple Behavior-Eat(we can eat apple) Syntax of Object:Syntax of Object:

Continues... 25

classname objectname;

Page 26: C++ part 1

Example:

Continues... 26

Page 27: C++ part 1

Used to access the class. Used to allocate memory for class when it is called. Used to execute the class. Though objects only we can run class.

27

Page 28: C++ part 1

28