C++ provides mechanisms for ensuring that your objects are initialized properly before they are used. As your objects go in and out of scope, memory is first allotted to them and then initialized. C++ provides a special member function called the constructor for the initialization of an object.
A constructor function is called whenever an object is created. An object can be created as a global variable, as a local variable, through the explicit use of the new operator, though an explicit call of a constructor or as a temporary object. Constructors are called when an object is created as part of another object. LEARN MORE>>

Classes and Objects....cont(3)

The declaration of a class does not include objects of that class. It only specifies the type of information the objects of this class type will hold, when created. Objects of a class can be created using the class tag-name as type specifier. The syntax used to declare objects is:
class-name object1, object2, .....objectn;
Ads will appear onthe next page refresh.
For example:
class book;
int bookno;
float cost;

Classes and Objects...cont(2)

Array within a Class
Arrays can be used as data members in a class. an Array can be a private or a public data member of the class. If an array is a private data member of the class, then only the member functions of the class can access it. Otherwise if an array is a public data member of the class, it can be accessed directly using objects of the class type. Consider the following class definition:
class myarray
int a[20];
void getval(void);
void display(void);
Here, the arrray a is declared as a as a private member of the class myarray. It can be accessed only through the member functions of the class like any other private data member . The member function getval() reads the values of elements of the array a and the member function display() prints the values of elements of the array a. LEARN MORE>>

Classes and Objects....cont(1)

An object is a region of storage with associated semantics. After the declaration int i;
we say that " i is an object of type int ". In C++, "object" usually menas "an instance of a class". Thus, a class defines the behaviour of many objects(instances). For example:
class Myclass
int a;
void getval(int);
void display();

Classes and Objects

A class is a fundamental building block of the object oriented programming language C++. Bjarne Stroustup, the originator of C++ language, gave the name "C with classes" to this language initially. The class is the most important feature of C++. It implements OOP concepts and ties them together.
A class is a way to bind data (describing an entity) and its associated functions together. In C++, a class makes a data type that is used to create objects of this same type.
The prerequisites for classes and objects are structures and the functions. A structure provides a way to group data elements and a function organizes program actions into a named entity.
Class Specification
A class specification consists of two parts:
1. Class declaration
2. Class method definition
Declaration of a Class
A class is declared using the class keyword. the syntax of a class declaration is similar to that of a structure.
The general form of a class declaration is : LEARN MORE>>

Structures and Arrays

Strutures are user defiened data types, whereas arrays are derived data types. While an array is a collection of nalogous elements elements, a structure assembles dissimilar elements under one roof. thus both arrays and structures allow several values to be treated together as a single data object.
int a[]={10,20,30,40,50}; // array are elements of the same type (int)
student stud1={2, "Rahul",12, 67.00, 'A'}; // structure elements are of different types
Arrays of structures
Using arrays of structures is similar to using arrays of anything else. When structures are present within an array you have an array of structures. To declare an array of structures, LEARN MORE>>


Initializing Structure Elements
The elements of a structure van be initialized either seperately using seperate assignment statements or jointly using the notation similar to that used for initializing arrays. The example given below demonstrates how structure elements can be initialized jointly or seperately.
struct student
int rollno;
char name[20];
short clas; // class is a reserved word of C++
float marks;
char grade;
} stud1, stud2;


A Structure is a collection of simple variables. The variables of a structure can be of different types: int, float and so on. (this is unlike the array, in which all the elements must be of the same type.) the data items or varible declared in the structure are called the members of the structure. The structure name is often reffered to as its tag.
For C++ programmers, structures are one of the two important building blocks in the understanding of objects and classes.
Defining a Structure
We know that structure is a collection of logically related variables referenced under a single name. These variables can be of different type, and each has a name which is used to select it from the structure.
A structure can be defined as a new named type, thus extending the number of avaialble types. LEARN MORE>>

Math & Conversion Functions

These functions are used for various algebric and trignometric operations:
1. abs()
The function abc() calculates the absolute vlaue of an integer. The argument to this function is an integer. It has a prototype in the header file math.h
2. fabs()
The function fabs() returns the absolute value of an argument. The argument to this function is a number of type float or double. It has a prototype in the header file math.h LEARN MORE>>

Character and String functions

These functions are used for manipulating characters.
1. isalnum()
This functions carries out the test "Is the character alphanumeric?". An alphanumeric character is a letter of either lower or upper-case, or a digit. It has a prototype in the header file ctype.h. The argument to this function is a character represented as an integer.
The function isalnum() returns a non-zero value if the character is alphanumeric and zero if it is not so.
2. isdigit()
This function carries out the test "Is the character a digit?". It has a prototype in the header file ctype.h. The argument to this function is also characte represented as an integer.
The function isdigit() returns a non-zero value if the character is a digit and a zero if it is not so.

Header Files

Various library functions are available in C and C++ in the form of header files. A hheader file is a file containing a list of all the functions and structures that will be used by a file ( for C++, classes and methods).
Header files provide function prototypes and declarations for library functions. Data types and constants used with the library functions are also defined in them.

In order to include the required header files in the program, angle brackets '< ' and '>' are used. the angle brackets prompt the C++ compiler to search for the header file in its include directory. LEARN MORE>>

Scope Rules in C++

Scope determines visibility of identifiers across function/procedure boundaries, code blocks and source files. The scope rules of a language decide in which part(s) of the program a particular piece of code or data item can be accessed.
There are five types of scopes in C++
Function Prototype



Default Values in Arguments
When defining a function we can specify default values that will be taken into acount by the argument variables in case these are avoided when the function is called. This is done by simply assigning a value to the arguments when declaring the function. These values will be used if that parameter is not passed when when the function is called.
If the value of that parameter is finally set when calling the dafault value, it is stepped up. For eg: LEARN MORE>>


Declaring Vs Defining a function
The syntax of a function declaration is identical to the header of a function definistion, except that:
It does not include a statement for the function. Which means that it does not include the statement body with all the instructions that are usually enclosed within key brackets { }.
It ends with a semicolon(;).
In the argument enumeration, it is enough to write the type of each argument. The inclusion of a name for each argument is recommended, though optional as in the definition of a standard function.
Calling a function
In order for a function to be used, it must be called by another function. To call a function, one enters the name of the function followed by a matching pair of parentheses inside which is the list of parameter values to be passed to the function. The list is in the same order as in the declaration. The parameters included in function declarations are called formal parameters while the parameters listed in a function call are called the actual parameters.
For example, in order to invoke a function whose prototype is of the following format:
flaot volume(float, float,float);
the function call statement can be used:
where l,bh are float variables. LEARN MORE>>


A Function is a named unit of a group of program statements. This unit can be invoked from other parts of the program. With the help of a function the program becomes easy to handle and ambiguity is avoided when dealing with a small part of the program. The size of the program also reduced by the use of functions in a prgram.
Functions are pieces of codes that do exactly what their names indicates - performs a task or function in your program. Functions are good because they let you write a code that is modular. Modular code is easy to debug and easy to maintain. In order to use a function, it has to be first declared and then defined. LEARN MORE>>


In all programs seen until now, we have used only numerical variables, used to express numbers exclusively. But in addition to numerical variables there also exist strings of characters, that allow us to represent successions of characters, like words, sentences, names, texts, et cetera. Until now we have only used them as constants, but we have never considered variables able to contain them.
In C++ there is no specific elemental variable type to store strings of characters. In order to fulfill this feature we can use arrays of type char, which are successions of char elements. Remember that this data type (char) is the one used to store a single character, for that reason arrays of them are generally used to make strings of single characters. LEARN MORE>>

Multidimensional Arrays

An array that has more than one subscrpt is known as a multidimensional array. Multidimensional arrays can be visualizes as arrays of arrays.

A two-dimensional array is the simplest form of a multidimensional array. In a two-dimensional array, two subscripts are enclosed in square brackets. The rirst subscript designates the row and the second subscript designates the column. A two-dimensional array is used for table processing or matrix manipulation.
Array Declaration
The general form of a two-dimensional array declaration in C++ is:
type array-name[rows][coloumns];

Structured Data Type: Arrays

Arrays are a series of elements (variables) of the same type placed consecutively in memory that can be individually referenced by adding an index to a unique name.
An Array declaration is very similar to a variable declaration. For eg:
float annual_temp[10];
This will cause the compiler to allocate space for 10 consecutive float variables in memory. The number of elements in an array must be fixed at compile time. The elements of an array are ordered by the index. Array index numbering starts from zero. LEARN MORE>>

Single Character Functions

C++ supports many character-based input and output functions for reading and writing a character. These functions can read or write one character at a time. These functions are known as unformatted console I/O functions.
Getchar() and Putchar() Functions
The functions getchar() and putchar() are single character functions. The heeader file for these functions is stdio.h.
The getchar() function reads a single character from the standard input device( keyboard). The getchar() waits for the character input until a charcter is typed at the keyboard. LEARN MORE>>

I/O Functions

Input and output devices play a key role indata processing. the first phase of processing data is input. Data is accepted in the form of input and output is generated after processing data. C++ language does not facilitate input and output with the help of keywords. Input and output operations are performed with the help of library functions. There are header files which help in performing input/output activities.
Header Files in C++
The list of keywords in C++ does not include functions. However, built in functions are available with C++ library header files. Declarations of function prototypes, classes etc. are provided by header files. The function prototypes are pre-declared before using them in the program. LEARN MORE>>

Bifurcation of Control

The break instruction.
Using break we can leave a loop even if the condition for its end is not fulfilled. It can be used to end an infinite loop, or to force it to end before its natural end. For example, we are going to stop the count down before it naturally finishes (an engine failure maybe):
// break loop example Output
#include 10, 9, 8, 7, 6, 5, 4, 3, countdown aborted!
int main ()
int n;
for (n=10; n>0; n--)
cout << n << ", ";
if (n==3)
cout << "countdown aborted!";
return 0;

Iterative Statement: do-while Loop

It is another repetitive control structure provided by C++. It is an exit control loop. It evaluates its test-expression after executing its loop body statements. A do-while loop always executes at least once.
The syntax of the do-while loop is
while ;


Iterative Statement : While Loop

The while loop.
As mentioned earlier, the while loop is an entry controlled loop. The syntax of a while loop is
while (condition) statement
and its function is simply to repeat statement while expression is true. While is a reserved word of C++; condition is a Boolean expression; and statement can be simple or compound statement.
For example, we are going to make a program to count down using a while loop: LEARN MORE>>