Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
61 views12 pages

It Begi Nning Uwi TH CH ND, Its Teariues) Snet S: Jnngungo

C++ allows for control structures like conditionals and loops to control the flow of a program. The main control structures in C++ are: 1. Conditional statements like if-else that allow certain code to execute based on whether a condition is true or false. 2. Loops like while and for that repeat a block of code as long as a condition remains true or for a set number of iterations. 3. Jumps like break and continue that allow skipping portions of code within loops under certain conditions.

Uploaded by

Aneesh Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views12 pages

It Begi Nning Uwi TH CH ND, Its Teariues) Snet S: Jnngungo

C++ allows for control structures like conditionals and loops to control the flow of a program. The main control structures in C++ are: 1. Conditional statements like if-else that allow certain code to execute based on whether a condition is true or false. 2. Loops like while and for that repeat a block of code as long as a condition remains true or for a set number of iterations. 3. Jumps like break and continue that allow skipping portions of code within loops under certain conditions.

Uploaded by

Aneesh Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

21/May OOP with C++

it Beginning uwith Ch nd, its teariues]


in engLly 1980s
tuaD deueloror. by Dinouane StBUAtuup
C++ iD a akjoct 0Puantod Jnngungo. but snet s puo1a O0
Jonqunge [Because we con deuelep C ctyle progruns using C+
C++ D o o tondion
tuppeutn bottom up. oljort eiontosl donign.
Heplication of Ctt
i n g Ct+ wwe can dauelsp edlitun, conpilauD, dataUaaeD
cSULNiLation a t a any complarc sonl lijo appliration
J Uaing Ctt we tan dovolep 0o Jibsaion ane Marina
Jbuel p9UDgSamD.

St uetuge Ot Ctt paogeam


Ct+ headers KiostTEan
Class efination.
Unit 2
Menber tunction detination #include < iostaeam
Main func tion.
Using name sPace stcb
int mea inC)

#include <ióstream int a,b Sum


two no.:
COut < " Enten
using nasmespace sto cin >>CL
0 t main Cin b
SUM atD;
cout < "Hello usgld"<<enddl: COut "Sum is < sum <s encil

getuen Op: Tetuon O;


Ope s a t o

uA@a
inaetion /put
inae9ution /putlo"C<<)
Atatamant hat
in the SuAut
cout
Hiad Juben oncsuartior/et From
Jntment
cin JD tha input opartabC )
tnACoda sarde cout
with
with

Jho < Ad. >> tns a cout < SUm is Coutsum


cin >aa Cin > a >>b; c out Sum;
cin> b is <sum
29/May
Basic datd. types
16uilt-in ypes
int,cha, tloab, double, uoid doesnt
functions
1S a deturn type.it
oetuon anth0g
Use-defined Ty Pes
stmuctuTE, Ve UNion and clhDD,

3 Denived. types
a Oy, tunction, pointes, sekesgenee
in
oules hat ane apliacble fo naming a vagia ble
Variables
Vagiables a
e also agelicable in Ct*
ae

C++ allua ua to Jsth doclasta ond initinlige ya9inled


hooueL Hy coLa orlod.
Ys o d nst hauwe to declnsa cw ha JJa9úailea at
he Jeginin9 -

<data-type> list-of-vadiables;

Retevence vaiables
H oh0once dJa9ialla p9BUielon aun alian C culto9untue

name) a p9QLDUAly.
dsinlla JAt e initisoc a tha
.A uleHaNe
ine o} dorlosuation.
data type> TetedeNce name;

Syntaoc of declaeing an aliag


<data.type 3 alias. name -
vac namg
in a lO
int m =
cout aer endl; Disply 10
cout erdl; ||Display I)

couteactendl1/Display
Cout n<Tendl / Dis play
27 May
Eccpme sisith Are hei tupES:12
An ocpotaaaion ip ornluiatisn pOLateno, Lonatant
And Ja9tinlylea n9oangod 0 p0 Bha suulas tha Jangungo
ad
H n ocpsanDi.on may conait eona col Moa NAUneda

*An éteprméssion 'délimitedu'bgra i&called statemert


i-e a 8 8; 4
Ccpoession statement'
Eocpstaai.onA con le oh ho jsllbUing +ypoh

Coatont oscpanAion.
Antagoua ocgotannion.
QcpsoADion
Pointo ocAoAOAion
Ralational acpoaRJsn
Lgical acpsOApion.
itwiQ op9IaRai on
Note:- Al spasuntoua C n90 unilnlblo in C++. ie

Agithmoti *
3Annignrnand C 4
Shoot hand/compound assigninent
Ralntional C, >,4, E
Relat ional inenuo lity Reletional eality
Logica C83..!)
Btwise C . 1 , , . )
Trg ue
Teenoany i ? )
Fake
1. Constont erpae ssion -
conninta only Conatart valuon
Sg-14. 2015/2 c
20+2-56 LA65. 1 ASC II values
22-5 a -97 J

2.Integeal exxpression o9to. thona that udno inag slanultn


atoimplomontiq a l the utomatic
And ocplirittupo onUebionD
Eg- int m-5 int M 5 , 0-4 m+ 5t intC9-6)
M-5 M*0-6 AsCII i-e 5+9
5%4-5 (automatic\
20-5 Ceccplicit type)
+ype

3 Float e ocpre ssion -

DO thoee uhith, nttoi Al Jousnial,


d u c a lonting psind anulta

Eg:-C+9 gy/10D
hsa.C-3-2.y=&5 C=12-0 y=9-o
9-2t9-5 12-O3O/10
6-7
6-O/10- miteed -mode etuptession
6
4.Pointes epeSsion p9DdurOA Oddtan uuluan a d nat
p9umitile waluea
Eg- k int k SP
int P
addoess of actres ot
P R P

-artdson
b"Kelational erpaession -

yoild. s0sulto type Uosl whith


taben a valune

&g- int L-5. y-8 a-5 -6 c-4 d-8


atb=Ctc

5r6 4t8
T6ue I 12 False
APa JJRd, tha will be Oauatd
thos p i t r a t i r . orpoLion
J i a ond h 0Lultn a g a SomRa90c Boo lean ecc pression
6. Logical eopsession- Combino two o MBLO alntinml
ocp9onDioo and podute
Josl ypo
AODult
ga.>b 39 c-=1O
if a 5 b 3 C-9.
hn a>b 6 c 9 False
Hene. if the fi6st crP*SÍon is folse he second expaession
is not evaluated

if a i5 b 3 OC- IO.
hn a b 3 8 Oc = 10 louue

AO URO to manipulato dato c t t laye


ituIS expression

Operatos Ouerloadinq
Ouesuoading M e a a adAigning dita3ort monringa tD
An

opontion, dopanding on the Condosd


-C++ nllsuo oUesUnding e cp9ntrgPLa
-"<" And ">»' asa uusasledl opauutoa in Ctt
Eq c »i Hosta, Acta aD itwine opasuato
cin > a Hoa, ncta a ocueuctisn ore9ato.

JJitwino on9nto
couta Hsa, « Din an inetinn ofaato.

Note:- inditortisnal spoato in alAo calacl an deaLouonting


Gpontr9.
28/May ntin,
J

ContwolStouctu res
Entoy
Enty Loop
Enty
TTe False
Action 1 Conditiony
e
ondition* Aetio0 1

Action 2 Action Action 2


False

Action Action 3
Action 9

Seauence Selectiony i ir teration


roqsam guns in a Selectively eOcecutes a tAlows uS te ececute
Sequence block ef statements ableck of statements
conditon
based on whethey, a SO long as c
evaluates te +Oue. O Oce
Cerdtain Condition
evalueates fo tove/talse thecondition eualuates t
false, the block wil not
.

Eg:Simple if e cecute any more


Stouctudecl if Eg- while
Nested if do..uwhile
Multi-uway, Ihe else if ladder
bwanching Switch
yntao o decision making r d boanching Statements,

imple il stalaman!
i Cere Ssion) selatioial eopsecoio
stotement- block; If toue staternent is erecuted
IF false 6taterert is Skiped

tsuetusecd f atatomont
to ue IF False
Cerp gession)

tueSteatement-black esceautes skS

else

Skips ececutes
false Statement-block;

Nentod itaBomont
if Ccondition)

to be erecuted if codition is toue


lcode
I Ccondition 2)

lcode to be ececutec if condition2 is true

tbo Jnddos
F Ccondition)

Il code pe ececutal if condition istsue,

else if Ccondition 2)

II Cde be eoce cwtec if Condtion is tovej


else if Ccondition3)
is true;
code to be ececuted if cond ition3

else > Coptional)


conditio age false
Code b be ececuted if all

Switchh statenert
Switch Ceo paession)
Must evaluate to an int value

value 1:l statemert seajuence F int value = valuei


Case
Tnis eocecutes
beak
case value 2: l|statement seq uence int va lue = ualue 2
This ece utes.
boeaR
ptional)
default : /default statenert sajuence

t else elause of else -if ladde


simila
Suntaoc of Looping9 Statements

while Statement, entu


contKollecl loOp etntesnert Levent contiolled

while Cconditiorn is toue)

statement 1 a statement that wil


hasa eshould be
statement 2;
*
Make condition to eualuate tco flase. Ohetwise
ececuticns
Statement n; the loo will have intini te no. of

MOVe no. of time:


is ececuted zeo (oT)
The body of he loop

Statement) Lcounterr contolled


Fog Statement entou contolled looping
forCinitialization s
test.condition:increment /decremert)

e ecorutodd;
/statomand o

finite no. of time2s


body loop will be ececuteck in a
of he

Do...UWhile statement. ecit contiollecl Ioop

do

staternent i
statement 2

statemet n;
uwnile Ctest condition)
ody of he loop is ececutedl one ed move no. of kimes.
29/May
Teem wNork 1
LLa). uloito a Ct+ p9Logouam to Awap tuo Ja9iallon ubing
oLostonte uasialle..
#include< iostoeam
Usingnamespace std;
void eocchange Cint 3. int 8);
int main C)
{
int a.b;
Cout< "Enter two numbers:;
cin > a >b;
cout < " Before exchange a is« a < and b is b <<end
exchange Ca. b);
cout" After escchange 'a i s i a < and b i s <b <<endl
etuon O;

void eocchange Cint Sm, int an).

int temp
atemp -M3

o -tenP

Output:
Enter tuo nunbers: IO 20
efore exchasge 'a is io and b is 20
Aftee erdw ge o i s 20 aud 'b is 10
An4int8) thad duakos3
.Lb). ustito a Ctt Junchisni pouweN Gint
iAbg.oosaLoued wastinllo
tus idoja JasAiablar.idoand s i dndi chtibsOn
aD AASumtast, Lompukod fa C i A O t ' i
4Ka alONKa JOSitble i14,.
he ionultb' in
aAAgciaod mainC) to caul PhiA unctirors
i
ulsito Hhe
#include <iost@eam>
USing namespace std
int. int &);
void powe Cint,
int main C)

int a . b , ges;
numbesrs:";
cout< " Enter tuo
cin >a »b;
Power Ca. b, ces);
<<" gaísed to " Rb<<" is" <Ves <<endl;
Cout a
oetuon O;

intb, int result)


void Power Cint a.

esult1;
for Cint i-i; i<-bs i++).
esult sesult * a

Out put:
numbets:2 3
Ente two

2 1aiRd to 9 is 8
LCe). ulstiter io tunction oocchanga Cint6, int, int8) hat uaoA
valueD
rstnca Jasuallan to ucisally aocchange
Centainac in HhoLg UJEBAiallaa
oito he aDAOciotod main to gro9CiAg hio untion.
#include <iostmeam>
vsing namespace stdi
void Cycliceocchange Cint.inta .int8;
int main C)

int a.b,C;
cOut << "Ente hdeee oumbers: ";
cin > a y b>C
Cout Before ecchange a ="{<a<<, b- i b < C={kc<<endl;
cyclic ecchange Ca.b. c);
a<e" b="<<b <<"C"C Kendl
Cout After eocchange a ="
oetunO;

void cyclicecchange Cint Sm, int in,


int so)

int temp
temp n ;
n M
m O:
O temP;

Output:
Entev hsee numbegs: 12.3
befove ecchange a1 b-2 C
After ecchange a 2 b-9 C-1

You might also like