C++ Introduction

Basics of C++ Programming:


C++ was developed by BJARNE STROUSSTRUP at AT&T BELL Laboratories in

Murry Hill, USA in early 1980’s.

Strousstrup combines the features of ‘C’ language and ‘SIMULA67’ to create more powerful language that support OOPS concepts, and that language was named as “C with CLASSES”. In late 1983, the name got changed to C++.

The idea of C++ comes from ‘C’ language increment operator (++) means more additions.

C++ is the superset of ‘C’ language or extension of ‘C’ language, most of the ‘C’ language features can also applied to C++, but the object oriented features (Classes, Inheritance, Polymorphism, Overloading) makes the C++ truly as Object Oriented Programming language.


Structure of C++ Program
 



 Section 1 : Header File Declaration Section

1. Header files used in the program are listed in this section.

2. Header File provides Prototype declaration for different library functions.

3. We can also include user define header file.

4. Basically all preprocessor directives are written in this section.

Include files provides instructions to the compiler to link functions from the system library.

Eg: #include <iostream.h>

#include – Preprocessor Directive iostream.h – Header File




Section 2 : Global Declaration Section

1. Global Variables are declared here.

2. Global Declaration may include

˗ Declaring Structure

˗ Declaring Class

˗ Declaring Variable

Section 3 : Class Declaration Section

0. Actually this section can be considered as sub section for the global declaration section.

1. Class declaration and all methods of that class are defined here.

2. A class is a way to bind and its associated functions together. It is a user defined datatype. It must be declared at class declaration part.

Section 4 : Main Function

1. Each and every C++ program always starts with main function.

2. This is entry point for all the function. Each and every method is called indirectly through main.

3. We can create class objects in the main.

4. Operating system call this function automatically. main( )

{

...........................

}

Program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function is the logical and of the program.

Section 5 : Method Definition Section

1. This is optional section . Generally this method was used in C Programming.

2. Member function definition describes how the class functions are implemented. This must be the next part of the C++ program.

Input / Output Statements Input Stream

Syntax:

cin >> var1 >> var2 >>;

cin is a keyword, it is an object, predefined in C++ to correspond to the standard input stream.

>> is the extraction or get from operator. Extraction operation (>>) takes the value from the stream object on its left and places it in the variable on its right.

Eg:

cin>>x;

cin>>a>>b>>c;

Output Stream:

Syntax:

cout<<var1<<var2;

cout  is a keyword, predefined object of standard output stream

<< is called the insertion or put to operator. It directs the contents of the variable on its right to the object on its left. Output stream can be used to display messages on output screen.

Eg:

cout<<a<<b; cout<<”value of x is”<<x; cout<<”Value of x is”<<x<<”less than”<<y;

Tokens

The smallest individual units in a program are known as tokens. C++ has the following tokens

˗ Keywords

˗ Identifiers

˗ Constants

˗ Strings

˗ Operators

Keywords

˗ It has a predefined meaning and cannot be changed by the user

˗ Keywords cannot be used as names for the program variables. Keywords supported by C++ are:

asm
auto
break
case
catch
char






class
const
continue
default
delete
do






double
else
enum
extern
float
for






friend
goto
if
inline
int
long






new
operator
private
protected
public
register






return
short
signed
sizeof
static
struct






switch
template
this
throw
try
typedef






union
unsigned
virtual
void
volatile
while






 

The specific C++ Keywords

There are several keywords specific to C++

asn
catch
class
delete




friend
inline
new
operator




private
protected
public
template




this
throw
try
virtual




أحدث أقدم