--%>

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 Upcast Upcast: It is a cast

    Upcast: It is a cast towards an object's ultimate super type - which is, `up' the inheritance hierarchy towards the Object class, for example:         // Upcast from VariableContr

  • Q : Explain Throws clause Throws clause :

    Throws clause: It is a clause in a method header pointing that one or additional exceptions will be propagated from this technique. For example:    public int find(String s) throws NotFoundExc

  • Q : Define Number of Threads Number of

    Number of Threads: Threads can be a useful abstraction and implementation mechanism to partition independent program actions. However, when there is coordination (or interference) between these threads, the required synchronization mechanisms increase

  • Q : What is the QuickTest Pro testing

    What is the QuickTest Pro testing process?

  • Q : State Precedence rules Precedence rules

    Precedence rules: The rules which determine the order of computation of an expression comprising more than one operator. The operators of higher precedence are computed before those of lower precedence. For example, in the expression x+y*z, the multip

  • Q : What is an Unary operator What is an

    What is an Unary operator: It is an operator which takes a single operand. Java's unary operators are as -, +, !, !, ++ and --.

  • Q : How Java client access Corba A Corba

    A Corba remote object exists. How could you get a Java client to access this object?

  • Q : What is Primitive Type Casting

    Primitive Type Casting: C/C++ allows you to cast between totally unrelated types. This can be problematic for model checking. Avoid type casting between unrelated types and in particular primitive types. For example,

    Q : Explain Out-of-bounds value

    Out-of-bounds value: It is a redundant value employed to point out that a different action from the norm is needed at some point. The read technique of InputStream returns -1 to point out that the end of a stream has been reached, for illustration, ra

  • Q : Explain Mutator method Mutator method :

    Mutator method: It is a method specifically designed to permit controlled modification of a private attribute of a class. By convention, we name the mutators with a set prefix obeyed by the name of the attribute being transformed. For example, the mut