< previous page page_129 next page >

Page 129
4. Write expressions to compute both solutions for the quadratic formula. The formula is
0129-01.gif
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The ± means plus or minus and indicates that there are two solutions to the equation: one in which the result of the square root is added to -b and one in which the result is subtracted from -b. Assume all variables are float variables.
5. Complete the following C++ program. The program should find and output the perimeter and area of a rectangle, given the length and the width. Be sure to label the output. And don't forget to use comments.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
//***********************************************
// Rectangle program
// This program finds the perimeter and the area
// of a rectangle, given the length and width
//***********************************************
#include <iostream.h>

int main()
{
    float length;         // Length of the rectangle
    float width;          // Width of the rectangle
    float perimeter;      // Perimeter of the rectangle
    float area;           // Area of the rectangle

    length = 10.7;
    width = 5.2;
6. Write C++ output statements that produce exactly the following output.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Four score
   and seven years ago
b. Four score
   and seven
   years ago
c. Four score
   and

   seven
   years ago
d. Four

   score
     and
   seven
     years
       ago

 
< previous page page_129 next page >