As we know the 2nd equation of motion
#include<iostream>
#include<cmath>
using namespace std;
void main()
{
double vi, vf, a, s;
int eq;
cout << "Press 1 to solve for acceleration, 2 for distance, 3 for initial velocity and 4 for final velocity \n";
cin >> eq;
if (eq == 1)
{
cout << "Enter vf, vi and s \n";
cin >> vf >> vi >> s;
a = (pow(vf, 2) - pow(vi, 2)) / (2 * s);
cout << "Acceleration is " << a << endl;
}
else if (eq == 2)
{
cout << "Enter vf, vi and a \n";
cin >> vf >> vi >> a;
s = (pow(vf, 2) - pow(vi, 2)) / (2 * a);
cout << "Distance is " << s << endl;
}
else if (eq == 3)
{
cout << "Enter vf, s and a \n";
cin >> vf >> s >> a;
vi = sqrt(pow(vf, 2) - 2 * a*s);
cout << "Initial velocity is " << vi << endl;
}
else if (eq == 4)
{
cout << "Enter vi, s and a \n";
cin >> vi >> s >> a;
vf = sqrt(2 * a*s + pow(vi, 2));
cout << "Final velocity is " << vf << endl;
}
else
{
cout << "Please enter a valid integer to solve for the equations\n";
}
system("pause");
}
#include<iostream>
#include<cmath>
using namespace std;
void main()
{
double vi, vf, a, s;
int eq;
cout << "Press 1 to solve for acceleration, 2 for distance, 3 for initial velocity and 4 for final velocity \n";
cin >> eq;
if (eq == 1)
{
cout << "Enter vf, vi and s \n";
cin >> vf >> vi >> s;
a = (pow(vf, 2) - pow(vi, 2)) / (2 * s);
cout << "Acceleration is " << a << endl;
}
else if (eq == 2)
{
cout << "Enter vf, vi and a \n";
cin >> vf >> vi >> a;
s = (pow(vf, 2) - pow(vi, 2)) / (2 * a);
cout << "Distance is " << s << endl;
}
else if (eq == 3)
{
cout << "Enter vf, s and a \n";
cin >> vf >> s >> a;
vi = sqrt(pow(vf, 2) - 2 * a*s);
cout << "Initial velocity is " << vi << endl;
}
else if (eq == 4)
{
cout << "Enter vi, s and a \n";
cin >> vi >> s >> a;
vf = sqrt(2 * a*s + pow(vi, 2));
cout << "Final velocity is " << vf << endl;
}
else
{
cout << "Please enter a valid integer to solve for the equations\n";
}
system("pause");
}
Comments
Post a Comment