Here is the assignment that I have to write out and a sample output of what it s
ID: 3623452 • Letter: H
Question
Here is the assignment that I have to write out and a sample output of what it should look like:
For this assignment, write a program that will analyze the data from a physics experiment.
The data consists of a series of position measurements for a moving object. The position measurements will be entered by the user of the program as they are continually prompted. Each of the position measurements that the user enters will have been recorded at uniform time intervals. This time interval will be entered by the user when the program begins and will be followed by the series of position measurements. Each position should be greater than or equal to the previous position because the object is either moving in one direction or still, but never moving backwards. Therefore a negative position measurement will be used to signal the end of the user's data for the run of the program.
After each of the position measurements has been entered, calculate and display the following:
the average velocity for the time interval
the average acceleration for the time interval
Calculations
Use the following formulas for the calculations:
change of position = current position - previous position
change of velocity = current velocity - previous velocity
average velocity = change of position / time interval
average acceleration = change of velocity / time interval
Sample Output:
Motion Analysis
Enter the uniform time interval in seconds: 2.5
Enter a position in feet (negative value to quit): 2
Average velocity (this interval): 0.80 feet/second
Average acceleration: 0.32 feet/second/second
Enter a position in feet (negative value to quit): 5
Average velocity (this interval): 1.20 feet/second
Average acceleration: 0.16 feet/second/second
Enter a position in feet (negative value to quit): 4
Invalid value: 4 is less than the current position of 5. Try again.
Enter a position in feet (negative value to quit): 12
Average velocity (this interval): 2.80 feet/second
Average acceleration: 0.64 feet/second/second
Enter a position in feet (negative value to quit): -1
Here is what I have so far. But for some reason, it isn't working properly and I can't figure out how to put the other loop in that if they enter the value incorrectly the first time, they can enter it a second time. But here it is:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
/*
Get the time interval, position in feet,
calculate the average velocity and the
average acceleration, and then display
the results.
*/
// Declaring all variables
int changePos, currentPos, prevPos, changeVel, currentVel,
prevVel;
double avgVel, avgAcc, timeInt;
int startPos = 0;
int startVel = 0;
// Start to display the results
cout << "Motion Analysis ";
// Gathering the time interval
cout << "Enter the uniform time interval in seconds: ";
cin >> timeInt;
// Gathering the position in feet and beginning the loop
while (currentPos > 0)
{
cout << " Enter a position in feet (negative value to quit): ";
cin >> currentPos;
cout << " Average velocity (this interval): " << (double)changePos/timeInt;
cout << " Average acceleration: " << (double)changeVel/timeInt << endl;
}
// Formulas to be used for calculations
changePos = currentPos - prevPos;
changeVel = currentVel - prevVel;
avgVel = changePos/timeInt;
avgAcc = changeVel/timeInt;
system("pause");
return 0;
}
PLEASE HELP!!!
Explanation / Answer
here you go, let me know if it doesnt work or you have any questions. #include using namespace std; int main() { double time; int curPosition, prevPosition = 0, changePos; double velocity, acceleration = 0, changeV, avgA; double prevVelocity = 0, avgV = 0; cout > time; cout > curPosition; while (curPosition > 0) { changePos = curPosition - prevPosition; avgV = changePos/time; changeV = avgV - prevVelocity; prevVelocity = avgV; avgA = changeV/time; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.