A2: Compiling Expressions

On This Page


Overview

During this assignment, you will:

  • 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.

After you compile the program, You can run the program by typing at the command line something like:

./expressions 1 4 2 3

where 1 4 2 3 matches up with a, b, c and d respectively.

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

Sample Output

$ ./expressions 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 expressions.cpp
  2. You must print the labels, such as Expression 1, to receive full credit.
  3. Create a file comment block at the top of your page formatted like the following:
  4. /**
     * CS-11 Asn 2
     * expressions.cpp
     * Purpose: Prints results of various expressions to the screen.
     *
     * @author Ed Parrish
     * @version 1.0 2/2/04
    */
    

    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.
  7. Do not worry about magic numbers for this assignment.

Starter Code

#include <iostream>
using namespace std;

int main(int argc, char* argv[]) {
    // You can ignore the next few lines
    if (argc != 5) {
        cout << "You must enter 4 values after the program name\n";
        exit(1);
    }
    double a = atof(argv[1]);
    double b = atof(argv[2]);
    double c = atof(argv[3]);
    double d = atof(argv[4]);
    cout << "a = " << a << ", b = " << b << ", c = " << c
         << ", d = " << d << endl;

    // 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. Code the following mathematical equation as an arithmetic expression with a label of Expression 6 (1 point):
  2. Code the following mathematical equation as an arithmetic expression with a label of Expression 7 (1 point):
  3. 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 expressions.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. expressions.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 | WebCT | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links

Last Updated: September 14 2004 @15:02:02