Question: Modify Listing 11.15 so that instead of reporting the results of a single trial for a particular target/step combination, it reports the highest, lowest, and

Modify Listing 11.15 so that instead of reporting the results of a single trial for a particular target/step combination, it reports the highest, lowest, and average number of steps for N trials, where N is an integer entered by the user.

Listing 11.15 randwalk.cpp // randwalk.cpp // compile with the vect.cpp file #include

Listing 11.15 randwalk.cpp // randwalk.cpp // compile with the vect.cpp file #include #include #include #include "vect.h" int main() { } using the Vector class using namespace std; using VECTOR::Vector; srand(time (0)); double direction; Tector step; Vector result (0.0, 0.0); unsigned long steps = 0; double target; double dstep; // rand (), srand() prototypes // time () prototype cout < < "Enter target distance (q to quit): ; while (cin >> target) { // seed random-number generator cout < < "Enter step length: "; if (! (cin >> dstep)) break; while (result.magval() < target) { direction rand() & 360; step.reset (dstep, direction, Vector::POL); result result + step; steps++; } cout < < "After " < < steps < < " steps, the subject "has the following location: "; cout < < result < < endl; result.polar_mode (); cout < < or " < < result < < endl; cout < < "Average outward distance per step < < result.magval() /steps < < endl; } cout < < "Bye! "; cin.clear(); return 0; steps = 0; result.reset (0.0, 0.0); cout < < "Enter target distance (q to quit): "; while (cin.get () != ' ') continue; 11 11

Step by Step Solution

3.41 Rating (170 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

include include include include include vecth using namespace std using VECTORVector int main srandt... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction Java Program Questions!