11th Computer Science 12th Computer Science BCA CBSE CBSE JAC JAC

C++ Programming Language Tutorial

C++ Programming Language Tutorial
Written by AIPS

C++ is an object oriented, High level , Case sensitive, Platform independent, 3rd Generation’s programming language through which we can communicate with the computer system.

Object oriented means program is divided into classes and objects.

It was developed by B Jarne stroustrup at AT & T Bell Laboratory in USA in 1980.

AT & T means American Telecommunication and Telegraph

It is an incremented or Extended or super set of C language. i.e Every term of C language is supported by this language

It is a Case sensitive language . i.e it treats different in upper case and lower case. a and A are not same in this language.

It is a platform independent language. i.e it supports any operating system like windows 10, windows 8, windows 7, Linux, Unix ..

It is used in both writing of system software and application software.

It supports both the feature of Low level and High level language , so some says its a middle level programming language.

It also support Supports feature of structured programming and object oriented programming.

Note:-

Programming Language:- The language which used to give instructions to computer.

programming:- The process of giving instructions to computer. or the process of making program

Programmer:- The person who gives instructions to computer.

There are two types of programming language.

  1. Low level language
  2. High level language

1st Generation 1940-1950 Machine Language (0,1)

2nd Generation 1950-1958 Assembly Language (Mnemonic code or small english words like ADD ,SUB, MULTI ..)

3rd Generation 1958-1985 High level Language (English ) (3GL)

4th Generation 1985-onward very High level Language (English )(4GL)

Note :-

G L :- Generation Language

1st and 2nd Generation Low level language(known as)

3rd and 4th Generation High Level language(Known as)

Low Level Language:- The language that does not include translator to convert source code into object code and does not provide portability is called low level language. i.e program made in one computer can not be used in other computer.

Example

1st Generation / Machine language :- Instruction written in 0, 1 or binary code is called machine language. It is very easy for computer and tough for programmer. There was no any translator used.

2nd Generation / Assembly Language:- Instructions written in small English words or Mnemonic code is called Assembly language. Assembler was used as Translator.

High Level Language:- The language which includes any translator to convert source into object code and provides portability is called high level language. i.e program made in one computer can be used in other computer with no or minimum changes. Example 3rd and 4th Generation language.

Basic Format of C++ Program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr( );
…………………..
………………….
getch( );
}

C++ program format using class

#include<iostream.h>
#include<conio.h>
class nips
{
public:
int a,b,c;
void show( )
{
…………………
}
};
void main()
{
clrscr( );
nips obj;
…………………..
………………….
getch( );
}

Note:- After writing program we need Compile and Run.

Compile Alt+ F9

Run Ctrl +F9

Error / Bug in Programming

Any mistake done by programmer in a program is known as Error.

There are three types of Errors.

1. Syntax Error: – Any mistake in Respect of programming Rules is known as syntax Error.Syntax error is detected by the computer.

Example:

Semicolon missing (;)

Curly bracket not balanced etc…

2. Logical Error: – Any mistake done by programmer in program’s logic is known as logical error. Logical error is not detected by computer.

Example:

* Symbol used instead of + etc…

Note: – compilation Error (syntax and Logical)

3. Run Time Error: – Error which arises after error free compilation is known as Run time error.

Example:

  • Divide by zero
  • Infinite loop
  • Incorrect file name etc..

Comments :-

  • comments are non executable statements.
  • comments are always neglected by compiler.
  • comments are replaced by white space during the Pre -processor phase.
  • comments can be used for documentation.
  • comments can be single or multiple line.
  1. single line comment: – we use // symbol and after double slash symbol written contents are ignored. End of line considered as end of comment
  2. Multiple line comment:- we use /* ………………………….*/ symbol for multiple line comments.
/*  Q. write a program to print your Name.
      and Address.  */
#include<iostream.h>
#include<conio.h>
void main()  // indicates Starting of program
{
clrscr();		//to clear the screen
cout<<”NIPS ACADEMY”;
cout<<”\n Abadganj”;
getch();
}

output

NIPS ACADEMY

Abadganj

Algorithm :-

Steps to solve a problem written in simple English language, is known as Algorithm.

Rules for writing Algorithm

There are following rules for writing an algorithm.

  • Algorithm must begin with “START” or “BEGIN” and ends with “STOP” or “ËND”
  • Each step has a step Number.
  • “ACCEPT” or “INPUT” is used take entry from the user.
  • “PRINT” or “DISPLAY” is used for displaying output.
  • Variable names are generally written in upper case.
  • := is used to assign value to a variable.
  • we use “IF” to check condition.

IF<condition> then

…………………………….

……………………………..

END IF

  • “While” is used for repeating steps.

while<condition> then

………………………………..

…………………………………

END WHILE

Note:- No Need to follow Grammatical Rules, it is never wrong but should be understandable and written in copy before writing in computer.

Q. Write an Algorithm to Post a letter.

Step 1:- START

Step 2:- Write a Letter

Step 3:- put the letter in an Envelope

Step 4:- write address on Envelope

Step 5:- post the letter into letterbox

Step 6:- STOP

Q. write an Algorithm to find sum of two numbers.

Step 1:- START

Step 2:- INPUT A,B

Step 3:- C=A+B

Step 4:- PRINT C

Step 5:- STOP

Flowchart: –

Symbolic or Graphical representation of a program , is known as Flowchart.

Symbolic representation of Input, Output and Process is called Flowchart.

There are following symbols that are used in flowchart.

Symbol…………………………. Purpose

Oval / Terminal box …………… START or STOP

Parallelogram………………… INPUT or OUTPUT

Rectangle………………………… Process

Rhombus / Diamond ……………………. Decision

Arrow ………………………….. Flow line

Data Type in C++

Data type shows about the nature of variable. i.e type to be stored,range, required memory,etc..

Data type is a type of data through which data are recognized and categorized.

  • primary Data types/Basic/Built in /Primitive

These data types are at the lowest level that represent actual data in computer’s Memory.

Example :

char ,int ,float, long ,double, void …

  • Derived data types

These data types are inherited from primary data type. i.e we have to take help of primary data type when we use derived data type.

example:

Array, pointer, Function etc.

  • User defined Data types

The data type defined by the user with the help of primary data type is called user defined data types.

Example:

structure , union , class , enumeration, etc.

Primary Data types

Data types………………………….Size(Byte)……………………..Range

signed char OR char …………………………1 ……………………………….-128 to 127

unsigned char ………………………………….1 ……………………………….0 to 255

signed int OR int ……………………………..2…………………………………-32768 to 32767

unsigned int …………………………………….2……………………………….0 to 65535

signed long OR long ………………….4…………………-2147483648 to 2147483647

unsigned long……………………………….4…………………0 to 4294967295

float …………………………..4…………………….-3.4 *10^38 to 3.4 to 10^ 38

double ……………………8…………………. -1.7*10^308 to 1.7*10^308

long double ……………..10 ……….. …-1.7*10^4932 to 1.7*10^4932

About the author

AIPS

Leave a Comment