You are on page 1of 62

Prestige Institute of Engineering Research & Management

Object Oriented Programming & Methodology (Practical File)

S.no Date of Experiment Name of Experiment Page Date of Remark


No. Submission

1. Write a Program to find the area and


perimeter of rectangle.
2. Write a program to find the area and
circumference of circle.

3. Write a program to calculate the area of


square.
4. Write a program to find the
volume of cube
5. Write a Program to swap two number.

6. Write a program to calculate aggregate


and Percentage Marks.
7. Write a program to convert kmph to
miles per hour.

8. Write a program to calculate compound


interest.
9. Write a program which accepts amount
as integer and display total number of
Notes of Rs. 500, 100, 50, 20, 10, 5 and
1.

10. Write a program to get the


volume of sphere.
11. Write a program to print the
positive number entered by
user.
12. Write a Program to check
whether a number is +ve or –ve
13. Check Whether a number is Even or
odd.
14. Write a program to determine
Vote Casting eligibility by age.
15. Write a program to find the greatest
number

16. Write a program to calculate student


grade.
17. Write a program to print numbers
divisible by 3&5.

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

18. Write a program to check positive


negative zero using switch case.

19. Find maximum using switch case:

20. Create a calculator using switch.

21. Write a program to print


number of days in a month
using.
22. Write a program to find first n
natural numbers.
23. Find the sum of first 10 natural
numbers.
24. Find factorial of a number

25. Program to generate Multiplication


Table.
26. Program to calculate sum of first N even
numbers.

27. Program to add 2 numbers using


functions.
28. Write a program to find sqrt of a
number.
29. Program to find max between two
numbers.

30. Program To check even odd using


Functions.
31. Find Factorial Through Function.

32. Program to reverse a number using


functions.

33. Check A number is Armstrong or not.

34. Print first N Terms of Fibonacci


series.

35. Add numbers Through function


overloading.
36. Program To find Area of Rectangle ..
function overloading.

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

37. Write a program to show


function overriding
38. Write a program to show single level
inheritance.

39. Write a program to show multilevel


inheritance.

40. Write a c++ program to find


length of string.
41. Write A program to compare
two string in c++.
42. Write A program to Copy a string.

43. Write A program to


Concatenate a string.
44. Write a program in c++ to reverse a
string.

45. Virtual function

46. Abstract class

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

1. Write a Program to find the area and perimeter of rectangle.

2. Write a program to find the area and circumference of circle.

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

3. Write a program to calculate the area of square.

4. Write a program to find the volume of cube.

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

5. Write a Program to swap two number.

6. Write a program to calculate aggregate and Percentage Marks.


// Average marks & Percentage

#include<iostream>

using namespace std;

int main()

int x;

cout<<"Enter the number of subjects : ";

cin>>x;

float A[x],Sum=0,y;

for(int i=0;i<x;i++)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<endl<<"Enter subject marks : ";

cin>>y;

Sum+=y;

cout<<endl<<"Enter maximum marks : ";

cin>>y;

cout<<endl<<"The Aggregate Marks is : "<<Sum/x<<" and percentage is :


"<<(Sum/y*x)*100;

return 0;

Output ->>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number of subjects : 3

Enter subject marks : 19

Enter subject marks : 18

Enter subject marks : 17

Enter maximum marks : 20

The Aggregate Marks is : 18 and percentage is : 810

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

7. Write a program to convert kmph to miles per hour.

// kmph to miles per hour

#include<iostream>

using namespace std;

int main()

float kmph;

cout<<"Enter the value : ";

cin>>kmph;

cout<<endl<<"The value in miles per hour is "<<kmph*0.625;

return 0;

Output->>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the value : 123

The value in miles per hour is 76.875

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

8. Write a program to calculate compound interest.


// Compund interest

#include<iostream>

#include<math.h>

using namespace std;

int main()

float prin,rate,time,ci;

cout<<"Enter Principle Amount : ";

cin>>prin;

cout<<endl<<"Enter Rate : ";

cin>>rate;

cout<<endl<<"Enter Time : ";

cin>>time;

ci=prin*(pow((1+(rate/100)),time));

cout<<"The compound Interest is : "<<ci;

return 0;

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter Principle Amount : 1000

Enter Rate : 10

Enter Time : 3

The compound Interest is : 1331

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

9. Write a program which accepts amount as integer and display total


number of Notes of Rs. 500, 100, 50, 20, 10, 5 and 1.
//Write a program which accepts amount as integer and display total number of
Notes of Rs. 500, 100, 50, 20, 10, 5 and 1.

#include<iostream>

using namespace std;

int main()

long int a,t;

cout<<"Enter the total Amount : ";

cin>>t;

int A[]={500,100,50,20,10,5,1};

for(int i=0;i<7;i++)

a=(t/A[i]);

cout<<endl<<a<<" -> "<<A[i]<<" notes";

t=t-a*A[i];

return 0;

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the total Amount : 1234567

2469 -> 500 notes

0 -> 100 notes

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

1 -> 50 notes

0 -> 20 notes

1 -> 10 notes

1 -> 5 notes

2 -> 1 notes

10. Write a program to get the volume of sphere.


//Volume of sphere

#include<iostream>

using namespace std;

int main()

float radius;

cout<<"Enter the radius : ";

cin>>radius;

cout<<"The volume of sphere is : " <<4*(3.14*radius*radius*radius)/3;

return 0;

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the radius : 12.34

The volume of sphere is : 7867.09

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

11. Write a program to print the positive number entered by user.


//Print positive number

#include<iostream>

using namespace std;

int main()

int a;

cout<<"Enter the number : ";

cin>>a;

if(a>0)

cout<<a;

return 0;

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : 23

23

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : -12

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

12. Write a Program to check whether a number is +ve or –ve .


//Check whether a number is positive or negative

#include<iostream>

using namespace std;

int main()

int a;

cout<<"Enter the number : ";

cin>>a;

if(a>0)

cout<<a<<" -> is Positive ";

else if(a<0)

cout<<a<<" -> is Negative ";

else if(a==0)

cout<<a<<" -> is Zero ";

return 0;

OUTPUT ->>>

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : 23

23 -> is Positive

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : -12

-12 -> is Negative

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : 0

0 -> is Zero

13. Check Whether a number is Even or odd.


// Checking Even Or Odd

#include<iostream>

using namespace std;

int main()

int a;

cout<<"Enter the Number"<<endl;

cin>>a;

cout<<endl;

if(a%2==0)

cout<<"Number is even";

else

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<"Number is 0dd";

return 0;

OUTPUT ->>>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Number

13

Number is 0dd

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Number

12

Number is even

14. Write a program to determine Vote Casting eligibility by age.


// Checking Vote Casting age

#include<iostream>

using namespace std;

int main()

int age;

cout<<"Enter the age : ";

cin>>age;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

if(age>=18)

cout<<"Candidate is eligible to vote ";

else

cout<<"Candidate is not eligible to vote ";

return 0;

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the age : 19

Candidate is eligible to vote

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the age : 17

Candidate is not eligible to vote

15.Write a program to find the greatest number


#include<iostream>

using namespace std;

int main()

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

int a,max=1;

cout<<"How many numbers are to be entered : ";

cin>>a;

int A[a];

for(int i=0;i<a;i++)

cout<<endl<<"Enter the number : ";

cin>>A[i];

if(A[i]>max)

max=A[i];

cout<<endl<<"The greatest number among them is : "<<max;

return 0;

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

How many numbers are to be entered : 5

Enter the number : 1

Enter the number : 2

Enter the number : 3

Enter the number : 4

Enter the number : 5

The greatest number among them is : 5

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

16. Write a program to calculate student grade.


#include<iostream>

using namespace std;

int main()

int a;

cout<<"Enter the Marks scored out of 100 : ";

cin>>a;

if(a>=90)

cout<<endl<<" A+ Grade ";

else if(a>=80)

cout<<endl<<" A Grade ";

else if(a>=70)

cout<<endl<<" B+ Grade ";

else if(a>=60)

cout<<endl<<" B Grade ";

else if(a>=50)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<endl<<" C+ Grade ";

else if(a>=40)

cout<<endl<<" C Grade ";

else if(a>=33)

cout<<endl<<" D Grade ";

else

cout<<endl<<" F Grade ";

return 0;

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Marks scored out of 100 : 89

A Grade

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Marks scored out of 100 : 32


Name- Harsh Tiwari
Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

F Grade

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Marks scored out of 100 : 99

A+ Grade

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Marks scored out of 100 : 67

B Grade

17. Write a program to print numbers divisible by 3&5.


#include<iostream>

using namespace std;

int main()

int a;

cout<<"Enter the Range value : ";

cin>>a;

for(int i=1;i<a;i++)

if(i%3==0 && i%5==0)

cout<<endl<<i;

return 0;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Range value : 87

15

30

45

60

75

18. Write a program to check positive negative zero using switch case.
#include<iostream>

using namespace std;

int main()

int a;

cout<<"Enter the Number : ";

cin>>a;

if(a>0)

a=1;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

else if(a<0)

a=2;

switch(a)

case 1: cout<<endl<<"Positive number";

break;

case 2: cout<<endl<<"negative number";

break;

default: cout<<"Zero number";

return 0;

Output->>>

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Number : 23

Positive number

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Number : -23

negative number

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

Enter the Number : 0

Zero number

19. Find maximum using switch case:


#include<iostream>

using namespace std;

int main()

int a,b;

cout<<"Enter two numbers : ";

cin>>a>>b;

switch(a>b)

case 1:

cout<<a;

break;

case 0:

if(b>a)

cout<<b;

