//****************************************************************** // HEADER FILE for program hpvloop.cpp * // FILENAME: hpvloop.h * // PROGRAMMER: Dr.Iz (Urieli) * // DATE: 01/17/04 (updated 10/5/07) * //****************************************************************** using namespace std; class HPvehicle { // human powered vehicle private: float cda, // [sq.m] - (coefficient of drag * frontal area) cr, // [-] - coefficient of rolling resistance mass; // [kg] - mass of hpv + rider public: float g, // [m/s/s] - acceleration due to gravity density, // [kg/cu.m] - air density wind_mph, // [mph] - wind velocity (positive for headwind) slope; // [-] - height/distance - (positive for uphill) //=============================================================== HPvehicle( // Constructor initialization float mass0 = 92.0, // [kg] - 15 kg bike, 77 kg rider typical float cda0 = 0.4, // [sq.m] - upright city bicycle float cr0 = 0.005) // [-] - high pressure tires on flat road { mass = mass0; cda = cda0; cr = cr0; cout << "hpv initialised as follows:\n" << " mass (hpv + rider): " << mass << "[kg]\n" << " cda (coeff.drag*area): " << cda << "[sq.m]\n" << " cr (coeff.rolling resist): " << cr << endl; g = 9.807; // [m/s/s] - standard acceleration due to gravity density = 1.18; // [kg/cu.m] - sea level standard air density wind_mph = slope = 0; cout << "local conditions initialised as follws:\n" << " gravity acceleration: " << g << "[m/s/s]\n" << " air density: " << density << "[kg/cu.m]\n" << " wind velocity: " << wind_mph << "[mph]\n" << " slope: " << slope << endl; cout << "-----------------------------------------------------\n"; } //=============================================================== float find_power(float vel_mph) { // applied power [watts] as function of velocity [mph] // pre: argument vel_mph and all private and public variables // have values // post: power (watts) has been evaluated and returned const float CONVERT = (4.0/9.0); // mph to meters/sec float vel, // velocity converted to m/s wvel, // wind velocity converted to m/s drag, // resistance due to wind drag [N] resist, // resistance due to rolling and slope [N] power; // applied power to wheels [watts] vel = CONVERT * vel_mph; wvel = CONVERT * wind_mph; drag = cda*density*(vel + wvel)*(vel + wvel)/2.0; resist = mass*g*(cr + slope); power = vel*(drag + resist); return power; } //=============================================================== float find_root(float lo_vel, float hi_vel, float epsilon); // find the root of "find_power" using the bisection method // pre: float bounds [lo_vel, hi_vel] have values // epsilon (allowable error in root) has a value // post: either the root "mid_vel" has been determined within a // tolerance epsilon and has been returned // or a warning message has been displayed //=============================================================== }; //================================================================ // general function prototypes: float get_wind(); // get the wind velocity from the keyboard float get_slope(); // get the slope from the keyboard //================================================================