Programming in C++
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 used in both writing of system software and application software.
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>
voidmain()
{
clrscr();
…………………
..
…………………
.
getch();
}
C++
program format using class
#include<iostream.h>
#include<conio.h>
classnips
{
public:
inta
,b
,c
;
voidshow(
)
{
…………………
}
};
voidmain()
{
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>
voidmain()
// 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 Evelope
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 or 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