0% found this document useful (0 votes)
6 views2 pages

Exp 3

Uploaded by

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

Exp 3

Uploaded by

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

// Program to print the reciprocal and ratio.

Program:

#include<iostream.h>
#include<conio.h>
class ratio
{
private :
int num,den;
public:
void assign(int n, int d)
{
num=n;
den=d;
}
double convert()
{
return (double)num/den;
}
void invert()
{
int temp;

temp=num;
num=den;
den=temp;
}
void print()
{
cout<<num <<"/" << den;
}

};
void main()
{
clrscr();
ratio r;
int x,y;
cout<<"Enter numerator = ";
cin>>x;
cout<<"\n Enter denometor = ";
cin>>y;
r.assign(x,y);
cout<<"\n The given ratio is ";
r.print();
cout<<"="<<r.convert();
r.invert();
cout<<"\n Reciprocal is ";
r.print();
cout<<"="<<r.convert();
getch();
}

*************************************************************************************

Output:

Enter numerator = 2
Enter denometor = 3

The given ratio is 2/3=0.666667


Reciprocal is 3/2=1.5

You might also like