Human Powered Vehicles - 6 (Program: "hpvplot")
The final program in our sequence on Human Powered Vehicles

This is the concluding exercise in the sequence on human powered vehicles. In the previous exercise (hpvarray) we rewrote our program in terms of velocity and power arrays, and wrote three new array methods to do various tasks based on these arrays. In the final program we will replace the method printarrays with a new method plotarrays in the new class Plot, as shown in the structure diagram below. This seemingly small change in the somewhat complex structure is significant. It allows us to get a visual appreciation of the nonlinear function find_power as a function of elapsed time rather than just a printout of the respective coordinate arrays.

Notice from the above flow diagram that the header file hpvplot.h is essentially a copy of the previous header file hpvarray.h with the only modification being that method printarrays has been removed. This method plotarrays is a method of the new class Plot that we developed independently in lab 9 in the header file plot.h. In order to invoke plotarrays this header file should also be included together with the header file hpvplot.h in the main function as shown below:

 |
 #include "hpvplot.h"
 #include "plot.h"
 |

A typical execution of hpvplot follows (user input is shown in italics):

 get basic bike data from file
enter the filename: Twike.data
 getting bike data from the "Twike.data" file
data read: 400.000, 0.230, 0.005
=============================
TWIKE data, Switzerland, 1995.
total mass = 400.0 kg
CdA = 0.23 sq.m
Cr = 0.005
=============================
hpv initialised as follows:
 mass (hpv + rider): 95.000[kg]
 cda (coeff.drag*area): 0.046[sq.m]
 cr (coeff.rolling resist): 0.005
local conditions initialised as follws:
 gravity acceleration: 9.807[m/s/s]
 air density: 1.180[kg/cu.m]
 wind velocity: 0.000[mph]
 slope: 0.000
-----------------------------------------------------
 enter wind velocity [mph] - positive for headwind
0
 value entered is 0.000[mph]
 enter slope (height/distance) - positive for uphill
0
 value entered is 0.000
new local conditions:
 wind velocity = 0.000[mph]
 slope = 0.000
enter low and high velocity bounds [mph]
0 60
values entered are [0.000,60.000] [mph]
enter the number of points to evaluate
21
number of points is 21
plot width is 61 characters
hpv power[watts] vs velocity[mph]
       0.000    *
       3.000    I*
       6.000    I*
       9.000    I *
      12.000    I *
      15.000    I  *
      18.000    I   *
      21.000    I     *
      24.000    I      *
      27.000    I        *
      30.000    I          *
      33.000    I             *
      36.000    I                *
      39.000    I                   *
      42.000    I                       *
      45.000    I                            *
      48.000    I                                 *
      51.000    I                                      *
      54.000    I                                            *
      57.000    I                                                   *
      60.000    I                                                           *
minimum value: 0.000, maximum value: 3096.314
save [velocity/power] coordinate data on file
enter the filename: Twike.out
21 rows of data written to "Twike.out" file
find velocity as a function of applied power
enter applied power [watts]
1500
enter required accuracy in velocity [mph]
0.1
required accuracy is 0.100[mph]
for applied power of 1500.000[watts]
steady state velocity is 45.264[mph]

Thus we see that the major difference between this output and that of the previous exercise is the graphical display of the velocity versus power data, rather than the two columns of values. This is a significant difference, and allows a quick visualization of the nonlinear function. In particular, the user can instantly see if there is a single root within the specified bounds of velocity.

Notice the following:

The source code should be in your home directory and named hpvplot.cpp, together with the relevant header files hpvplot.h and plot.h at 10:00 a.m. of the due date.

Note that the sequence with which data is entered is important, since your programs are tested with a data file. The following is a typical data sequence (used in the example above). Be sure that your program will operate with the data as shown:

Twike.data
0
0
0
60
-5  {what in heaven's name is this number doing here?}
21
Twike.out
1500
0.1