akosiraff

Download Rational CPP

Nov 5th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/rational-cpp/
  3. Define a class for rational numbers. A
  4. rational number is a number that can be
  5. represented as the quotient of two
  6. integers. For example, 1/2, 3/4, 64/2,
  7. and so forth are all rarional numbers.
  8. (By 1/2 and so on we mean that everyday
  9. fractions, not the integer division this
  10. expression would produce in a C++
  11. program.) Represent rational numbers as
  12. two values of type int, one for the
  13. numerator and one for the denominator.
  14. Call the class Rational. Include a
  15. constructor with two arguments that can
  16. be used to set the member variables of an
  17. object to any legitimate values. Also
  18. include a constructor that has only a
  19. single parameter of type int; call this
  20. single parameter wholeNumber and de?ne
  21. the constructor so that the object will
  22. be initialized to the rational number
  23. wholeNumber/1. Include a default
  24. constructor that initializes an object to
  25. 0 (that is, 0/1). Overload the input and
  26. output operators >> and <<. Numbers are
  27. to be input and output in the form 1/2,
  28. 15/32, 300/401, and so forth. Note that
  29. the numerator, the denominator, or both
  30. may contain a minus sign, so -1/2, 15/-
  31. 32, and -300/-401 are also possible
  32. inputs. Overload all the following
  33. operators so that they correctly apply to
  34. the type Rational: ==, <, <=, >, >=, +,
  35. -, *, and /. The main() should test your
  36. class and the functions.
  37. Hints: Two rational numbers a/b and c/d
  38. are equal if a*d equals c*b. If b and d
  39. are positive rational numbers, a/b is
  40. less than c/d provided a*d is less than
  41. c*b. You should include a function to
  42. normalize the values stored so that,
  43. after normalization, the deniminator is
  44. positive and the numerator and
  45. denominator are as small as possible. For
  46. example, after normalization 4/-8 would
  47. be represented the same as -1/2.
  48. Filename: rational.cpp
  49.  
  50. Download: http://solutionzip.com/downloads/rational-cpp/
Add Comment
Please, Sign In to add comment