|
|
|
|
|
|
|
Programming Warm-Up Exercises |
|
|
|
|
|
|
|
|
1. The following program is written with very poor style. For one thing, global variables are used in place of parameters. Rewrite it without global variables, using good programming style. |
|
|
|
 |
|
|
|
|
#include <iostream.h>
void MashGlobals();
int a, b, c;
int main()
{
cin >> a >> b >> c;
MashGlobals();
cout << a= << a << << b= << b <<
<< c= << c << endl;
return 0;
}
void MashGlobals()
{
int temp;
temp = a + b;
a = b + c;
b = temp;
} |
|
|
|
|
|
|
|
|
2. Write the heading for a value-returning function Epsilon that receives two float parameters named high and low and returns a float result. |
|
|
|
|
|
|
|
|
3. Write the heading for a value-returning function named NearlyEqual that receives three float parametersnum1, num2, and differenceand returns a Boolean result. |
|
|
|
|
|
|
|
|
4. Given the heading you wrote in Exercise 3, write the body of the function. The function returns TRUE if the absolute value of the difference between num1 and num2 is less than the value in difference and returns FALSE otherwise. |
|
|
|
|
|
|
|
|
5. Write a value-returning function named CompassHeading that returns the sum of its four float parameters: trueCourse, windCorrAngle, variance, and deviation. |
|
|
|
|
|
|
|
|
6. Write a value-returning function named FracPart that receives a floating point number and returns the fractional part of that number. Use a single parameter named x. For example, if the incoming value of x is 16.753, the function return value is 0.753. |
|
|
|
|
|
|
|
|
7. Write a value-returning function named Circumf that finds the circumference of a circle given the radius. The formula for calculating the circumference of a circle is p multiplied by twice the radius. Use 3.14159 for p. |
|
|
|
|
|
|
|
|
8. Given the function heading |
|
|
|
 |
|
|
|
|
float Hypotenuse( float sidel,
float side2 ) |
|
|
|
|
|