stone.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // stone.cpp -- user-defined conversions
  2. // compile with stonewt.cpp
  3. #include <iostream>
  4. using std::cout;
  5. #include "stonewt.h"
  6. void display(const Stonewt & st, int n);
  7. int main()
  8. {
  9. Stonewt incognito = 275; // uses constructor to initialize
  10. Stonewt wolfe(285.7); // same as Stonewt wolfe = 285.7;
  11. Stonewt taft(21, 8);
  12. cout << "The celebrity weighed ";
  13. incognito.show_stn();
  14. cout << "The detective weighed ";
  15. wolfe.show_stn();
  16. cout << "The President weighed ";
  17. taft.show_lbs();
  18. incognito = 276.8; // uses constructor for conversion
  19. taft = 325; // same as taft = Stonewt(325);
  20. cout << "After dinner, the celebrity weighed ";
  21. incognito.show_stn();
  22. cout << "After dinner, the President weighed ";
  23. taft.show_lbs();
  24. display(taft, 2);
  25. cout << "The wrestler weighed even more.\n";
  26. display(422, 2);
  27. cout << "No stone left unearned\n";
  28. // std::cin.get();
  29. return 0;
  30. }
  31. void display(const Stonewt & st, int n)
  32. {
  33. for (int i = 0; i < n; i++)
  34. {
  35. cout << "Wow! ";
  36. st.show_stn();
  37. }
  38. }