|
|
|
|
|
|
|
fuelWt = float (fuel) * LBS_PER_GAL;
if (fuel 60)
fuelDistance = float(fuel) * 314.6;
else if (fuel << 361)
fuelDistance = 305.8 + (-0.01233 * float(fuel - 60));
else if (fuel << 521)
fuelDistance = 303.0 + ( 0.12500 * float(fuel - 361));
else
fuelDistance = 323.0 + (-0.04444 * float(fuel - 521));
return fuelDistance * fuelWt;
} |
|
|
|
|
|
|
|
|
Stubs and drivers are important tools in team programming. The programmers develop the overall design and the interfaces between the modules. Each programmer then designs and codes one or more of the modules and uses drivers and stubs to test the code. When all of the modules have been coded and tested, they are assembled into what should be a working program. |
|
|
|
|
|
|
|
|
For team programming to succeed, it is essential that all of the module interfaces be defined explicitly and that the coded modules adhere strictly to the specifications for those interfaces. Obviously, global variable references must be carefully avoided in a team-programming situation because it is impossible for each person to know how the rest of the team is using every variable. |
|
|
|
|
|
|
|
|
Testing and Debugging Hints |
|
|
|
|
|
|
|
|
1. Make sure that variables used as actual parameters to a function are declared in the block where the function call is made. |
|
|
|
|
|
|
|
|
2. Carefully define the precondition, postcondition, and parameter list to eliminate side effects. Variables used only in a function should be declared as local variables. Do not use global variables in your programs. (Exception: It is acceptable to reference the global variables cin and cout.) |
|
|
|
|
|
|
|
|
3. If the compiler displays a message such as UNDECLARED IDENTIFIER, check that identifiers aren't misspelled (and that they are, in fact, declared), that identifiers are declared before they are referenced, and that the scope of the identifier includes the reference to it. |
|
|
|
|
|
|
|
|
4. If you intend to use a local name that is the same as a nonlocal name, a misspelling in the local declaration will wreak havoc. The C++ compiler won't complain, but will cause every reference to the local name to go to the nonlocal name instead. |
|
|
|
|
|
|
|
|
5. Remember that the same identifier cannot be used in both the formal parameter list and the outermost local declarations of a function. |
|
|
|
|
|