Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. /24.10.2017 - zad3
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. class truck;
  8.  
  9. class car {
  10. int passenger;
  11. int speed;
  12. public:
  13. car (int p, int s) {
  14. passenger = p;
  15. speed = s;
  16. }
  17.  
  18. int sp_greater(truck t);
  19. };
  20.  
  21. class truck {
  22. int weight;
  23. int speed;
  24. public:
  25. truck(int w, int s) {
  26. weight = w;
  27. speed = s;
  28. }
  29.  
  30. friend int car::sp_greater(truck t);
  31. };
  32.  
  33. int car::sp_greater(truck t) {
  34. return speed - t.speed;
  35. }
  36.  
  37. int main() {
  38. int t;
  39. car c1(6,55), c2(2,120);
  40. truck t1(10000,55), t2(20000,72);
  41.  
  42. cout << "Comparing c1 and t1: " << endl;
  43. t = c1.sp_greater(t1);
  44. if (t<0) cout << "Truck is faster";
  45. else if (t==0) cout << "Car and truck speed is the same";
  46. else cout << "Car is faster";
  47.  
  48. cout << endl;
  49. cout << endl;
  50.  
  51. cout << "Comparing c2 and t2: " << endl;
  52. t = c2.sp_greater(t2);
  53. if (t<0) cout << "Truck is faster";
  54. else if (t==0) cout << "Car and truck speed is the same";
  55. else cout << "Car is faster";
  56.  
  57. return 0;
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement