Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- double xArr[3];
- double x1, x2, x3, v1, v2, v3, time12, time23, time13;
- cout << "Input x1: ";
- cin >> x1;
- cout << "Input speed of x1: ";
- cin >> v1;
- cout << "Input x2: ";
- cin >> x2;
- cout << "Input speed of x2: ";
- cin >> v2;
- cout << "Input x3: ";
- cin >> x3;
- cout << "Input speed of x3: ";
- cin >> v3;
- xArr[0] = min(min(x1, x2), x3);
- xArr[1] = x1 + x2 + x3 - min(min(x1, x2), x3) - max(max(x1, x2), x3);
- xArr[2] = max(max(x1, x2), x3);
- time12 = (xArr[1] - xArr[0]) / (v1 - v2);
- time13 = (xArr[2] - xArr[0]) / (v1 - v3);
- time23 = (xArr[2] - xArr[1]) / (v2 - v3);
- if (time12 >= 0)
- cout << "Points x1 and x2 intersect at time: " << time12 << endl;
- else
- cout << "Points x1 and x2 do not intersect!\n";
- if (time13 >= 0)
- cout << "Points x1 and x3 intersect at time: " << time13 << endl;
- else
- cout << "Points x1 and x3 do not intersect!\n";
- if (time23 >= 0)
- cout << "Points x2 and x3 intersect at time: " << time23 << endl;
- else
- cout << "Points x2 and x3 do not intersect!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement