Note: 1) you must use multi-file approach to the program and 2) pre- and post-co
ID: 3815403 • Letter: N
Question
Note: 1) you must use multi-file approach to the program and 2) pre- and post-conditions are intentionally left incomplete and you are asked to fill in wherever applicable (refer to P6).
in Devc++
P8.1 Given the rational class interface below:
class rational {
public:
rational();
rational(int, int);
rational add(const rational &) const;
rational subtract(const rational &) const;
rational multiply(const rational &) const;
rational divide(const rational &) const;
bool lessThan(const rational &);
// Postcondition: returns true if calling object is smaller; returns false otherwise
void display();
// Postcondition: calling object is displayed as: 1/4 (not 2/8), -2/3 (not 2/-3), 0 (not 0/5), etc.
void input();
// displays prompt message "Enter values for numerator and denominator: "
// Postcondition: two values entered are read and stored in num and denom of the calling obj
private:
int GCD();
// Postcondition: returns the greatest common divisor between num and denom
int num;
int denom;
};
Implement two friend functions.
Implement all eight member functions.
Write a main() function to test all member functions.
Your program output should be similar to the following sample display. Notice that r2 is initialized by the second constructor to a value of 1/3 (i.e., 0) and r1 is declared with no parameter thus it is initialized to 0/1 by calling the default constructor. Your program output should be similar to the following sample display (except 0/1 should be displayed as 0)
1 is initialized by default constructor r1 0/1 r2 is initialized by the 2nd constructor: r2 1/3 Calling overloaded operator to reset r1 Enter values for numerator followed by denominator: 25 After reset r1 2/5 esting overloade arithmetic and insertion operatorExplanation / Answer
#include <iostream>
using namespace std;
class Test
{
public:
int main(int s){
cout << s << " ";
return 0;
}
int main(char *s) {
cout << s << endl;
return 0;
}
int main(int s ,int m)
{
cout << s << " " << m;
return 0;
}
};
int main()
{
Test obj;
obj.main(2);
obj.main("I love java");
obj.main(2, 4);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.