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

  • Q : Explain the term accessibility testing

    Explain the term accessibility testing.

  • Q : How authorities save their Private Keys

    How do certifying authorities save their Private Keys?

  • Q : Explain Java Virtual Machine Java

    Java Virtual Machine (JVM): It is an idealized machine whose instruction set comprises of bytecodes. Java program is compiled to an equal bytecode form and performed on an interpreter that implements the JVM.

  • Q : What is Pop-up menu Pop-up menu : A

    Pop-up menu: A menu of actions which is generally not visible on the screen till a mouse button is clicked. The Popup menus assist to keep a user interface from becoming cluttered.

  • Q : Explain Conditional operator

    Conditional operator: It is an operator taking three operands that is, a ternary operator. The conditional operator (?:) is employed in the form bexpr ? expr1 : expr2

    Q : Define Propagation Propagation : When

    Propagation: When an exception is thrown in a method, and there is no suitable exception handler within the method, the exception might be propagated to the caller of the method. For a checked exception, the method should include a throws clause in it

  • Q : Define the term non-XML resource Define

    Define the term non-XML resource?

  • Q : Define Delegation Delegation : The

    Delegation: The procedure by which an object passes on a message has received to a sub-ordinate object. When inheritance is not accessible in a programming language, then delegation is the most viable option for ignoring code duplication and promoting

  • Q : Define TCP endpoint TCP endpoint : It

    TCP endpoint: It is the combination of an IP address and Transmission Control Protocol (abbreviated as TCP) port number.

  • Q : What are ORB-IOR-a servant-a POA manager

    In CORBA, what are i) an ORB ii) an IOR iii) a servant iv) a POA and v) a POA manager?

©TutorsGlobe All rights reserved 2022-2023.