else{

cout<<"A is equal to B";

break;

default: cout<<"Error while input try again";

return 0;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

test.cpp: In function 'int main()':

test.cpp:8:11: warning: switch condition has boolean value [-Wswitch-bool]

switch(a>b)

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter two numbers : 2

20. Create a calculator using switch.


// CALCULATOR

#include<iostream>

using namespace std;

int main()

float a,b,d;

int c;

cout<<"Enter the two values "<<endl;

cin>>a>>b;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<"Select the operation"<<endl<<"1 for ADD"<<endl<<"2 for Sub"<<endl<<"3


for div"<<endl<<"4 for Mul"<<endl;

cin>>c;

switch(c)

{ case 1: d=a+b;

cout<<"The Sum is "<<d;

break;

case 2: d=a-b;

cout<<"The difference is "<<d;

break;

case 3:

if(b!=0)

d=a/b;

cout<<"The division is "<<d;

else{

cout<<"Invalid opperation";

break;

case 4:

d=a*b;

cout<<"The multiplication is "<<d;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

break;

default:

cout<<"Invalid option";

break;

return 0;

Output->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the two values

23

34

Select the operation

1 for ADD

2 for Sub

3 for div

4 for Mul

The Sum is 57

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the two values

12

23

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

Select the operation

1 for ADD

2 for Sub

3 for div

4 for Mul

The division is 0.521739

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the two values

12

34

Select the operation

1 for ADD

2 for Sub

3 for div

4 for Mul

The multiplication is 408

21. Write a program to print number of days in a month using.

#include<iostream>
using namespace std;
int main()
{
int a;
cout<<" Enter a choice for month : "
<<endl<<"1.Jan"<<endl<<"2.Feb"<<endl<<"3.Mar"<<endl<<"4.Apr"<<endl;
cout<<"5.May"<<endl<<"6.Jun"<<endl<<"7.Jul"<<endl<<"8.Aug"<<endl<<"9.Sep"<
<
endl;
cout<<"10.Oct"<<endl<<"11.Nov"<<endl<<"12.December";
cin>>a;
switch(a==1||a==3||a==5||a==7||a==8||a==10||a==12)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

{
case 1: cout<<" 31 Days ";
break;
case 0:
if(a==2)
{
cout<<" 28 Days ";
}
else{
cout<<" 30 Days";
}
break;
default:
cout<<"Wrong choice !!!";
break;
}
return 0;
}

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp


test.cpp: In function 'int main()':
test.cpp:10:11: warning: switch condition has boolean value [-Wswitch-bool]
switch(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
^
PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe
Enter a choice for month :
1.Jan
2.Feb
3.Mar
4.Apr
5.May
6.Jun
7.Jul
8.Aug
9.Sep
10.Oct
11.Nov
12.December

331 Days

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

22. Write a program to find first n natural numbers.


#include<iostream>

using namespace std;

int main()

int n;

cout<<"Enter the value of n : ";

cin>>n;

for(int i=1;i<=n;i++)

cout<<endl<<i;

return 0;

Output ->>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the value of n : 10

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

10

23. Find the sum of first 10 natural numbers.


#include<iostream>

using namespace std;

int main()

int n,sum=0;

cout<<"Enter the value of n : ";

cin>>n;

for(int i=1;i<=n;i++)

cout<<endl<<i;

sum+=i;

cout<<" sum = "<<sum;

return 0;

Output ->>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the value of n : 10

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

10 sum = 55

24. Find factorial of a number.


// FACTORIAL

#include <iostream>

using namespace std;

void factorial(int);

int f=1;

int main()

int a;

cout<<"Enter the number ";

cin>>a;

factorial(a);

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

return 0;

void factorial(int a)

f=f*a;

a-=1;

if(a==0)

cout<<"Factorial is "<<f;

else{

factorial(a);

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number 6

Factorial is 720

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

25. Program to generate Multiplication Table.


#include <iostream>

using namespace std;

int main()

{ int a;

cout<<"Enter the number : ";

cin>>a;

cout<<endl;

for(int i=1;i<11;i++){

cout<<" "<<a<<" X "<<i<<" = "<<a*i<<endl;

return 0;

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : 5

5 X 1 = 5

5 X 2 = 10

5 X 3 = 15

5 X 4 = 20

5 X 5 = 25

5 X 6 = 30

5 X 7 = 35

5 X 8 = 40

5 X 9 = 45

5 X 10 = 50

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

26. Program to calculate sum of first N even numbers.


#include <iostream>

using namespace std;

int main()

int a,i=0;

cout<<"Enter the number : ";

cin>>a;

cout<<a*(a+1);

return 0;

Output->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : 5

30

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number : 4

20

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

27. Program to add 2 numbers using functions.

#include <iostream>

using namespace std;

void add(int a,int b)

cout<<a+b;

int main()

{ int a,b;

cout<<"Enter two numbers : ";

cin>>a>>b;

add(a,b);

return 0;

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter two numbers : 5

11

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

28. Write a program to find sqrt of a number.

#include <iostream>

#include<math.h>

using namespace std;

int main()

int a;

cout<<"Enter Number : ";

cin>>a;

cout<<endl<<sqrt(a);

return 0;

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter Number : 625

25

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

29. Program to find max between two numbers.


#include <iostream>

using namespace std;

void maximum(int a, int b)

if(a>b)

cout<<a;

else if(b>a)

cout<<b;

else{

cout<<"Both are equal";

int main()

int a,b;

cout<<"Enter two Number : ";

cin>>a>>b;

maximum(a,b);

return 0;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter two Number : 12

344

344

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter two Number : 234

32

234

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter two Number : 2

Both are equal

30. Program To check even odd using Functions.


#include <iostream>

using namespace std;

void Check(int a)

if(a%2==0)

cout<<a<<" Is Even ";

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

else if(a%2!=0)

cout<<a<<" Is Odd ";

else{

cout<<" Invalid number ";

int main()

int a;

cout<<"Enter Number : ";

cin>>a;

Check(a);

return 0;

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter Number : 78

78 Is Even

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter Number : 23

23 Is Odd

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

31. Find Factorial Through Function.


// FACTORIAL

#include <iostream>

using namespace std;

void factorial(int);

int f=1;

int main()

int a;

cout<<"Enter the number ";

cin>>a;

factorial(a);

return 0;

void factorial(int a)

f=f*a;

a-=1;

if(a==0)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<"Factorial is "<<f;

else{

factorial(a);

Output ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the number 6

Factorial is 720

32. Program to reverse a number using functions.


#include <iostream>

using namespace std;

void Reverse(int x)

int r,b=0;

while(x>0)

r=x%10;

b=b*10+r;

x=x/10;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<endl<<" The Reverse of Number is "<<b;

int main()

int a;

cout<<"Enter Number : ";

cin>>a;

Reverse(a);

return 0;

OUTPUT->>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter Number : 123456

The Reverse of Number is 654321

33.Check A number is Armstrong or not.


#include<iostream>

#include<math.h>

using namespace std;

void Check(int x)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

int c=0,a,r,y,b=0;

a=x;

while(x>0)

b+=1;

x=x/10;

x=a;

while(x>0)

r=x%10;

c=c+pow(r,b);

x=x/10;

if(a==c)

cout<<"Number is Armstrong ";

else{

cout<<"Number is not Armstrong ";

int main()

int a;

cout<<"Enter Number : ";

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cin>>a;

Check(a);

return 0;

Output ->>>

Enter Number : 153

Number is Armstrong

34.Print first N Terms of Fibonacci series.


#include <iostream>

using namespace std;

void Display(int x)

{ int a=0,b=1,c;

for(int i=0;i<x;i++)

if(i==0)

cout<<a<<endl;

if(i==1)

{ cout<<b<<endl;

if(i>1)

{ c=a+b;

cout<<c<<endl;

a=b;

b=c;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

int main()

int a;

cout<<"Enter Number : ";

cin>>a;

cout<<endl;

Display(a);

return 0;

Output->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter Number : 7

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

35. Add numbers Through function overloading.


#include <iostream>

using namespace std;

void add(int x,int y)

cout<<x+y;

void add(float x, float y)

cout<<x+y;

int main()

int a,b;

float c,d;

cout<<"Enter two integer Number : ";

cin>>a>>b;

add(a,b);

cout<<endl;

cout<<"Enter two float Values : ";

cin>>c>>d;

add(c,d);

cout<<endl;

return 0;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter two integer Number : 12

23

35

Enter two float Values : 12.23

12.45

24.68

36. Program To find Area of Rectangle , Square , Triangle, Circle using function
overloading.

#include <iostream>

#include<math.h>

using namespace std;

void Area(float x)

cout<<x*x;

void Area(float x, float y)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<x*y;

void Area(double x)

cout<<x*x*3.14;

void Area(float x, float y, float z)

float s=x+y+z;

cout<<sqrt(s*(s-x)*(s-y)*(s-z));

int main()

float a,b,c;

double d;

cout<<"Enter the Side of Square : ";

cin>>a;

cout<<endl;

Area(a);

cout<<endl<<"Enter the Length of Rectangle : ";

cin>>a;

cout<<endl<<"Enter the width of Rectangle : ";

cin>>b;

cout<<endl;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

Area(a,b);

cout<<endl<<"Enter the radius of Circle : ";

cin>>d;

cout<<endl;

Area(d);

cout<<endl<<"Enter the Sides of triangle : ";

cin>>a>>b>>c;

cout<<endl;

Area(a,b,c);

return 0;

OUTPUT ->>>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter the Side of Square : 11.23

126.113

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

Enter the Length of Rectangle : 12.3

Enter the width of Rectangle : 23.4

287.82

Enter the radius of Circle : 34.2

3672.67

Enter the Sides of triangle : 1.2

12.3

12.4

342.716

37. Write a program to show function overriding.


#include <iostream>

using namespace std;

class A {

public:

void print() {

cout << "Base class Function" << endl;

};

class B : public A {

public:

void print() {

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout << "Derived class Function" << endl;

};

int main() {

B obj;

obj.print();

return 0;

OUTPUT ->>>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Derived class Function

38. Write a program to show single level inheritance.

#include<iostream>

using namespace std;

// Base class

class Number

public:

int add(int x, int y)

{ int h,j;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

h=x+y;

cout<<h<<endl;

cout<<"Do u want to multiply"<<endl<<"1 for yes "<<endl<<" 2 for


no"<<endl;

cin>>j;

return j;

};

// Derived class

class sum : public Number

public:

void multiply(int b, int k)

cout<<b*k;

};

int main() {

sum aj;

int a,b;

cout<<"Enter no a and b :"<<endl;

cin>>a>>b;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

int l=aj.add(a,b);

cout<<l<<endl;

if(l>=1)

aj.multiply(a,b);

return 0;

OUTPUT->>>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter no a and b :

Do u want to multiply

1 for yes

2 for no

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

10

39. Write a program to show multilevel inheritance.

#include<iostream>

using namespace std;

// SUPER class

class Number

public:

int add(int x, int y)

{ int h,j;

h=x+y;

cout<<h<<endl;

cout<<"Do u want to multiply"<<endl<<"1 for yes "<<endl<<" 2 for


no"<<endl;

cin>>j;

return j;

};

// SUB class

class sum : public Number

public:

void multiply(int b, int k)

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<b*k;

};

// SUB SUB Class

class sub : public sum

public:

void subtract(int a,int b)

cout<<endl<<"The result of subtraction is "<<a-b;

};

int main() {

sub aj;

int a,b;

cout<<"Enter no a and b :"<<endl;

cin>>a>>b;

int l=aj.add(a,b);

cout<<l<<endl;

if(l>=1)

aj.multiply(a,b);

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

aj.subtract(a,b);

return 0;

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Enter no a and b :

13

Do u want to multiply

1 for yes

2 for no

40

The result of subtraction is -3

40. Write a c++ program to find length of string.

#include<iostream>

#include<string.h>

using namespace std;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

int main()

char a[]="Harsh Tiwari";

Write a program to show mechanism of abstract class

cout<<"The length of string is "<<strlen(a);

return 0;

OUTPUT->>>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

The length of string is 12

41. Write A program to compare two string in c++.


#include<iostream>

#include<string.h>

using namespace std;

int main()

char a[]="Harsh Tiwari";

char b[]="Harsh Tiwari";

if(strcmp(a,b)==0)

cout<<"STRING IS SAME ";

else{
Name- Harsh Tiwari
Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

cout<<"TRY AGAIN STRING NOT MATCHED";

return 0;

OUTPUT->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

STRING IS SAME

42. Write A program to Copy a string.

#include<iostream>

#include<string.h>

using namespace std;

int main()

char a[]="Harsh Tiwari";

char b[]="";

strcpy(b,a);

cout<<"The value stored in B is same as A : "<<endl<<b;

return 0;

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

The value stored in B is same as A :

Harsh Tiwari

43. Write A program to Concatenate a string.


#include<iostream>

#include<string.h>

using namespace std;

int main()

char a[]="Harsh ";

char b[]="Tiwari";

cout<<"The Value in First is "<<a;

cout<<endl<<"The Value in Second is "<<b;

strcat(a,b);

cout<<endl<<"The value stored now in first after concatenation


is : "<<a;

return 0;

OUTPUT ->>>

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

The Value in First is Harsh

The Value in Second is Tiwari

The value stored now in first after concatenation is : Harsh


Tiwari

44.Write a program in c++ to reverse a string.


#include<iostream>

#include<string.h>

using namespace std;

int main()

char a[]="Harsh Tiwari";

cout<<"The Value before is "<<a;

int j=strlen(a);

for(int i=0;i<j;i++,j--)

a[i]=a[i]+a[j-1];

a[j-1]=a[i]-a[j-1];

a[i]=a[i]-a[j-1];

cout<<endl<<"The value stored now in first after Reverse


is : "<<a;

return 0;

OUTPUT->>>
Name- Harsh Tiwari
Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

PS C:\Users\Dell\Desktop\Coding\c++> g++ test.cpp

PS C:\Users\Dell\Desktop\Coding\c++> ./a.exe

The Value before is Harsh Tiwari

The value stored now in first after Reverse is : irawiT hsraH

45. Virtual function

#include <iostream>
using namespace std;

class Base {
public:
virtual void print() {
cout << "Base Function" << endl;
}
};

class Derived : public Base {


public:
void print() {
cout << "Derived Function" << endl;
}
};

int main() {
Derived derived1;

// pointer of Base type that points to derived1


Base* base1 = &derived1;

// calls member function of Derived class


base1->print();

return 0;

Name- Harsh Tiwari


Enrollment no – 0863AD201013
Prestige Institute of Engineering Research & Management
Object Oriented Programming & Methodology (Practical File)

Output->

Derived Function

46. Abstract function


#include<iostream>
using namespace std;

class Base
{
int x;
public:
virtual void fun() = 0;
int getX() { return x; }
};

// This class inherits from Base and implements fun()


class Derived: public Base
{
int y;
public:
void fun() { cout << "fun() called"; }
};

int main(void)
{
Derived d;
d.fun();
return 0;
}

Output->

fun() called

Name- Harsh Tiwari


Enrollment no – 0863AD201013

You might also like