jituTechnology

jituTechnology

>2.1: Write a complete program with definitions of the class Rational with its method defined inside

>/*Write a complete program with definitions of the class Rational with its method defined inside

Programmed by:
Name: Jitendra Kumar Yadav
Roll no.: 10116
Programmed on: 17th july,2011*/
#include <iostream.h>
#include <conio.h>
class Rational
{
private:
int n;
int d;
public:
void show()
{
cout << n<<“/”<<d<<endl;
}
void assign(int a,int b)
{
n= a;
d=b;
}
float convert()
{
return(float(n)/d);
}
void invert()
{
int temp;
temp = n;
n=d;
d= temp;
}
};
int main()
{
Rational r1,r2;
r1.assign(10,20);
r1.show();
r1.convert();
cout<<r1.convert()<<endl;
r1.invert();
r1.show();
r2.assign(30,40);
r2.show();
r2.convert();
cout<<r2.convert()<<endl;
r2.invert();
r2.show();
getch();
}
Output Sample:
10/20
0.5
20/10
30/40
0.75
40/3

No comments yet.

Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Connect with Me

GPO 8973 NPC 541; Kathmandu Nepal
Phone: +977 9851236800

Calendar

October 2019
S M T W T F S
« Jun    
 12345
6789101112
13141516171819
20212223242526
2728293031