Public feed
#886974
/*
Airplane Problem Solver.
"An airplane goes at X miles per hour with no wind resistance. It travels Y amount of miles with the wind and Z amount
of miles against the wind, in T amount of time. How fast was the wind blowing?"
We will need to transform this word problem into a quadratic equasion, and then solve it.
Quadratic Equasion is
x = -b +/- sqrt( (b)squared - 4(A)(C) ) / (2)(A)
We will get two answers for this, a negative and a positive answer. Since we cant have negative miles per hour,
the answer will be the positive one.
*/
//Quadratic Equasion formula variables
float A, B, C; //floats because they may have a decimal point. Integers are not needed.
float f1,f2,f3; //intermediate function
float X1, X2; //two possible outcomes.
#define BSQRD B * B // ^ is the XOR function, not Exponent. We learned this the hard way.
//d = rt, or t = d/r
float speed, distanceW, distanceA, time;
int iChoice; //lets make this a global variable
#define QUADPLUS -B + sqrt ( BSQRD - 4 * A * C )
#define QUADMINUS -B - sqrt ( BSQRD - 4 * A * C )
int Greeting()
{
printf("Welcome to the Algebra Solver! \n");
printf("Programmed by Paulius Trimakas \n");
printf("What would you like to do? \n");
printf("1. Solve a Quadratic Equasion\n");
printf("2. Solve the Airplane Problem\n");
cin >> iChoice;
return iChoice;
}
void QuadraticEquasion()
{
cout << "What is A?" << endl;
cin >> A;
cout << "What is B?" << endl;
cin >> B;
cout << "What is C?" << endl;
cin >> C;
f1 = QUADPLUS;
f2 = QUADMINUS;
f3 = (2 * A);
X1 = f1 / f3;
X2 = f2 / f3;
printf("Your answers are: \n");
printf("%f \n %f\n",X1, X2);
}
float GetAirplaneVars()
{
cout << "What is the speed of the airplane in still air?\n" << endl;
cin >> speed;
cout << "What is the distance against the wind?\n" << endl;
cin >> distanceA;
cout << "What is the distance with the wind?\n" << endl;
cin >> distanceW;
cout << "What is the total time traveled (in hours)\n" << endl;
cin >> time;
return speed, distanceA, distanceW, time;
}
void SolveAirplane()
{
//fuck it, we'll just do the actual distribution.
//our equasion is distanceA(speed + r) + distanceW(speed - r) = time (speed + r)(speed - r)
//we need to find r, so r = x (for quadratic equasion)
float temp1, temp2, temp3,temp4,temp5,temp6,temp7,temp8,temp9;
temp1 = distanceA * speed;
temp2 = distanceA; //distanceA + r
temp3 = distanceW * speed;
temp4 = -distanceW; //distanceW - r
temp5 = speed * speed;
temp6 = time * temp5;
temp7 = temp1 + temp3;
temp8 = temp2 + temp4;
temp9 = temp7 - temp6;
printf("Your quadratic equasion is: \n");
printf("%f x^2 + %f x + %f\n",time,temp8,temp9);
//And now, we go for the quadratic equasion itself to give us the speed of the wind.
A = time;
B = temp8;
C = temp9;
f1 = QUADPLUS;
f2 = QUADMINUS;
f3 = (2 * A);
X1 = f1 / f3;
X2 = f2 / f3;
printf("The speed of the wind is (choose the positive answer):\n");
printf("%f\n%f\n",X1,X2);
}
int _tmain(int argc, _TCHAR* argv[])
{
Greeting();
if(iChoice == 1)
{
QuadraticEquasion();
}
else if(iChoice == 2)
{
GetAirplaneVars();
SolveAirplane();
}
system("pause");
return 0;
}