IUP Computer Science
COSC 110  Fall 2006
 
 

Project #1
(Due  13 September 2006)

On the next two pages is a C++ program written in the style you will be expected to use throughout this course. Your first assignment is to enter, compile, link, and run this program.  As you enter the program, replace my name and section number with your own name and your section number. Otherwise, you should enter just what you see on the other pages. Do not worry that the program contains C++ features that we have not yet covered; these features will be covered soon. If you do this correctly, when you run the program, you will see a display similar to this:

Circle diameter is   31.0000 cm or   12.2047 inches
Circumference is   97.3894 cm
Circle area is  754.7676 sq cm
Side of equivalent square is   27.4730 cm or   10.8161 inches
Side of equivalent equilateral triangle is   41.7500 cm or   16.4370 inches
Press any key to continue

After you have entered the slightly modified program and run it to get the answers, print out a page with your program on it. (You MUST do this printing using the Visual Studio programming environment, NOT a word processor; you do not need to print in color.) Then, do one of the following, depending on the last digit of your Banner ID number.

Deliberately make one of the following mistakes in your program and then try to compile again - choose the mistake whose number matches the last digit of your Banner ID number. You should get one or more error or warning messages. By hand, write the last digit of your Banner ID number, and the error/warning message(s) you get on the bottom or back of your printout;  then hand it in.

 0.  Omit the semicolon from  area = PI * RADIUS * RADIUS;
 1.  In the declaration of edgeOfSquare, double    edgeOfSquare;
         change the 'O' to lowercase, i.e., 'o'.
 2.  Omit the () after the word main.
 3.  Replace the first <<  with >>  in
         cout << fixed << showpoint;
 4.  Omit the // on the line  // Specify 4 decimal places
 5.  Change the declaration,  const double   RADIUS = 15.5;
         to    const double  RADIUS;
 6.  Misspell MakeInches as MakeInch in the last cout statement
         << MakeInches(edgeOfTriangle) << " inches " << endl;
 7.  Misspell double in  double     diameter;    as doble.
 8.  Change // to /* in  // Specify 4 decimal places
 9.  Replace the 0 from the  return 0; statement with "done".

Do NOT save your program with the error in it. Do NOT print out your program with the error in it. By hand, using your best handwriting, write the error/warning message(s) on the printout of the correct program. Be sure to look at the entire message window to find all error/warning messages.  You do not need to write repeated error messages; writing each error once is enough.
 

// **************************
//
//   Project 1: Circle - Square - Triangle
//   This program computes the diameter, circumference, and area of
//   a circle, given the radius.  It also computes the length of the
//   side of a square and an equilateral triangle with an area
//   equivalent to that of the circle.  Units are centimeters.
//
//   Author:   Jim Wolfe
//   Section:  789
//   Due on 13 September 2006
//   Input:  none - circle radius is a constant
//   Output:  Shows values described above; some in both inches and cm
//
// **************************

#include <iostream>
#include <iomanip>             // For formatting the output
#include <cmath>               // For the square root function

using namespace std;

const double PI = 3.14159265359;         // Standard value of pi
const double ROOT_OF_3 = sqrt(3.0);      // Square root of 3.0
const double INCHES_PER_CM = 0.3937;     // Inches in one centimeter
const double RADIUS = 15.5;              // Radius of the circle used

double MakeInches (double);        // Prototype for conversion

int main()
{
     double    diameter;           // Computed diameter of circle
     double    circumference;      // Computed circumference of circle
     double    area;               // Computed area of circle
     double    edgeOfSquare;       // Length of side of square with
                                   //   equivalent area
     double    edgeOfTriangle;     // Length of side of triangle with
                                   // equivalent area

     cout << fixed << showpoint;   // Set up for floating pt formatting

     diameter = RADIUS * 2.0;           // Make computations using
     circumference = diameter * PI;     // standard formulas
     area = PI * RADIUS * RADIUS;
     edgeOfSquare = sqrt(area);         // Area of square is square of side

          // Area of a triangle is 0.5 * side * height
          // For equilateral, height is sqrt(3)/2 * side
          // So, side * side * sqrt(3) / 4 is the area

     edgeOfTriangle = sqrt(4.0 * area / ROOT_OF_3);

     cout << setprecision(4);           // Specify 4 decimal places

          // Output results, each in a field of width 9 and with
          // appropriate annotation and convert to inches in the process

     cout << "Circle diameter is " << setw(9)
          << diameter << " cm or " << setw(9)
          << MakeInches(diameter) << " inches " << endl;
     cout << "Circumference is " << setw(9)
          << circumference << " cm " << endl;
     cout << "Circle area is " << setw(9)
          << area << " sq cm " << endl;
     cout << "Side of equivalent square is " << setw(9)
          << edgeOfSquare << " cm or " << setw(9)
          << MakeInches(edgeOfSquare) << " inches " << endl;
     cout << "Side of equivalent equilateral triangle is " << setw(9)
          << edgeOfTriangle << " cm or " << setw(9)
          << MakeInches(edgeOfTriangle) << " inches " << endl;

     return 0;
}

// Function to convert centimeters to inches
//      centimeters - parameter holding some number
//
//     precondition:  centimeters must have a value prior to use
//     postcondition:  the equivalent number of inches is returned

double MakeInches (double centimeters)
{
     return  centimeters * INCHES_PER_CM;
}