Hot Air Balloons - 6 (Program: "balplot")

This is the concluding exercise in the sequence on hot air balloons. In the previous exercise (balarray) we rewrote our program in terms of altitude and payload arrays, and wrote three array methods to do various tasks based on the arrays. In the final program we have replaced the function printarrays with a new function 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_payload, rather than just a printout of the two coordinate arrays.

Notice from the above flow diagram that the header file balplot.h is essentially a copy of the previous header file balarray.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 balplot.h in the main function as shown below:

 |
 #include <balplot.h>
 #include <plot.h>
 |

Consider a typical execution of balplot as follows (user input is shown in italics):

 get balloon data from file
enter the filename: bal500.data
data read from "bal500.data": 500, 50
################newballoon data:
First item: volume of the balloon [cu.m]
Second item: empty mass of the balloon [kg]
###########################################
balloon initialised as follows:
 balloon volume: 500[cu.m]
 balloon empty mass: 50[kg]
standard atmospheric conditions:
 temperature lapse rate: -0.0065[deg C/m]
 temperature at sea level: 15[deg C]
 standard pressure at sea level: 101325[Pa]
determine a sequence of (altitude,payload) points
enter low and high bounds of altitude [m]:
0 13000
altitude bounds are [0.0,13000.0] [m]
enter the number of points to evaluate
14
number of points is 14
WARNING! Altitude 12000.0[m] out of range
WARNING! Altitude 13000.0[m] out of range
plot width is 61 characters
balloon height[m] vs payload mass[kg]
         0.0    I                                                           *
      1000.0    I                                                         *
      2000.0    I                                                      *
      3000.0    I                                                   *
      4000.0    I                                               *
      5000.0    I                                           *
      6000.0    I                                       *
      7000.0    I                                   *
      8000.0    I                              *
      9000.0    I                          *
     10000.0    I                     *
     11000.0    I                 *
     12000.0    *
     13000.0    *
minimum value: 0.0, maximum value: 89.7
enter the filename: bal500.out
14 rows of data written to "bal500.out" file
find altitude as a function of required payload
enter the required payload [kg]:
80
required payload entered is 80.0[kg]
enter required accuracy in altitude [m]
1
required accuracy is 1.0[m]
WARNING! Altitude 13000.0[m] out of range
for a required payload of 80.0[kg]
altitude attained is 2486.3[m]

Thus we see that the major difference between this output and that of the previous exercise is the graphical display of the altitude versus payload 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 altitude.

Notice the following:

The source code should be in your home directory and named balplot.cpp, together with the relevant header file balplot.h. and the plot header file which you developed in lab8 plot.h

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:

bal500.data
0
13000
-5  {what in heaven's name is this number doing here?}
14
bal500.out
80
1