@@ -18,19 +18,19 @@ class Fraction {
1818 friend bool equal ( Fraction const & lhs, Fraction const & rhs ) {
1919 return (lhs.m_num ==rhs.m_num ) && (lhs.m_denom ==rhs.m_denom );
2020 }
21-
21+
2222 friend int compare ( Fraction const & lhs, Fraction const & rhs ) {
2323 int v1 = lhs.m_num * rhs.m_denom ;
2424 int v2 = rhs.m_num * lhs.m_denom ;
2525 if (v1 < v2) return -1 ;
2626 else if (v1 > v2) return 1 ;
2727 else return 0 ;
2828 }
29-
29+
3030 friend Fraction multiply ( Fraction const & lhs, Fraction const & rhs ) {
3131 return {lhs.m_num * rhs.m_num , lhs.m_denom * rhs.m_denom };
3232 }
33-
33+
3434 Fraction normalized () const {
3535 const int gcd = std::gcd (m_num, m_denom);
3636 return {m_num/gcd, m_denom/gcd};
@@ -51,23 +51,23 @@ class TestResultPrinter {
5151 void process (std::string const & what, bool passed) {
5252 std::cout << std::left << std::setw (m_width) << what << " : " << (passed ? " PASS" : " ** FAIL **" ) << ' \n ' ;
5353 }
54-
55- private:
54+
55+ private:
5656
5757 unsigned int m_width;
5858
5959};
6060
6161#define CHECK (printer,what ) printer.process(#what, what)
62-
62+
6363int main () {
6464
6565 // create a fraction with values 3 (which is 3/1) and 1/3
6666 std::cout<<std::endl;
6767 const Fraction three{3 };
6868 const Fraction third{1 ,3 };
6969 std::cout<<three.str ()<<' ' <<third.str ()<<' \n ' ;
70-
70+
7171 // equality
7272 std::cout<<std::endl;
7373 TestResultPrinter p1{40 };
@@ -80,14 +80,14 @@ int main() {
8080 CHECK (p1,equal (Fraction{1 ,3 },third));
8181 CHECK (p1,!equal (third,Fraction{2 ,6 }));
8282 CHECK (p1,equal (third,Fraction{2 ,6 }.normalized ()));
83-
83+
8484 // equivalence
8585 std::cout<<std::endl;
8686 TestResultPrinter p2{32 };
8787 CHECK (p2,compare (third,Fraction{2 ,6 })==0 );
8888 CHECK (p2,compare (third,Fraction{1 ,4 })>0 );
8989 CHECK (p2,compare (third,Fraction{2 ,4 })<0 );
90-
90+
9191 // multiply
9292 std::cout<<std::endl;
9393 TestResultPrinter p3{48 };
0 commit comments