Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6. class Distance {
  7. private:
  8. int feet;
  9. double inches;
  10.  
  11. public:
  12. Distance(): feet(0), inches(0.0) { }
  13. Distance(int ft, double in): feet( ft ), inches( in ) { }
  14. ~Distance() { }
  15. public:
  16. void getDistance() {
  17. cout << "Iveskite pedas ir colius " << endl;
  18. cin >> feet >> inches;
  19. }
  20. void showDistance() {
  21. cout << " Pedos: " << feet << " Coliai: " << inches << endl;
  22. }
  23. void addDistance1(Distance d1, Distance d2) {
  24. inches=d1.inches+d2.inches;
  25. feet=d1.feet+d2.feet;
  26. if (inches >=12.0) {
  27. inches-=12;
  28. feet++;
  29. }
  30.  
  31. }
  32. Distance addDistance2(Distance d) {
  33. double in=inches+d.inches;
  34. int ft=feet+d.feet;
  35. if (inches >=12.) {
  36. in-=12;
  37. ft++;
  38. }
  39.  
  40. }
  41. };
  42. int main ()
  43. {
  44. Distance d1,d2;
  45. Distance d3(1, 2.5);
  46. d2.getDistance();
  47. cout << "d1 = ";
  48. d1.showDistance();
  49. cout << "d1 = ";
  50. d2.showDistance();
  51. cout << "d3 = ";
  52. d3.showDistance();
  53. d1=d2.addDistance2(d3);
  54. d1.addDistance1(d2,d3);
  55. cout << "d1 = ";
  56. d1.showDistance();
  57. cout << endl;
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement