[Cpp]
# Include <iostream>
Using namespace std;
Class Point
{
Private:
Int c_point;
Int m_point;
Char code;
Public:
Point ()
{
Code = '/';
}
Point (int n1, int n2)
{
C_point = n1;
M_point = n2;
Code = '/';
}
Void Output ()
{
If (m_point = 0) cout <"error ";
Else
If (m_point = 1) cout <c_point;
Else
Cout <"(" <c_point <code <m_point <")";
}
Int Big (int n1, int n2) // maximum common approx.
{
Int s = 1;
Int n = n1, m = n2;
While (s! = 0)
{
S = n1 % n2;
N1 = n2;
N2 = s;
}
If (n1! = 1 & n % n1 = 0 & m % n1 = 0)
Return n1;
Else
Return 0;
}
// Int Small_Multiple ()
Point operator + (Point B)
{
Point c;
Int n1, n2, s = 1;
N1 = m_point;
N2 = B. m_point;
If (n1 = n2)
{
C. c_point = c_point + B. c_point;
C. m_point = B. m_point;
}
Else
{
While (s! = 0)
{
S = n1 % n2;
N1 = n2;
N2 = s;
}
S = m_point * B. m_point/n1; // minimum public multiple
C. m_point = s;
C. c_point = c_point * (s/m_point) + B. c_point * (s/B. m_point );
}
Int t;
T = Big (c. c_point, c. m_point );
While (t! = 0)
{
C. c_point = c. c_point/t;
C. m_point = c. m_point/t;
T = Big (c. c_point, c. m_point );
}
Return c;
}
Point operator-(Point B)
{
Point c;
Int n1, n2, s = 1;
N1 = m_point;
N2 = B. m_point;
If (n1 = n2)
{
C. c_point = c_point-b.c_point;
C. m_point = B. m_point;
}
Else
{
While (s! = 0)
{
S = n1 % n2;
N1 = n2; // The maximum number of common appointments.
N2 = s;
}
S = m_point * B. m_point/n1; // minimum public multiple
C. m_point = s;
C. c_point = c_point * (s/m_point)-B. c_point * (s/B. m_point );
}
Int t;
T = Big (c. c_point, c. m_point );
While (t! = 0)
{
C. c_point = c. c_point/t;
C. m_point = c. m_point/t;
T = Big (c. c_point, c. m_point );
}
Return c;
}
Point operator * (Point B)
{
Point c;
C. c_point = c_point * B. c_point;
C. m_point = m_point * B. m_point;
Int t;
T = Big (c. c_point, c. m_point );
While (t! = 0)
{
C. c_point = c. c_point/t;
C. m_point = c. m_point/t;
T = Big (c. c_point, c. m_point );
}
Return c;
}
Point operator/(Point B)
{
Point c;
C. c_point = c_point * B. m_point;
C. m_point = m_point * B. c_point;
Int t;
T = Big (c. c_point, c. m_point );
While (t! = 0)
{
C. c_point = c. c_point/t;
C. m_point = c. m_point/t;
T = Big (c. c_point, c. m_point );
}
Return c;
}
};
Int main ()
{
Int n1, n2, m1, m2;
// Char a1, b1;
Cout <"enter two numerator numbers, with the denominator :";
// Cin> n1> a1> n2> m1> b1> m2;
Cin> n1> n2> m1> m2;
Point a (n1, n2), B (m1, m2 );
Cout <"the two scores are :";
A. Output (); cout <"";
B. Output (); cout <endl;
// Define a selection variable here. Select the operator to perform.
A. Output ();
Cout <"+ ";
B. Output ();
Cout <"= ";
Point c;
C = a + B;
C. Output ();
Cout <endl;
A. Output ();
Cout <"-";
B. Output ();
Cout <"= ";
C = a-B;
C. Output ();
Cout <endl;
A. Output ();
Cout <"*";
B. Output ();
Cout <"= ";
C = a * B;
C. Output ();
Cout <endl;
A. Output ();
Cout <"/";
B. Output ();
Cout <"= ";
C = a/B;
C. Output ();
Cout <endl;
Return 0;
}