0% found this document useful (0 votes)
10 views

5,6 Practical Program Dsa and Oop

Uploaded by

wafflerick69
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)
10 views

5,6 Practical Program Dsa and Oop

Uploaded by

wafflerick69
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/ 9

Experiment No.

05
Name :Deepak Prakash Deore
Roll Number : 57.
Batch : S4.
Date Of Performance : / / 2024.

Problem Statement : A phone number, such as (212) 767-8900 can be thought


of as having three parts: the area code (212), the exchange (767) and the number
(8900). Write a program that uses a structure to store these three parts of a phone
number separately. Call the structure phone. Create two structure variables of
type phone. Initialize one and have the user input a number for the other one.
Then display both numbers.

Input :
#include<bits/stdc++.h> using
namespace std; struct phone
{
int area_code,exchange,number;
};
int main()
{
phone p1,p2;
p2={212,767,8900};

cout<<"\n Enter area code, exchange and number :";

cin>>p1.area_code>>p1.exchange>>p1.number;

cout<<endl;
cout<<"My number is "<<"("<<p2.area_code<<")"<<p2.exchange<<"-

"<<p2.number;

cout<<endl;

cout<<"Your number is "<<"("<<p1.area_code<<")"<<p1.exchange<<"-

"<<p1.number;
return 0;
}

Output :
Enter area code, exchange and number :253
326
9467

My number is (212)767-8900
Your number is (253)326-9467
Experiment No. 0
Name :Deepak Prakash Deore
Roll Number : 57.
Batch : S4.
Date Of Performance : / / 2024.

#include<stdio.h>
void main()
{
int a[10],n,i,j,temp;
clrscr();
printf("\nEnter size of an array=");
scanf("%d",&n);
printf("\nEnter array elements=");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(i=0;i<n;i++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("Sorted array=\n");
for(i=0;i<n;i++)
{
printf("\n%d\n",a[i]);
}
}

//output
Enter size of an array=5
Enter array elements=36
42
84
63
69
Sorted array=
36
42
63
69
84
Experiment No. 0
Name :Deepak Prakash Deore
Roll Number : 57.
Batch : S4.
Date Of Performance : / / 2024.

#include<stdio.h>
void main()
{
int a[10],n,i,j,temp;
printf("Enter Size Of Array = ");
scanf("%d",&n);
printf("\nEnter Array Elements = ");
for(i=0;i<n;i++)
{
scanf("%d", &a[i]);
}
for(i=1;i<n;i++)
{
temp=a[i];
j=i-1;
while(temp<a[j] && j>=0)
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("Sorted Arra y=\n");
for(i=0;i<n;i++)
{
printf("\n%d", a[i]);
}
}

Output :
Enter Size Of Array = 5
Enter Array Elements = 36
15
48
92
34
Sorted Array =
15
34
36
48
92
Experiment No. 06
Name :Deepak Prakash Deore
Roll Number : 57.
Batch : S4.
Date Of Performance : / / 2024.

Problem Statement : Create two classes DM and DB which store the value of distances. DM
stores distances in meters and centimeters and DB in feet and inches. Write a program that
can read values for the class objects and add one object of DM with another object of DB.
Use a friend function to carry out the addition operation. The object that stores the results
maybe a DM object or DB object, depending on the units in which the results are required.
The display should be in the format of feet and inches or meters and centimeters depending
on the object on display.

Input :
#include<iostream>
using namespace std;
class DB;
class DM
{
float m,cm;
public:
void getdata()
{
cout<<"\nEnter meter value :";
cin>>m;
cout<<"\nEnter centimeter value :";
cin>>cm;
}
friend float sum(DM a,DB b);
};
class DB
{
float ft,in;
public:
void getdata()
{
cout<<"\nEnter feet value :";
cin>>ft;
cout<<"\nEnter inch value :";
cin>>in;
}
friend float sum(DM a,DB b);
};
float sum(DM a,DB b)
{
float x,y,z;
x=(a.m+(a.cm/100));
y=(b.ft+(b.in/12));
z=(x+(y*0.304));
return z;
}
int main()
{
DM a;
DB b;
cout<<"\nEnter the value in meter and centimeter :";
a.getdata();
cout<<"\nEnter the value in feet and inches :";
b.getdata();
cout<<"\nThe summed value in meter is :"<<sum(a,b);
return 0;
}

Output :
Enter the value in meter and centimeter :
Enter meter value :65
Enter centimeter value :32
Enter the value in feet and inches :
Enter feet value :53
Enter inch value :51
The summed value in meter is :82.724

You might also like