the smartpath information systems c plus plus

Post on 12-Jan-2017

273 Views

Category:

Services

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

C++ Programming Basic Learning

Prepared By The Smartpath Information systemswww.thesmartpath.in

Index

1. About C++ Programming Language2. Basic Concepts of OOPs3. Basic Concepts of OOPs(continue….)4. Basic Concepts of OOPs(continue….)5. Basic Concepts of OOPs(continue….)6. Benefits7. Languages with Object Oriented Features8. C++ Programming Environment 9. C++ Program Structure10.C++ Program Structure (Explanation)11.Creating Class and Objects12.Explanation

Index

14 . C++ Program Syntax15. Keywords16. Data Types17. Operators in C++18. Operators in C++ (continue….)19. Variables20. Working With Classes21. Feature of OOP - Inheritance 22. Types of Inheritance23. Polymorphism - Operator Overloading24. Operators that cannot be overloaded25. OOPs Applications

About C++ programming language

C++ is an object-oriented programming language developed by Bjarne Stroustrup at AT&T Bell Lab in the year 1980. Initially it was named “C with classes” but later in 1983 the name changed to C++. It is an extension of C with major addition of classes. It supports concepts of Object Oriented Programming known as OOP concepts C++ can be said as superset of C. It provides bottom-up and object oriented design.

Basic concepts of object oriented programming

Objects Object is an entity in program. They are also called class variables. An object represents real world things such as person, student, etc Objects contain data and methods in it. When object is created in a program memory is allotted to a program. Class Class is a user-defined data type which holds data and program code. It is collection of objects of similar type.

Concepts of object oriented programming

Encapsulation The wrapping up of data and functions in a class is known as encapsulation. The functions inside class can use the data within it. It is not accessible outside world directly only function who is member of class or friend function can access data. Data Abstraction Abstraction is hiding details of a process and presenting essential features to the user. By creating a class and putting data and methods in it. We use objects to access.

Concepts of object oriented programming

Inheritance The feature of inheritance provides reusability of class. This is a process through Which a class acquires the properties of another class. The class which is created By inheritance is called derived class , and class whose features are inherited is Called base class Polymorphism It is the feature that gives ability to take different forms. To behave differently in different forms. It is done through operator overloading. An operator has one or more behavior. With same name it acts differently

Concepts of object oriented programming

Dynamic Binding binding is done as compiler does not know what are functions in a program. It gets to know when binding or linking of code and function is done either at run time or compile time. Run time binding is called as dynamic binding or early binding. It is linking of code and function at the run time. Also called late binding. In early binding or compile time binding function and code are linked when file is compiled Message passing Just as people communicate with each other . Objects also communicate with each other through message passing. They send and receive information with] each other. When object gets message it invokes a procedure in it and generate results of the procedure call.

Benefits

Benefits of OOP object oriented systems can easily be upgraded from small to large systems software complexity can be easily managed

Through Inheritance classes once created can be used again as required Through abstraction and data hiding. Data is secure.

languages with object oriented features

1. C++2. JAVA3. C#4. Falcon5. Delphi6. Objective C7. Python8. PHP59. Perl

C++ programming Environment

C++ Programming Environment consists of Text Editor and C++ compiler (1) Text Editor - Programs are typed in Text Editor . By default a new file Noname.cpp is opened. Type your programs here , save it , compile and run. (2) Compiler – Compiler is a System software that is installed on computer to compile and run programs. Most widely Turbo C compiler is used

C++ program Structure

A C++ program consists of the following 1. Class 2. Methods 3. Object 4. Instance Variables For Example creating a class #include< iostream.h> int main( ) { statements; getch(); return 0; }

C++ program Structure Explained

1. #include - This statement adds the necessary header file iostream.h to the program. It contains methods for input and output in a program 2 int main() – The program execution starts with main method. 3. Type the statements inside main( ) method.. 4. getch() – marks the end of program and returns to programming window 5. return 0- In C++ main() method is of int type, it is not necessary to return a value always so we take return 0; statement.

Creating Class and objects in C++

Example of class and object#include<iostream.h> Class sample // class named Sample { public: int a; // instance variable void get() // member method }; Int main( ) { sample S; // method is called using object S S.get(); }

Explanation

1. Class is created using class ‘keyword’ 2. Class has name Sample it has instance variable in which data is stored3. It has member method called get() . It can access the data in it.4. main() method is defined.5. An Object of class is created in main()6. method of class is called using object of class

C++ program Syntax

1. In Each Program header file iostream.h is included in the beginning2. put semicolon at the end of each statement3. When using classes create class and put semicolon at the closing bracket4. method are called member methods and variables are called data member5. The main method is of type int. ie.. Int main() is used in programs6. Getch() is placed before return 0;7. Return 0; statement is necessary because main has return type int. 8. Comments are given after two slashes as // comments9. comments are not executed they are used to enhance readability of program

Key Concepts

DataTypes

Operators in C++

1. Arithmetic operators 2. Relational operators addition + Equals == subtraction - Not Equal != Multiplication * Greater than > Division / Greater than equal to >= Modulus % Less than < Less than equal to <=

Operators in C++

3 . Logical operators logical AND && logical OR || logical NOT ! 4. Scope Resolution Operator - :: 5. Memory allocation operator - new 6. Memory release operator - delete 7. Line feed operator - endl 8. Field Width operator - setw()

Variables

Variables in C++ is valid name in the memory where input given by user is stored and the result of program is stored. When a variable is declared in program , it occupies space in memory according to its size. Such as integer type takes 2 bytes of memory, char type takes 1 byte of memory Example : #include<iostream.h> int main() { int a; float b; }

Working with Classes

A class definition starts with the keyword class followed by the class name; and the class body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations. The keyword public determines the access attributes of the members of the

class that follow it. A public member can be accessed from outside the class anywhere within the scope of the class object. You can also specify the members of a class as private or protected .

Private member cannot be accessed out side the class. Only the public member method of a class can access private data and method Protected – It determines the scope up to a single level of inheritance

Feature of OOPs - Inheritance

Inheritance Inheritance is using the previously defined class as required Base Class – The Class which is used for deriving a new class and whose features are used by it , is called Base class. Derived Class- The newly formed class which contains features of base class and also contains features of its own

Types of Inheritance

Polymorphism – operator overloading

Polymorphism It is achieved through operator overloading. With this we can create new definition of the operators by giving special meaning to them. Syntax: <return type> class name : : operator (arguments) { statements; } Example: void sample : : + operator() { x = +x; y = +y; }

Operators that cannot be overloaded

1. Class member access operators - ( dot . , *) 2. Scope resolution operator - :: 3. Size operator - sizeof( ) 4. Conditional operator - ? :

Oops Applications

1. Real Time Systems 2. Simulation and Modeling 3. Object Oriented Databases 4. Hypertext , hypermedia 5. Decision Support Systems 6. Office Automation Systems 7. CAD / CAM Systems

top related