Interoduction to c++

21
INTERODUCTION TO C++ ATM PROJECT SUBMITTED BY:-

Transcript of Interoduction to c++

Page 1: Interoduction to c++

INTERODUCTION TO C++ ATM PROJECT

SUBMITTED BY:- SUBMITTED TO:-AMRESH KUMAR DR.MUKESH SHARMA(14IT004) (H.O.D of CS/IT DEPARTMENT)

Page 2: Interoduction to c++

TOPICS:-1.Principal of object-oriented programing2.Classes and Objects3.Funtions in C++4.Constructor and Destructor5.Operator Overloading and type conversion6.Inheritance7.Pointers,Virtual funtions and Polymorphism8.Working with files9.Templates10.Exception handling

Page 3: Interoduction to c++

The C++ Language:-Bjarne Stroupstrup, the language’s

creatorC++ was designed to provide Simula’s facilities for program organization together with C’s efficiency and flexibility for systems programming.

Page 4: Interoduction to c++

1.PRINCIPLES OF OBJECT ORIENTED PROGRAMING

Conventional programming, using high level languages such as COBOL,FORTRAN and C,is commonly known as procedure oriented programming (POP). In the POP approach, the problem is viewed as a sequence of things to be done such as reading,calculating and printing. A number of functions are written to accomplish these tasks. The primary focus is on functions. A typical structure for procedural programming is shown in the fig 

Page 5: Interoduction to c++

Another serious drawback is that it does not model real world problems very well.Some characteristics exhibited by procedure-oriented programming are:1)     Emphasis is on doing things (algorithms).2)     Large programs are divided into smaller programs known as functions.3)     Most of the functions share global data.4)     Data move openly around system from function to function.5)     Functions transform data from one form to another.6)      Employs top-down approach in program design.

The major motivating factor in the invention of object-oriented programing Is to remove some flaws encountered in the procedural approach

Page 6: Interoduction to c++

Some of the striking features of object – oriented programming are:•Ø      Emphasis is on data rather than procedure.•Ø      Programs are divided into what are known as objects.•Ø      Functions that operate on the data of an object are tied together.•Ø      Data is hidden and cannot be accessed without functions.•Ø      Objects may communicate with each other through functions.•Ø      New data and functions can be easily added whenever necessary.•Ø      Follows bottom-up approach in program design.

Page 7: Interoduction to c++

The OOP language is divided into four major concepts. Encapsulation Inheritance Polymorphism Abstraction

Encapsulation in C++Encapsulation is one of the major cores of OOP. It is the mechanism that binds code and data together and keeps them safe and away from outside inference and misuse. In short, it isolates a data from outside world. Encapsulation can be called as the core concept of OOP because it is encapsulation that reduces the maintenance burden, and limiting your exposure to vulnerabilities. 

Page 8: Interoduction to c++

Inheritance in C++This technique also supports the hierarchical classification in which each object would not need to be redefined by all its characteristics explicitly. It prevents the programmer from unnecessary work and it is the inheritance concept that does this job. 

Polymorphism in C++Polymorphism,means the ability To take more than one works.Polymorphismc may be:-1.Operator overloading 2Funtion overloading

Page 9: Interoduction to c++

Abstraction in c++Abstraction refers to the act of representing essential features Without including the background detailsor explanations.Let's take one real life example of a TV, which you can turn on and off, change the channel, adjust the volume, and add external components such as speakers, VCRs, and DVD players, BUT you do not know its internal details, that is, you do not know how it receives signals over the air or through a cable, how it translates them, and finally displays them on the screen.

Page 10: Interoduction to c++

2.CLASSES AND OBJECTSCLASSESWhen you define a class, you define a blueprint for a data type. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object. class box { double length; double breadth; double height; };

Page 11: Interoduction to c++

OBJECTSA class provides the blueprints for objects, so basically an object is created from a class. We declare objects of a class with exactly the same sort of declaration that we declare variables of basic types. box b1;//1st object of box box b2;//2nd object of box

Page 12: Interoduction to c++

3.FUNTIONSA function is a group of statements that together perform a task. Every C++ program has at least one function, which is main(), and all the most trivial programs can define additional functions.The C++ standard library provides numerous built-in functions that your program can call. For example, function strcat() to concatenate two strings, function memcpy() to copy one memory location to another location and many more functions.SYNTAX:-Return-type function name(Arguments){Body of the funtions}

Page 13: Interoduction to c++

4.CONSTRUCTOR AND DESTRUCTORCONSTRUCTORA class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.DESTRUCTORA destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class.A destructor will have exact same name as the class prefixed with a tilde (~) 

Page 14: Interoduction to c++

5.OPERATOR OVERLOADING AND TYPE CONVERSIONOPERATOR OVERLOADINGOverloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined. Like any other function, an overloaded operator has a return type and a parameter list. box operator+(int box)TYPE CONVERSIONImplicit conversions do not require any operator. They are automatically performed when a value is copied to a compatible type. For example: short a=2000; int b; b = (int) a; // c-like cast notationb = int (a); // functional notation

Page 15: Interoduction to c++

6.INHERITANCEInheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.Eg:- class derieved class:acess specifier base class

Page 16: Interoduction to c++

7.THIS POINTER AND VIRTUAL FUNCTION POINTEREvery object in C++ has access to its own address through an important pointer called this pointer. The this pointer is an implicit parameter to all member functions. Therefore, inside a member function, this may be used to refer to the invoking object.Friend functions do not have a this pointer, because friends are not members of a class. Only member functions have a this pointer.VIRTUAL FUNTIONA virtual function is a member function that is declared within a base class and redefined by a derived class. To create virtual function, precede the function’s declaration in the base class with the keyword virtual. When a class containing virtual function is inherited, the derived class redefines the virtual function to suit its own needs.

Page 17: Interoduction to c++

8.WORKING WITH FILESwe have been using the iostream standard library, which provides cinand cout methods for reading from standard input and writing to standard output respectively.This tutorial will teach you how to read and write from a file. This requires another standard C++ library called fstream, which defines three new data types:ofstream This data type represents the

output file stream and is used to create files and to write information to files.

ifstream This data type represents the input file stream and is used to read information from files.

fstream This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files.

Page 18: Interoduction to c++

9.TEMPLATESTemplates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.There is a single definition of each container, such as vector, but we can define many different kinds of vectors for example, vector <int> or vector <string>.template <class type> ret-type func-name(parameter list)

{ // body of function }

Page 19: Interoduction to c++

10.EXCEPTION HANDLINGAn exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, andthrow. throw: A program throws an exception when a problem

shows up. This is done using a throw keyword. catch: A program catches an exception with an exception

handler at the place in a program where you want to handle the problem. Thecatch keyword indicates the catching of an exception.

try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks.

Page 20: Interoduction to c++

Assuming a block will raise an exception, a method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception.

Try { // protected code }catch( ExceptionName e1 ) { // catch block }catch( ExceptionName e2 ) { // catch block }catch( ExceptionName eN ) { // catch block }

Page 21: Interoduction to c++

THANK YOU