A2: Arithmetic Formulas

On This Page


Overview

The main points of this assignment are to:

  • Compile a program.
  • Convert mathematical formulas to arithmetic expressions.
  • Use functions from the C++ <cmath> library.
  • Document your program.

Specifications

Using the starter code, convert each of the following mathematical equations to an arithmetic expression.

  1. a + b - c
  2. (a - b)2

Code each expression after the expression-variable of the starter code that matches the equation number. For instance, equation 1 matches expr1 in the starter code. Thus, the arithmetic expression is assigned to expr1 of the starter code.

The output of the program should look similar to the sample output shown below.

Sample Output

$ ./expressions
Enter four values: 1 4 2 3
a = 1, b = 4, c = 2, d = 3

Expression 1: 3
Expression 2: -17.2222
Expression 3: 9
Expression 4: 5
Expression 5: 3.16228

Additional specification are:

  1. The name of the program must be math.cpp and all the code must be in this file.
  2. When run, your program display must look just like the Sample Output shown above, including the labels for each expression, for you to receive full credit.
  3. Create a file comment block at the top of your source code formatted like the following:
  4. /**
     * CS-11 Asn 2
     * math.cpp
     * Purpose: Prints results of various expressions to the screen.
     *
     * @author Ed Parrish
     * @version 1.0 8/31/05
    */
    

    Use your own name and date, of course.

  5. Make certain that you have no tab characters in your source code.
  6. In addition, make sure you have spaces before and after operators and after commas.
  7. Also, make sure your line length is 80 characters or less.
  8. Do not worry about magic numbers for this assignment.
  9. Do not add to or change the input statements provided in the starter code.
  10. Use the default formatting and precision for the numbers -- do NOT add any formatting statements to the code.
  11. Submit your file(s) to WebCT as explained in the section of this document: What to Turn In.

Starter Code

#include <cmath>
#include <iostream>
using namespace std;

int main() {
    // Do NOT change the next few lines
    double a, b, c, d;
    cout << "Enter four values: ";
    cin >> a >> b >> c >> d;
    cout << "\na = " << a << ", b = " << b << ", c = " << c
         << ", d = " << d << "\n\n";

    // Make changes after this line
    double expr1 = 0; // change this line for expression 1
    cout << "Expression 1: " << expr1 << endl; // do not change this line

    double expr2 = 0; // change this line for expression 2
    cout << "Expression 2: " << expr2 << endl; // do not change this line

    double expr3 = 0; // change this line for expression 3
    cout << "Expression 3: " << expr3 << endl; // do not change this line

    double expr4 = 0; // change this line for expression 4
    cout << "Expression 4: " << expr4 << endl; // do not change this line

    double expr5 = 0; // change this line for expression 5
    cout << "Expression 5: " << expr5 << endl; // do not change this line

    // Add extra credit after this line
}

Extra Credit

The following are worth extra credit points:

  1. Install CygWin or GCC/g++ on a computer system. (2 points)
  2. Briefly describe your installation experience in the README.txt file you submit. Include a description of how you tested the installation.

    Note that if you get stuck installing, you should bring your questions to class.

  3. Code the following mathematical equation as an arithmetic expression and display the result with a label of Expression 6 (1 point):
  4. Code the following mathematical equation as an arithmetic expression and display the result with a label of Expression 7 (1 point):
  5. aebc

    The letter e in the above formula is the mathematical symbol for the exponent which is the base of the natural logarithms. To represent this in C++, you will need to use the exp function.

Include the extra credit code in your math.cpp file. Make certain that your README.txt file describes any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course information page.

Program Compilation

  • 4: Source code compiles with no errors or warnings
  • 2: Source code compiles with warnings
  • 0: Does not compile or wrong file turned in

Functionality

Two (2) points for each correct arithmetic expression (10 points possible).

Programming Style

  • 4: Code is well-documented
    • Name, date, and program description in file comment block
    • Follows specified format for file comment block
    • Proper use of spaces around operators
    • No tab characters are present in the source code
    • As described in How To Document and Organize C++ Code
    • Correct file name used
  • 3: Code has minor documentation errors
    • Has 1 documentation error
  • 2: Code has some documentation errors
    • Has 2-3 documentation errors
  • 1: Code has many documentation errors
    • Has more than 3 documentation errors
  • 0: No apparent attempt to document code

REAME.txt File

  • 2: README.txt file submitted with specified information included
  • 1: README.txt file submitted but some information was missing
  • 0: No README.txt file submitted

Maximum Score: 20, plus extra credit

What to Turn In

Submit your assignment following the instructions for homework. Include the following items for grading:

  1. README.txt file
  2. math.cpp source code file

You must submit all the files needed to make your assignment function properly. Do not assume that the instructors has any files unless explicitly stated by the instructor. Your assignment must work as submitted.

Home | Blackboard | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links

Last Updated: February 19 2007 @14:29:47