<Starting Project 12>
- Open a terminal window and move (cd) into the Project_12 directory created in the
- Download all needed files from Canvas into this directory. Once you have finished with the program and it compiles without syntax errors, run the executable and verify that the output for your program matches the output from the provided solution executable
NOTE: Output of your program is to match the output of the sample solution. This match includes all information written to the terminal by the program <Project 12 Description>
You will write a program that performs the following tasks for a simple mathematical calculator:
- Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file name and tries to open the new file. The loop continues until the user successfully enters a valid file name or presses ctrl-c to exit
- If the input file is empty, your program should indicate that the input file was empty as shown by the sample solution – note that an empty input file message only is printed out for an empty input file. (see the hints section on how to perform this test)
- The input file contains several lines of information for processing. There are two types of lines: one for Math calculations and one for Trig
- Math calculation line: Math, Operator, Value1, Value2
- Operator is +, -, *, / or % (for add, subtract, multiply, divide or modulo)
- Value1 is the first (left) operand for the operator
- Math calculation line: Math, Operator, Value1, Value2
- Value2 is the second(right) operand for the operator
- Trig calculation line: Trig, Operation, Degrees or Radians indicator, Angle Value
- Operation is s, c or t (for sine, cosine or tangent)
- Degrees or Radians indicator is d or r
- Angle Value Is the angle in the same units provided by the Degrees or Radians indicator
- For Trig calculations use 3.14159265 for the value of pi.
- Remember that the trig functions expect the angle in radians not degrees
- Look at the provided input files for further understanding of the expected input.
- All values are double values except for the values used with the modulo operation which requires both operands be integers.
- Possible input file errors are:
- Invalid calculation type – calculation type is not Math or Trig.
Two different error messages |
- Invalid operator for Math
- Invalid operation for Trig
- Output formatting uses the default output configuration ç (7) Output lines look like the following:
- Add: 4 + 6 = 10
- sin(degrees): sin(45) = 0.707107
- Identifiers for output for Math calculations are: Add, Sub, Mul, Div, Mod
- Identifiers for output for Trig calculations are: sin, cos, tan
- Run the sample solution for the provided input file to see the format of the output
- All output is to the terminal. Output of your program is to match that of the sample solution
- Functions can be used in this program, although it is not a requirement.
- This program can easily be completed using loops and if statements (or switch statement)
<Project 12 C++ Hints>
- Resetting the input stream variable: In Dev C++ and g++, the clear function must be used on a file stream that is repeatedly reopened in a loop. Therefore use the following statement in your while loop that executes until a valid filename is entered:
Input_file_stream_var.clear();
Where Input_file_stream_var is the name of your input file stream variable
- Testing for an empty input file is performed by using a priming read, and then testing the status of the file stream after the priming read – before the while loop is entered. In this case, if the file stream is in the fail state (or the eof bit is true) after the priming read, print out an appropriate message and terminate the program. Otherwise proceed to the loop to process and read the rest of the input file
- Use a while loop to read and process all information in the input file (or a do-while loop can be used)
- Each line in the input file will contain a calculation type, a type of operation identifier and two values to use with that operation. All values are separated by spaces. Use extraction for all reads
- Calculation type will be a single word of: Math or Trig
- Operator will be a single character (+, -, *, /, %, s, c or t)
- For Math, the left operand is the first value and the right operand is the second value
- For Math, all operands are of data double except for the mod operator which requires both operands be integers.
- For Trig, the first value is d or r indicating degrees or radians
- For Trig, the second value is the angle in degrees or radians
- All numbers are of data type double except for the values used with the modulo operator
- Output is to use the default format configuration, and all output is to the terminal
- Output is required to match the output provided by the sample solution
- Use a single loop with a priming read to read the information from the input file. Each loop iteration processes one line from the input file and outputs the results of the calculation.
- In the loop use nested if-then-else-if statements to process the information in the input file. Or, use nested switch statements. Or, use a combination of switch and if-then-else-if statements.
- Error messages for invalid input file and empty input file have 47 characters on the top and bottom lines.
Reviews
There are no reviews yet.