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 : Define the term XML Define the term XML?

    Define the term XML?

  • Q : Define the term XQuery Define the term

    Define the term XQuery?

  • Q : Explain Call-by-value Call-by-value:

    Call-by-value: The semantics of passing an argument to a method in which a copy of actual argument value is taken and positioned in a separate memory location, symbolized by the corresponding formal argument. As an outcome, assignment to the formal ar

  • 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 the differences between HTML

    Explain the differences between HTML and XML?

  • Q : Networking Homework Assignment : A

    Homework Assignment : A Barbershop Problem Due: November 20, 2012 In this assignment, you are asked to write a multithreading problem to simulate the barbershop problem, which is a classical synchronization problem. The problem is taken from William Stallings's Operating Systems: Internals and D

  • Q : Explain Base type Base type : The kind

    Base type: The kind of items that might be stored in an array - the arrays defined type. For example, in     int[] numbers; the base type

  • Q : Different services provided by DLR to

    Give details about the different services that are provided by DLR to CLR?

  • Q : Generate source code for an ASP.NET Web

    What is the possibility to generate the source code for an ASP.NET Web service by a WSDL? Answer: The Wsdl.exe tool (as .NET Framework SDK) can be utilized to genera

  • Q : Define Short-circuit operator

    Short-circuit operator: It is an operator in which only as a lot of operands are computed as are required to determine the final outcome of the operation. The logical-and (&&) and logical-or (||) operators are most general illustration, though

©TutorsGlobe All rights reserved 2022-2023.