Learning File system with operations

Program 1. Purpose of this assignment is to learn to work with files.
Assignment: The file, data.txt, is provided on the class website. Each line of the file consists of a binary operator followed by two operands. Your program will read each line and perform the operation described.

Additional requirements:

There are four possible operations, which your program should store: addition, subtraction, multiplication, and division.

  1. Since order matters for subtraction and division, assume that each line is of the form operator,operand1,operand2 and therefore the operation to perform is operand1 operator operand2 = answer For example, if the line is division,4,3 your program should produce 4 / 3 = 1.33 where operator has been replaced by its common symbol.
  2. When the operand is division, the result should be shown to two decimal places if the second operand is not zero. Since division by zero is undefined, report "undefined" when the denominator is 0.
  3. The results should be printed to the screen. For each line in the file there should be one line of output.
  4. Do not hard-code your program to your particular data; we will generate a different data for testing your program. You can assume that each line will have the form described above and that the operands will be integers that can be stored in four bytes.

Sample Output: Here is some sample output to give you an idea of what you are
trying to achieve.
If data.txt is
addition,82,10
subtraction,3,57
multiplication,90,46
division,26,7
division,26,0
then your program would produce
82 + 10 = 92
3 - 57 = -54
90 * 46 = 4140
26 / 7 = 3.71
26 / 0 = undefined operation

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.