Monday, July 7, 2008

Learn C++[OOP]

C++ is a general-purpose, high-level programming language with low-level facilities. It is a statically typed, free-form, multi-paradigm language, supporting procedural programming, data abstraction, object-oriented programming, generic programming and RTTI.
Programming Techniques
This section is a short survey of programming techniques. There are various types of programming technique is available in the programming era. Here more focus has been given over OOP.
Introduction
Without a program, a computer has no purpose. It becomes an inert mass, a way to keep a door open when the wind blows.

In 1952, a very clever man named John Von Neumann was working on a rather primitive computer that was programmed by moving wires about on a large plug-board.
Various programming techniques
This section is a short survey of programming techniques. There are various types of programming technique is available in the programming era. Here more focus has been given over OOP.

Principal of Object Oriented Programming
With procedural programming you are able to combine returning sequences of statements into one single place.

A procedure call is used to invoke the procedure. After the sequence is processed, flow of control proceeds right after the position where the call was made.
Introduction of OOP
Object

Object is an identifiable run-time entity with some characteristic and behavior. for example 'orange' is an object and its characters are shape, color etc.

Introduction of C++

In 1952, a very clever man named John Von Neumann was working on a rather primitive computer that was programmed by moving wires about on a large plug-board.
History of C++
C language is separation of C++ language .
C++ has made enormous alter in the marketplace of computer, because it is primary object oriented language
Introduction of C++

First C++ program
The C++ compiler runs a program called the C++ preprocessor. The preprocessor is expert to set in and carry off code from your source file.

Overview of OOP using C++
During the late 1970s and early 1980s, C became the dominant computer programming language, and it is still widely used today Since C is a successful and useful language but there arise a need for something else existed, the reason is complexity.

Elements of C++ Language
Tokens
Character set is a set of valid characters that a language can recognize. A character represents any letter , digit or any sign. The C++ has the following character set
Literals & constant
Literals are data items that never change their value during a program run. C++ allows several kind of literal:

Variables
Variable represents named storage location, whose values can be manipulated during program run. variables are called symbolic variables because they are named.
Declaration of Variable
Variables declared within a function are called local variables. They are also sometimes called automatic variables.
Data types
Data can be of many type e.g. character, integer, real, string etc. Any thing enclosed in single quotes represent character data.
Pointer
A pointer is a variable that holds a memory address. This address is usually the location the location of another variable in memory.
Constant
The keyword const can be added to the declaration of an object to make that object a constant rather than variable
Control structures & Operators
Introduction of control structure
Statements are the instructions given to the computer to perform any kind of action, be it data movements, be it making decisions, or be in repeating action.

Introduction of Operators

Once we know of the continuation of variables and constants, we can begin to operate with them. C++ integrates operators.
Precedence of Operators
Writing complex expressions with more than a one operands, we may have a number of misgivings about which operand is evaluated foremost and which afterward.
Expression
An expression is composed of one or more operations. The objects of the operations are referred to as operands. An expression in C++ is any valid combination of operators, constants, and variables
Functions
Introduction
Now that you should have learned about variables, loops, and if statements it is time to learn about functions. You should have an idea of their uses.
Function declaration & prototyping
Functions that a programmer writes will generally require a prototype. Just like an blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed.
Function definition & call
Once the compiler knows that you have declared a function, it then needs the definition of that function.
Return values of functions
Return values are used in the function syntax and so far we have mentioned void as the return value of a function. Void means: no value is returned by the function.
Types of function
The declaration of library function is in the header file specified at the beginning of the program
Inline functions
If a function is very small, then there is no need to go for branching to sub routines (i.e. there is no need for using another function).
Recursion
What is recursion? Recursion comes from the word ‘to recur’ which means happening repeatedly over and over again.
Manipulators

Manipulators are keywords that are used for doing something to change the way the output appears on the screen.
Objects & Classes
Object is an instance of a class, i.e. only when you define an object for a class, will the compiler allocate memory for the object.
Object

