C.S.1428.001 Program Assignment #3

Due: Wednesday, October 18, 2017

Develop an algorithm using top-down design and step-wise refinement to solve the problem listed below. Then implement your algorithm in C++.

For this assignment you must work with one other student in your section to write a program to satisfy the following specifications (no more than two in a group unless approved by your instructor). Names of both members of your group should be listed in the documentation at the top of the program as well as in the personal information section written as output. Turn in one paper copy per group on the due date. Both members of your group must individually submit an electronic copy of the final project. Be sure both group members submit the same program, or no credit will be given.

Write a program to read a simple expression of the form 'value operator value' from the keyboard. (Use only one read statement to "get" the parts of the expression entered.) Keep the prompt and the input expression on one line. Leave two blank lines after keying in the expression and hitting the enter key before printing your identifying information to the console screen. Leave one blank line after the program’s due date before printing an appropriate message to the console screen indicating to the user the name of the output file to which the results have been written. (Refer to sample console output below.) No credit will be given if this program is written using a looping structure!

Evaluate the expression entered at the keyboard as described below. Allow for input of real values.

Check for the addition (+), subtraction (-), multiplication (*), & division (/) operators. (Be sure to include a check for division by zero when the division operator is encountered.) Include a check for an invalid operator as well. (e.g. 134.6 ! 23.1) These are mutually exclusive events suggesting either the use of an if-else if or a switch …with a nested double-sided alternative for handling the division operator. For full credit, you must use a switch statement for this assignment.

ECHO THE ORIGINAL EXPRESSION TO AN OUTPUT FILE (prog3_001out?.txt) along with the evaluated result IF the operator is valid. If division by zero is encountered, echo the original expression to the output file along with the message ' Division by zero produces an undefined result.' (not bold and without quotation marks) If an invalid operator is encountered, echo the original expression to the output file along with the message ' Encountered unknown operator.' (not bold and without quotation marks).

Run the program six times with the data below as the values for the expressions. (Recall that if a looping/repetition construct is used in this program, no credit will be given.) To prevent each successive run from overwriting the previous output file, you should ‘adjust’ the name of the output file with each successive run. Evaluating the first expression should produce an output file named prog3_001out1.txt while evaluating the second expression should produce an output file named prog3_001out2.txt, etc.

For example, type prog3_001out1.txt as the output file name in your source code. Save the changes, build and run the program entering the first expression. Open prog3_001out1.txt, and print the output for the first expression from within Code::Blocks.

Change your source code to reflect the output file name associated with the second expression (prog3_001out2.txt). Run the program again, and enter the second expression. Open prog3_001out2.txt, and print the output for the second expression from within Code::Blocks. Repeat the process for the remaining expressions.

When finished, you should have produced source code and six different output files with six different file names.

Try to eliminate repetitive code in your switch statement!

Expressions to enter for ‘final runs’ – in this order:

1) 123.5 + 59.3

2) 198.7 / -26

3) 125 $ 28

4) 89.3 * 2.5

5) 178.9 - 326.8

6) 198.7 / 0.0

For full credit, you must process as follows (See output sample for spacing/alignment, etc.):

1. Prompt the user for a binary expression of the form operand operator operand.
Read user input.

2. Display the author’s identifying information to the output file.

3. Echo the binary expression entered at the keyboard to the output file.

4. Code a switch statement to match the following operators executing the appropriate statement(s) for each case. (Refer to the output sample to help you decide what you should code for each case.)

a. addition

b. subtraction

c. multiplication

d. division (Use the if-else construct to check against the second operand. Recall that division by zero is undefined.)

e. unknown

5. Display the author’s identifying information on the console screen.

6. Display an appropriate message on the console screen indicating to the user the name of the output file to which the results have been written.


Using Code::Blocks-C++, create source code in a file named prog3_xxxxxx.cpp, replacing xxxxxx with your Texas State NetID, also known as your account number, your username, your UIC, and your user identification code. Your NetID is made up of your initials followed by a series of digits. Make note of the case of the characters in the filename. e.g. I would name my file prog3_br02.cpp, since br02 is my NetID.

When you work with others, the naming scheme must include all accounts. e.g. If Sally Student (ss0000) and I worked together, we would name our file prog3_br02_ss0000.cpp. (If groups fail to include all TxStateNetIDs in the filename and include all names authoring the code in documentation and program output, no credit will be given.)

To receive full credit for this assignment, you must include a complete documentation block. For this assignment, the complete documentation is provided for you. It is located in prog3_xxxxxx.cpp on the assignments page. Copy the content of prog3_xxxxxx.cpp into the file you just created in Code::Blocks.

Pay special attention to this documentation which is much like that found in the example programs located on the assignments page (‘Hello World’ and the ‘Age Calculation’ programs). You will be required to include such documentation in all future programs.

Don’t forget to turn off the spell checker before printing, or points will be deducted.

Change the default paper size from A4 (European paper size) to Letter before printing the source code from within Code::Blocks-C++ by following the instructions described in the Code::Blocks-C++ Compiler document under the C.S.1428 Support Materials link on your instructor’s web page, or no credit will be given. Print on the equivalent of the CS_Letter laser printer (single-sided, no holes), or points will be deducted. Include line numbers only in the source code, or points will be deducted. (To receive full credit, you must have changed comments to a bold, dark color before printing. We can’t grade what we can’t see!)

Print a copy of the input values (expressions entered at the keyboard) from within NotePad. Be sure to save a copy locally so the following ‘meaningful’ file name appears in the header of the printed copy, or points will be deducted. e.g. prog3_001inp.txt

Print one sample console output from within WordPad by following the instructions described in the Code:Blocks Compiler document under the C.S.1428 Support Materials link on your instructor’s web page, or points will be deducted.

Print the six copies of the file output (prog3_001out1.txt, prog3_001out2.txt, etc.) from within Code::Blocks, or points will be deducted. Do not include line numbers when printing input or output files, or points will be deducted.

Turn in the source code, a copy of the input values used for your final ‘runs’, one sample of the console output, and the six output files stapled together (in this order) in the top left corner with the source code on top. Legibly print by hand your full name and section number in the top left corner of the source code.

Don't forget to electronically submit your program on TRACS. Submit only prog3_xxxxxx.cpp.

The number of submission attempts is limited, so ‘use them wisely’. Just like with baseball, three strikes, and you’re out! In other words, don’t submit to TRACS until you are absolutely certain you plan on making no more revisions.

No credit will be given if an entire project is submitted.

No credit will be given unless:

· the paper copies and the electronic copies are simultaneously available to the grader.

· the paper copies match the electronic copies.

· all files necessary for the grader to run your program are simultaneously available, which, in this case, means simply prog3_xxxxxx.cpp.

Refer to my programming style guide, lecture outlines and your lecture notes for more programming requirements to include.

Sample console output for one run. Note: Only turn in one sample console output.


Sample file output for one run should look like the following:

Format the result of each valid expression to one decimal place.

(File output should be printed from within Code::Blocks without line numbers.)

OR (…another sample, again printed from within Code::Blocks.)

OR (…still another sample, again printed from within Code::Blocks.)

Be sure to make note of the spacing (both vertical & horizontal) in the examples above!