Você está na página 1de 10

INTRODUCTION TO

C++…
 The C++ programming language was developed at AT&T Bell
laboratories in the early 1980s by BJARNE STROUSTRUP..
 He found ‘C’ lacking for simulations and decided to extend the
language by adding features from his favorite language, SIMULA
67.
 SIMULA 67 was one of the earliest object oriented language.
 BJARNE STROUSTRUP called it “c with classes” originally.
 The name C++ (pronounced as C plus plus) was coined by RICK
MASCITTI where “++” is the C increment operator !!
C++ CHARACTER SET
 Character set is a set of valid characters that a language can recognize .
A character represents any letter , digit or any other sign.
 THE C++ HAS FOLLOWING CHARACTER SET -:
LETTERS a-z , A-Z
SPECIAL SYMBOLS Space + - * / ^ \
() {} [ ] = !=
<> . ‘ “ , ;
: %! &? _
DIGITS 0-9
WHITE SPACES Blank space , Horizontal tab
OTHER CHARACTERS C++ can process all 256 ASCII
characters as data or as literals
A FIRST LOOK AT C++
PROGRAM
# include < iostream.h >
# include<conio.h> OUTPUT--
Void main ()

hello
{
clrscr ();
cout<< “hello”;
getch();
}
SELECTION STATEMENTS (Switch
statement)

 SELECTION STATEMENTS allow to choose set of instructions for execution


depending upon an expression’s truth value.
 C++ PROVIDES TWO TYPES OF SELECTION STATEMENTS : IF AND SWITCH
 LET’S STUDY ABOUT SWITCH STATEMENT IN DETAIL :

THE SWITCH STATEMENT


 C++ provides a multiple – branch selection statement known as SWITCH.
 This selection statement successively tests the value of an expression
against a list of integer or character constants .When a match is found ,
the statements associated with that constant are executed …
SYNTAX OF SWITCH
STATEMENTS
THE SYNTAX OF SWITCH STATEMENTS IS AS FOLLOWS:
Switch (expression)
{
case constant 1: statement sequence 1;
break;
case constant 2: statement sequence 2;
break;
case constant n-1: statement sequence n-1;
break;
[default : statement sequence n];
}
WORKING OF SWITCH
STATEMENT
The expression is evaluated and its values are matched against
the values of the constants specified in the case statements…
When a match is found, the statement sequence associated
with that case is executed until the break statement is reached. If a break
statement is not included, that situation is called fall through.
The default statement is optional and if it is missing ,no action
takes place . When a break statement is encountered in a
switch statement , program execution jumps outside the body
of the switch statement…..
PROGRAM OF A CALCULATOR USING
SWITCH STATEMENT

#include <iostream.h>
#include<conio.h>
Void main ()
{
clrscr ();
Char op;
Float num1, num2;
Cout<<“ENTER OPERATOR EITHER +,-,* OR /”>>;
Cin>>op;
Cout<<“ENTER TWO OPERANDS”>>;
Cin>>num1>>num2;
PROGRAM OF A CALCULATOR
USING SWITCH STATEMENT
Switch(op)
{
case ‘+’ : cout<<“num1+num2”;
break;
case’-’ : cout<<“num1-num2”;
break;
case’*’: cout<<“num1*num2”;
break;
case’/’: cout<<“ num1/num2”>>;
break;
default : cout<<“ERROR! OPERATOR IS NOT CORRECT”>>;
}
OUTPUT
(WHEN VALID INPUT IS PUT) OUTPUT
(INVALID INPUT)

 ENTER OPERATOR EITHER


 ENTER OPERATOR +,-,*,/=%
 ENTER TWO OPERANDS=
EITHER +,-,*,/= + 2,6
 ENTER TWO  ERROR! OPERATOR IS NOT
CORRECT
OPERANDS = 2,6
 2+6=8
MADE BY-
SALONI DAWAR
11-D