The command prompt specifies what drive and directory you are currently in. The command prompt can be seen in the ms-dos prompt.
Classes
Object & classes together
Command line arguments
The command prompt specifies what drive and directory you are currently in. The command prompt can be seen in the ms-dos prompt.
Constructors & Destructors

Basic constructors
Constructors are used for this purpose. A constructor is a special member function with same name as the class. It is used for the automatic initialization of object and it is carried out at the time of creation.
Copy constructors
A copy constructors is used to declare and initialize an object from another object. A copy constructor is invoked when you initialize a new object of a class using an existing object.
Dynamic constructor
Destructors in details
Allocation of memory to objects at the time of their construction is known as dynamic construction of objects. The memory is allocated with the help of the new operator.
Operator Overloading & Type Conversion
A destructor always has the same name as the class itself, but is preceded with a ~ symbol
Operator overloading
The compiler identifies that it is an overloaded operator by looking at the data type of operand (i.e. if it is a user defined data type then the compiler knows it is an overloaded operator
Binary operator overloading

In the case of a unary operator we generally use no arguments. In the case of a binary operator we need to use one argument.
Type conversion
Conversion of a numeric values to Boolean yield T if the converted value is non-zero. A string value yields T if its length is non-zero.
Inheritance
Data Hiding
Inheritance

It is also known as data encapsulation and is a fundamental concept of Object oriented programming. By the way, in many instances you may come across the term ‘method’. A method is just another term used for a function.
Multople Inheritance
Multiple inheritance means that one subclass can have more than one superclass. This enables the subclass to inherit properties of more than one superclass and to "merge'' their properties
Pointers,Virtual Functions & Polymorphism
An Introduction to pointer
Pointers are variables that store memory address. This address is the address of another variable.
Pointer
When * is used, it denotes a pointer. The data type denotes the data type to which the pointer points.
Polymorphism
Basically, the word is the same word but it's interpretation varies depending on the use. Similarly, in C++ we can make use of polymorphism.
Virtual functions
Virtual function is a member function of a base class and redefined by a derived class.
I/O Operations
Insertion & Extraction
StreamsVirtual function is a member function of a base class and redefined by a derived class.
Stream functions

This section covers the basics of using streams, including explaining which streams are provided by the streams library, how the different streams classes are related, which member functions are available for use with streams, and how to create your own streams.
Formatting

When a program inserts or extracts values other than single characters, such as integers or floating-point data, a number of different formatting options are available.
Manipulators again
A manipulator is an object that can be an operand to the << or >> operator, but which modifies the state of the stream, rather than actually inserting or extracting any data.
I/O status handlingAssociated with each stream is a set of flags indicating the I/O state of the stream.
Working with Files
Streams revisitUsing C++ you can access a device through an intermediate medium. The intermediate medium is called as stream. The device that you access is known as file.
Opening & closing a fileWe think you'll find this interesting. You'll learn how to access disk files in the following sections.
Writing to a text fileReading and Writing to a file is very easy. First we shall take a look at writing:
Reading a text file
Before learning this section We hope you know the Difference between void main ( ) and int main ( ). If you haven't seen the section then please do so and come back here.
Template & Exception HandlingIntroduction of template
Templates are the mechanism that make it possible to use one function or class to handle many different data types
Function template
We can also define function templates that could be used to create a family of functions with different arguments types. The general format template is
Class template
However, the examples of these classes that we presented could store data of type float in a stack we would be required to define a completely new class.
Exception Handling
Check out whether your C++ compiler supports this feature (the older C++ compilers will not support exception handling
Namespace & Dynamic Memory
Introduction of Namespace
Namespace is the collection of or group of same type of classes. Meaning of this it is collection of same type of entities.
Introduction of Dynamic Memory
With the help of dynamic memory we can determine memory required by variable during runtime.
New & Delete OperatorsTo demand dynamic memory there is use the operator new. new is followed by a data type specifies and if a series of extra than single element is mandatory- then there is use of brackets []. It returns a pointer to the beginning of the new block of memory allocated.

0 comments:

Copyright

Copyright © 2008 C Tutorial, All rights are reserved