|
|
|
| Variables | | Name | Data Type | Description | | totMiles | float | Total of rounded mileages | | miles | float | An individual rounded mileage |
|
|
|
|
|
|
Now we're ready to write the program. Let's call it Walk. We take the declarations from the tables and the executable statements from the algorithm. We have labeled the output with explanatory messages and formatted it with fieldwidth specifications. We've also added comments where needed. |
|
|
|
|
|
|
|
|
//*****************************************************************
// Walk program
// This program computes the mileage (rounded to tenths of a mile)
// for each of four distances between points in a city, given
// the measurements on a map with a scale of one inch equal to
// one quarter of a mile
//*****************************************************************
#include <iostream.h>
#include <iomanip.h> // For setprecision()
const float DISTANCE1 = 1.5; // Measurement for first distance
const float DISTANCE2 = 2.3; // Measurement for second distance
const float DISTANCE3 = 5.9; // Measurement for third distance
const float DISTANCE4 = 4.0; // Measurement for fourth distance
const float SCALE = 0.25; // Map scale
int main()
{
float totMiles; // Total of rounded mileages
float miles; // An individual rounded mileage
cout.setf(ios::fixed, ios::floatfield); // Set up floating pt.
cout.setf(ios::showpoint); // output format
totMiles = 0.0;
|
|
|
|
|
|