IUP Computer Science
COSC 110  Spring 2006
 
 

Project #1
(Due  1 February 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 with your own name and your section number. Otherwise, you should enter just what you see on the other page. 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:

The area is 597787.417 square feet or 13.723 acres

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.) Then, do one of the following, depending on the last digit of your Banner ID nunber. 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.  Replace the 0 from the  return 0; statement with "done".
 1.  Omit the semicolon from  acres = area / SQFT_ACRE;
 2.  In the declaration of nQuarter, double    nQuarter;
         omit the n in nQuarter.
 3.  Omit the () after the word main.
 4.  Replace the first <<  with >>  in
        cout << acres << " acres" << endl;
 5.  Omit the // on the line  // Standard formula for area
 6.  Change the declaration,  const double   NW_LENGTH = 233.4;
         to    const double  NW_LENGTH;
 7.  Misspell sin as sine in
     area = 0.5*backDistance*forwardDistance * sin (thetaInRadians);
 8.  Misspell double in  double     theta;    as doble.
 9.  Change // to /* in  // Get total area and convert to acres

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 neet to write repeated error messages; writing each error once is enough.
 
 
 

// *****************
// Project #1:  Land Area
// Program to calculate the area of a four-sided piece of land based on
// surveyor measurements made from a point in the interior of the land.
// There are four paired measurements of the angle and distance to each
// corner of the land.  The area is expressed in square feet and acres.

// Written by Jim Wolfe
// Section: 789
// Due:  1 February 2006

// Inputs:  None, all measurements are given as constants.
// Outputs: The land area in square feet and acres.
// ******************

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double     PI = 3.14159265;        // Standard value for PI
const int        FULL_CIRCLE = 360;      // Degrees in a circle
const int        SQFT_ACRE = 43560;      // Square feet in an acre
const double     NW_ANGLE = 308.0;       // Direction to northwest corner (degrees)
const double     NW_LENGTH = 233.4;      // Distance to northwest corner (feet)
const double     NE_ANGLE = 56.0;        // Direction to northeast corner (degrees)
const double     NE_LENGTH = 359.1;      // Distance to northeast corner (feet)
const double     SE_ANGLE = 164.0;       // Direction to southeast corner (degrees)
const double     SE_LENGTH = 783.2;      // Distance to southeast corner (feet)
const double     SW_ANGLE = 218.0;       // Direction to southwest corner (degrees)
const double     SW_LENGTH = 978.5;      // Distance to southwest corner (feet)

void TriArea (double, double, double, double, double &);

int main ()
{
     double  nQuarter;      // Area of north quarter
     double  eQuarter;      // Area of east quarter
     double  sQuarter;      // Area of south quarter
     double  wQuarter;      // Area of west quarter
     double  area;          // Total area in square feet
     double  acres;         // Total area in acres

           // Calculate areas of each quarter using TriArea function

     TriArea (NW_ANGLE, NW_LENGTH, NE_ANGLE, NE_LENGTH, nQuarter);
     TriArea (NE_ANGLE, NE_LENGTH, SE_ANGLE, SE_LENGTH, eQuarter);
     TriArea (SE_ANGLE, SE_LENGTH, SW_ANGLE, SW_LENGTH, sQuarter);
     TriArea (SW_ANGLE, SW_LENGTH, NW_ANGLE, NW_LENGTH, wQuarter);

          // Get total area and convert to acres

     area = nQuarter + eQuarter + sQuarter + wQuarter;
     acres = area / SQFT_ACRE;
     cout << fixed << showpoint << setprecision(3); // Show results
     cout << endl << "The area is " << area << " square feet or ";
     cout << acres << " acres" << endl;
     return 0;
}

// TriArea - calculates the area of a triangle from surveyor measurements
//  Uses the standard formula for the area of a triangle given the
//  length of two sides and the included angle

//     Precondition: Angles and lengths of two sides must be known
//     Postcondition:  Area of the triangle in square feet is returned

void TriArea (double back_ANGLE,       // Angle of one side relative to north
             double backDistance,      // Length of that side
             double forward_ANGLE,     // Angle of other side relative to north
             double forwardDistance,   // Length of that side
             double &area)             // The area of the triangle
{
     double theta;               // Included angle
     double thetaInRadians;      // Included angle in radians

          // Determine included angle and convert to radians

     theta = forward_ANGLE - back_ANGLE;
     thetaInRadians = theta / FULL_CIRCLE * 2 * PI;

          // Standard formula for area

     area = 0.5 * backDistance * forwardDistance * sin (thetaInRadians);
     return;
}