1
0

stonewt1.cpp 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // stonewt1.cpp -- Stonewt class methods + conversion functions
  2. #include <iostream>
  3. using std::cout;
  4. #include "stonewt1.h"
  5. // construct Stonewt object from double value
  6. Stonewt::Stonewt(double lbs)
  7. {
  8. stone = int (lbs) / Lbs_per_stn; // integer division
  9. pds_left = int (lbs) % Lbs_per_stn + lbs - int(lbs);
  10. pounds = lbs;
  11. }
  12. // construct Stonewt object from stone, double values
  13. Stonewt::Stonewt(int stn, double lbs)
  14. {
  15. stone = stn;
  16. pds_left = lbs;
  17. pounds = stn * Lbs_per_stn +lbs;
  18. }
  19. Stonewt::Stonewt() // default constructor, wt = 0
  20. {
  21. stone = pounds = pds_left = 0;
  22. }
  23. Stonewt::~Stonewt() // destructor
  24. {
  25. }
  26. // show weight in stones
  27. void Stonewt::show_stn() const
  28. {
  29. cout << stone << " stone, " << pds_left << " pounds\n";
  30. }
  31. // show weight in pounds
  32. void Stonewt::show_lbs() const
  33. {
  34. cout << pounds << " pounds\n";
  35. }
  36. // conversion functions
  37. Stonewt::operator int() const
  38. {
  39. return int (pounds + 0.5);
  40. }
  41. Stonewt::operator double()const
  42. {
  43. return pounds;
  44. }