Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /24.10.2017 - zad3
- #include <iostream>
- #include <math.h>
- using namespace std;
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- class truck;
- class car {
- int passenger;
- int speed;
- public:
- car (int p, int s) {
- passenger = p;
- speed = s;
- }
- int sp_greater(truck t);
- };
- class truck {
- int weight;
- int speed;
- public:
- truck(int w, int s) {
- weight = w;
- speed = s;
- }
- friend int car::sp_greater(truck t);
- };
- int car::sp_greater(truck t) {
- return speed - t.speed;
- }
- int main() {
- int t;
- car c1(6,55), c2(2,120);
- truck t1(10000,55), t2(20000,72);
- cout << "Comparing c1 and t1: " << endl;
- t = c1.sp_greater(t1);
- if (t<0) cout << "Truck is faster";
- else if (t==0) cout << "Car and truck speed is the same";
- else cout << "Car is faster";
- cout << endl;
- cout << endl;
- cout << "Comparing c2 and t2: " << endl;
- t = c2.sp_greater(t2);
- if (t<0) cout << "Truck is faster";
- else if (t==0) cout << "Car and truck speed is the same";
- else cout << "Car is faster";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement