Difference: Lab9 (5 vs. 6)

Revision 62015-11-19 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 9

Due: Nov 20, 11:55pm

Line: 20 to 20
  A principle of abstract data type construction is that constructors must be present to create objects with any legal values. You should provide constructors to make objects out of pairs of int values; this is a constructor with two int parameters. Since every int is also a rational number, as in 2/1 or 17/1, you should provide a constructor with a single int parameter.
Changed:
<
<
Provide member functions input and output that take an istream and ostream argument, respectively, and fetch or write rational numbers in the form 2/3 or 37/51 to or from the keyboard (and to or from a file).
>
>
(Optional to use files, worth extra credit) Provide member functions input and output that take an istream and ostream argument, respectively, and fetch or write rational numbers in the form 2/3 or 37/51 to or from the keyboard (and to or from a file). Ask the users to enter a filename if they want the program to read/write from a file. If they don't provide a filename, use cin and cout.
  Provide member functions add, sub, mul, and div that return a rational value. Provide a function less that returns a bool value. These functions should do the operation suggested by the name. Provide a member function neg that has no parameters and returns the negative of the calling object. Provide a main function that uses your class implementation as seens below. The following formulas will be useful in defining functions.
Line: 45 to 45
 
  • Rational divide(Rational x);
  • bool less(Rational x);
  • bool equals(Rational x);
Changed:
<
<
  • void input(); // Inputs into this rational
  • void output(x); // Outputs this rational
>
>
  • void input(ifstream s); // Inputs into this rational
  • void output(x, ofstream s); // Outputs this rational
 
  • int getNum(); // Get the numerator
  • int getDem(); // Get denominator

Program Operation

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback