#include<iostream> //Required for cin,cout #include<iomanip> //Required for setp
ID: 3805273 • Letter: #
Question
#include<iostream> //Required for cin,cout
#include<iomanip> //Required for setprecision(), setw()
#include<cmath> //Required for pow()
using namespace std;
int main()
{
// Declare objects.
double time, velocity, acceleration;
// Get time value from the keyboard.
cout << "Enter new time value in seconds: ";
cin >> time;
velocity = 0;
acceleration = 0;
// Compute velocity and acceleration.
while (time < 200)
{
if (time < 100)
{
velocity = 0.00001*pow(time, 3) - 0.00488*pow(time, 2)
+ 0.75795*time + 181.3566;
acceleration = 3 - 0.000062*velocity*velocity;
}
else
{
velocity = 2 * pow(time, 2) + ( pow(90*time, 0.5));
acceleration = 9 * velocity + log(time);
}
time = time + 20;
// Print time, velocity and acceleration.
cout << fixed << setprecision(3);
cout << "time= " << time << " sec" << endl;
cout << "Velocity = " << setw(10)
<< velocity << " m/s" << endl;
cout << "Acceleration = " << setw(14)
<< acceleration << "m/s^2" << endl << " ";
}
system("pause");
// Exit program.
return 0;
}
Explanation / Answer
on compiling your code it was giving the below error
error: 'system' was not declared in this scope
system("pause");
i have included the header file #include<cstdlib> and now it is running
#include<iostream> //Required for cin,cout
#include<iomanip> //Required for setprecision(), setw()
#include<cmath> //Required for pow()
#include<cstdlib>
using namespace std;
int main()
{
// Declare objects.
double time, velocity, acceleration;
// Get time value from the keyboard.
cout << "Enter new time value in seconds: ";
cin >> time;
velocity = 0;
acceleration = 0;
// Compute velocity and acceleration.
while (time < 200)
{
if (time < 100)
{
velocity = 0.00001*pow(time, 3) - 0.00488*pow(time, 2)
+ 0.75795*time + 181.3566;
acceleration = 3 - 0.000062*velocity*velocity;
}
else
{
velocity = 2 * pow(time, 2) + ( pow(90*time, 0.5));
acceleration = 9 * velocity + log(time);
}
time = time + 20;
// Print time, velocity and acceleration.
cout << fixed << setprecision(3);
cout << "time= " << time << " sec" << endl;
cout << "Velocity = " << setw(10)
<< velocity << " m/s" << endl;
cout << "Acceleration = " << setw(14)
<< acceleration << "m/s^2" << endl << " ";
}
system("pause");
// Exit program.
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.