Lab Manual IV (1).pdf on C++ Programming practice

ranaibrahim453 54 views 32 slides Apr 26, 2024
Slide 1
Slide 1 of 32
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32

About This Presentation

C++ Programming C++ involves writing code to solve problems or create software applications using the C++ programming language. C++ is a powerful and versatile programming language widely used for developing system software, application software, device drivers, embedded software, and much more.Her...


Slide Content

Lab Manual
IV

Pre and Post Practice
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=2;
++a;
a++;
a++;
cout<<a;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=2; b=2;
++b;
b++;
a++;
a++;
cout<<a<<b;
getch();
}
Output of
a
Output of
a
b

Pre and Post Practice
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
--a;
a--;
--a;
a--;
cout<<a;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=4; b=4;
--b;
b--;
a--;
a--;
cout<<a<<b;
getch();
}
Output of
a
Output of
a
b

Unary with cout

Use of Unary Operators with cout
Output as
4
5
Output as
4
5
6
Output as
4
5

Pre and Post Practice
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
cout<<--a;
cout<<--a;
cout<<a--;
cout<<a;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=4; b=4;
cout<<b--;
cout<<b--;
cout<<b--;
cout<<b;
getch();
}

Pre and Post Practice
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
cout<<--a;
cout<<a--;
cout<<a--;
cout<<a--;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=4; b=4;
cout<<b--;
cout<<b;
cout<<b--;
cout<<++b;
cout<<b;
getch();
}

Pre and Post Practice
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
--a;
a++;
cout<<a--;
cout<<--a;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=4; b=4;
b--;
b++;
b--;
cout<<++b;
cout<<b--;
cout<<b
getch();
}

Unary Practice with
Assignment statement

Use of Unary Operators into = statement
Output as
c=4
d=5
Output as
c=4
d=5
b=6
Output as
c=4
d=5
b=6

Use of Unary Operators in = statement
Output as
D=8
E=11
A=12
Output as
D=8
E=11
A=12
B=7

Pre and Post Practice
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
a = b++;
a = a+2;
++a;
b = a++;
cout<<a<<b;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
b = ++b;
a = a++;
a--;
b = --a;
cout<<a<<b++;
getch();
}

Pre and Post into Expression
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
c = a + ++a + ++a;
cout<<a<<c;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
c = ++b + --b + b++;
cout<<b<<c;
getch();
}

Pre and Post Expression
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=b=8;
a = b + ++a + ++b;
cout<<a<<b;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c; a=b=c=4;
a = ++a + --a + b++;
cout<<a<<b;
getch();
}

Pre and Post Expression
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c; a=b=c=4;
a = ++a + --a + b++;
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
a=2; b=1;
a = ++b + a++;
b= b + ++a

-

++b;
cout<<a<<b;
getch();
b = a--

+ a--

+ ++b + b;
cout<<a++<<b++;
cout<<a<<b;
getch();

Transform Expression into C++ Format
Mathematics Operator in C++ Example
+ + 2+4 =6
- - 4-2 = 2
X * 2*3 =6
/ 4/2 = 2
% (Percentage)% (Remaining) 10%2 = 0
3
2
3*3 or 3^3 or Power (3,2)2^3 = 8
Sqrt(9) Sqrt(9) =3

Transform Expression into C++ Format
Mathematics C++ Format
2+3+4 2+3+4
2-6-5 2-6-5
2X3 2*3
4/2
4%2 4%2
3
2
3*3
Sqrt(9)

Transform Expression into C++ Format
Mathematics Exp C++ Exp
2*3+4*10/2
3X6-3
3
+7 3*6-(3*3*3)+7
3
2
Power(3,2)
3*5-Sqrt (9) + (3^2)

Transform Expression into C++ Program
Mathematics C++
2*3+4*10/2
#include<iostream.h>
#include<conio.h>
voidmain ( ) {
inta,b,c,d,e, ans;
a=2; b=3; c=4; d=10; e=2;
ans= a*b+c*d/e;
cout<<“answer=“<<ans;
getch(); }

Transform Expression into C++ Program
Mathematics C++
3X6-3
3
+7 3*6-(3*3*3)+7
#include<iostream.h>
#include<conio.h>
voidmain ( ) {
inta,b,c,d,e, ans;
a=3; b=6; c=7;
exp= a*b-(a*a*a)+c;
cout<<“answer=“<<exp;
getch(); }

Transform Expression into C++ Program
Mathematics C++
3*5-Sqrt (9) + (3^2)
#include<iostream.h>
#include<conio.h>
#include<math.h>
voidmain ( ) {
inta,b,c,d,e, ans;
a=3; b=5; c=9; d=3; e=2;
exp= a*b-sqrt(c)+ (d^2);
cout<<“answer=“<<exp;
getch(); }

Operator Precedence
Read expression from Left to Right
1.( )
2 * , /, %
3 + , -

Solve Expression using Operator Precedence
Question Output
2 + 3 * 4 / 2+10 ?
( ( 2 + 3 ) * 4 / 2 + 10 ) ?
2 + 4 –3 * 2 / 2 -10 % 2 + power(2,5) ?
( ( (5*(2+4) %2 )+10 )-sqrt(49) ) ?
(3 * 2 / 2 -10 % 2 + (5^2) ) ?

Solve Binary Operators in Expression
Output as
5 Output as
-3

Variable as a Constant
Output as
a=5
p=5
Output as
a=5
p=5

Constant Variable Value not Change
DEVC++
Output as
a=5
p=5
DEVC++
Output as
-15.6

Input Value at Run Time Screen
Ifwewanttoinputvalueatruntime
cout<<a; cin>>a;
cout<<a<<b<<c; cin>>a>>b>>c;

Input at Runtime Screen
Using Turbo C++
a=5
Runtime screen
5//input value & press
enter
a=5
Runtime screen
10 //input value &
press enter
a=10

Message before Input at Runtime Screen

More Input at Runtime Screen

More Input at Runtime Screen

Enter value at run time
Tags