Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the attached sample program. The student should start with the attached code. Please notice that main function is given as well as several test

Complete the attached sample program. The student should start with the attached code. Please notice that main function is given as well as several test functions. Before beginning the project, you should understand the main function and test functions first. When you implement the code, try to implement the functions that are required for test 1 first. Comment away the code in the main function so that only test 1 portion will be executed. After finishing test 1, then implement the functions that are required for test 2. This time, uncomment the code in the main function that tests test 2 ... and so on.

/* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include  #include  #include  using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e 0 // member functions int get_numerator() const; // return the numerator of the fraction int get_denominator() const; // return the denominator of the fraction void reduce(); // reduce this fraction to simplest form. For instance, // 2/4 will be reduced to 1/2 Fraction reciprocal() const; // return the reciprocal of this Fraction // friend functions friend Fraction operator +(const Fraction& f1, const Fraction& f2); // return the sum of f1 and f2, // the result is reduced friend Fraction operator -(const Fraction& f1, const Fraction& f2); // return the difference of f1 and f2, // the result is reduced friend Fraction operator *(const Fraction& f1, const Fraction& f2); // return the product of f1 and f2, // the result is reduced friend Fraction operator /(const Fraction& f1, const Fraction& f2); // return the quotient of f1 and f2, // the result is reduced friend Fraction operator -(const Fraction& f); // return the negation of f friend bool operator  (const Fraction& f1, const Fraction& f2); // return true if f1 is greater than f2. // False otherwise friend bool operator = (const Fraction& f1, const Fraction& f2); // return true if f1 is greater or equal to f2. // False otherwise friend bool operator == (const Fraction& f1, const Fraction& f2); // return true if f1 is equal to f2. // False otherwise friend bool operator != (const Fraction& f1, const Fraction& f2); // return true if f1 is not equal to f2. // False otherwise friend istream& operator >> (istream& in, Fraction& f); // input f in the form of a/b, where b cannot be zero. Also, // if b is negative, the Fraction will change b to be positive. // So, again, 1/-3 will be changed to -1/3 friend ostream& operator , =, > and  0) cout  1.4) cout  0) cout  1.4) cout  0) cout  2.9) cout  if(f1 > f2 || !(f2 > f1) || f1 > f3) { cout  operator was wrong. "; result -= 0.5; } // Test == if(f1 == f2 || !(f1 == f3) || f2 == f3) { cout = if(f1 >= f2 || !(f1 >= f3) || !(f2 >= f3)) { cout  0) cout  1.9) cout > f; if(f.get_denominator() != 4 || f.get_numerator() != -3) { cout > choice; if(choice != 'y' && choice != 'Y') { cout  0) cout  0.9) cout image text in transcribedimage text in transcribed
(CSCI 361) Help on Project Three To finish project three, student should implement it step by step. In each step, comment away the testing code and test functions that are related to later tests. For example, when write code for the functions that are tested by test1, you may comment away all code that calls test2, test 3 , test 4 , and test 5 function. You may also comment away the implementation of test2, test3, test 4 , and test 5 function Step One: Implement all functions that are tested in test1. These functions are three constructors and two get functions. The difficult part in this step is to ensure that the denominator is always positive. Fraction: : Fraction( int a, int b) \{ num =a; den =b; if ( den

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions

Question

My opinions/suggestions are valued.

Answered: 1 week ago