IUP Computer Science
COSC 110  Spring 2007
 

Project #1
(Due  31 January 2007)

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:

Initial velocity of 8.000 m/s and deflection of 40.000 degrees

New velocity for small rock: 0.547 m/s
Big rock velocity: 0.954 m/s
Big rock angle: 10.626 degrees

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  bigRockAngle = asin(part2);
 1.  In the declaration of cosSquared, double    cosSquared;
         change the 'S' to lowercase, i.e., 's'.
 2.  In the line  int main ()      change the right parenthesis to ]
 3.  Replace the first <<  with >>  in
         cout << fixed << showpoint << setprecision(3);
 4.  Omit the // on the line  // Display initial conditions
 5.  Change the declaration,  const double   ONE_EIGHTY = 180.0;
         to    const double  ONE_EIGHTY;
 6.  Misspell Square as Squaring in the statement
          sinSquared = Square(sinSmallAngle);
 7.  Misspell double in  double     part2;    as   doble.
 8.  Change // to /* in  // Display results
 9.  Replace the  return 0; statement with    return "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: Curling Collision
//   This program computes the effects when a half-size
//   curling stone collides with a full-size one.  The effects
//   include the momentum shift to the large stone (its angle
//   and velocity) and the change in speed of the small stone
//   (its new velocity).
//   All velocities are in meters/second.
//
//   Written by Jim Wolfe
//   Section 789
//   Due on 31 January 2007
//   Input:  None - initial velocity of small stone and the
//       deflection angle are set as constants
//   Output: Velocity and angle of the large stone and
//       the remaining velocity of the small stone
// **************************

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

using namespace std;

const double ONE_EIGHTY = 180.0;     // Degrees in a radian
const double PI = 3.14159265359;     // Accurate version of Pi
const double INITIAL_VELOCITY = 8.0; // Starting speed of small
const double SMALL_ANGLE = 40.0;     // Deflection angle of small

double Square (double);              // Function to square a value

int main ()
{
     double  newVelocity;         // Changed velocity of small
     double  bigRockVelocity;     // Velocity of large stone
     double  bigRockAngle;        // Angle of large stone (radians)
     double  bigRockDegrees;      // Angle of large stone (degrees)
     double  cosSmallAngle;       // Cosine of deflection
     double  sinSmallAngle;       // Sine of deflection
     double  sinSquared;          // Sine of deflection squared
     double  cosSquared;          // Cosine of deflection squared
     double  part1;               // Part 1 of formula for angle
                                  //  large stone takes
     double  part2;               // Part 2 of formula

     cout << fixed << showpoint << setprecision(3);
          // Display initial conditions
     cout << "Initial velocity of " << INITIAL_VELOCITY  <<
          " m/s and deflection of " << SMALL_ANGLE << " degrees" << endl;
          // Convert to radians and get trig function values & squares
     cosSmallAngle = cos (SMALL_ANGLE / ONE_EIGHTY * PI);
     sinSmallAngle = sin (SMALL_ANGLE / ONE_EIGHTY * PI);
     sinSquared = Square(sinSmallAngle);
     cosSquared = Square(cosSmallAngle);
          // Calculate angle large stone takes to small stone path
     part1 = cosSmallAngle * sqrt(3.0 + cosSquared);
     part2 = sqrt((1.0 + cosSquared - part1)/4.0);
     bigRockAngle = asin(part2);
          // Convert to degrees for display
     bigRockDegrees = bigRockAngle * ONE_EIGHTY / PI;
          // Calculate large stone's velocity
     bigRockVelocity = (INITIAL_VELOCITY * part2) / (2.0 * (cosSmallAngle
              * part2 + sinSmallAngle * cos (bigRockAngle)));
          // Calculate small stone's remaining velocity
     newVelocity = 2.0 * bigRockVelocity * part2 / sinSmallAngle;
          // Display results
     cout << endl;
     cout << "New velocity for small rock: " << newVelocity << " m/s" << endl;
     cout << "Big rock velocity: " << bigRockVelocity << " m/s" << endl;
     cout << "Big rock angle: " << bigRockDegrees << " degrees" << endl << endl;

     return 0;
}

// Square a floating point value
//    precondition:   arg must contain the value to be squared
//    postcondition:  value returned is the square of arg

double Square (double arg)   // Value to take square of
{
     return arg * arg;       // Calculate and return result
}