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

Document

This class defines a rational number with private data members for the numerator and denominator. It includes constructors, member functions to get input, set data, and display the rational number. It also overloads operators like addition, subtraction, multiplication, and division for rational numbers, as well as prefix and postfix increment and decrement operators.

Uploaded by

sunnia munsif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Document

This class defines a rational number with private data members for the numerator and denominator. It includes constructors, member functions to get input, set data, and display the rational number. It also overloads operators like addition, subtraction, multiplication, and division for rational numbers, as well as prefix and postfix increment and decrement operators.

Uploaded by

sunnia munsif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Class rational

{ private:

int num;

int den;

public:

rational (): number(0),den(0)

{}

rational (into n,int d): number(n),den(d)

{}

void get_input()

{ cort<<”Enter num”;

cin>>num;

cort<<”Enter den”;

cin>>den;

void set_data()

{num= 9;

den=6;

Void display()

cout<<num<<”/”<<den<<endl;

rational operator+(rational r1)

{ rational r4;

r4.num=(num*r1.den)+(den*r1.num);

r4.den=den*r1.den;

return r4;

}
rational operator-(rational r1)

{ rational r4;

r4.num=(num*r1.den)-(den*r1.num);

r4.den=den*r1.den;

return r4;

rational operator*(rational r1)

{ rational r4;

r4.num=num*r1.num;

r4.den=den*r1.den;

return r4;

rational operator~(rational r1)

{ rational r4;

r4.num=r1.num;

r1.num=*r1.den;

r1.den=r4.num;

return r1;

rational operator++( )

{ ++num;

return num;

rational operator--( )

{ --num;

return num;

};

You might also like