Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FIIRST Run this program. Called “ifwhile1” online Note and understand The logic

ID: 3819873 • Letter: F

Question

FIIRST Run this program. Called “ifwhile1” online Note and understand The logic for input times = 150,30,0 ? Study output carefully! Hand in WITH OUTPUTS AND COMMENTS ON ALL OUTPUTS AS TO WHY YOU ARE GETTING THE VALUES YOU SEE NOTE: no comment no credit!

//Fun with selection and early introduction to repetition #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; } 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<<" "; } // Exit program. return 0; } FIIRST Run this program. Called “ifwhile1” online Note and understand The logic for input times = 150,30,0 ? Study output carefully! Hand in WITH OUTPUTS AND COMMENTS ON ALL OUTPUTS AS TO WHY YOU ARE GETTING THE VALUES YOU SEE NOTE: no comment no credit!

//Fun with selection and early introduction to repetition #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; } 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<<" "; } // Exit program. return 0; }

//Fun with selection and early introduction to repetition #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; } 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<<" "; } // Exit program. return 0; } //Fun with selection and early introduction to repetition #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; } 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<<" "; } // Exit program. return 0; }

Explanation / Answer

INPUT:150

// it satisfies the condition while (time < 200) as 150<200

//But it won't satisfy 150<100, so it won't enter into the if loop

1.time=time+20 // 150+20=170

2.cout << fixed << setprecision(3);// it is used to set the precision upto 3 decimals

3.And the velocity=0 m/s, acceleration=0 m^2/s //it won't enter into the if loop so it prints the default values only.

4.While loop repeats again as 170<200, again it will prints the time=190,v=0,a=0;

5.While loop repeats again as 190<200, again it will prints the time=210,v=0,a=0;

6. Next it will exit the loop, 210<200 false.

INPUT:30

// it satisfies the condition while (time < 200) as 30<200

//But it will satisfy 30<100, so it will enter into the if loop

1.while(30<200)
{
if(30<100)
velocity=0.00001* (30^3)-0.00488* (30^2)+ 0.75795*30 + 181.3566=199.973 m/s //as we fixed the setprecision(3);
Acceleration=3 - 0.000062*199.973*199.973=0.521 m/^2
Note: setw() is used set the width of the field
}
time=50;
velocity= 199.973 m/s;
acceleration=0.521 m/s^2;

2.while(50<200)
{
if(50<100)

// Again it will calculate the velocity and acceleration
}

The loop will repeat untill the conditions false.

INPUT:0

1.while(0<200)
{
if(0<100)
velocity=0.00001* (0^3)-0.00488* (0^2)+ 0.75795*0 + 181.3566=181.357 //as we fixed the setprecision(3);
Acceleration=3 - 0.000062*181.357*181.357=0.961 m/s^2
Note: setw() is used set the width of the field
}
time=20;
velocity= 181.357 m/s;
acceleration=0.961 m/s^2;

2.while(20<200)
{
if(20<100)

// Again it will calculate the velocity and acceleration
}

the loop will repeat untill the conditions false.