Sie sind auf Seite 1von 3

Project 1 of JG Calculator

This project is based on the design of a calculator that performs the addition subtraction,
multiplication, division and explains in detail the function that this JG calculator performs based
on the designated commands that are located in the CommandsProj1.dat which is the file from
where the program takes the information from. The information refers to the data entered in the
mother file that consist in a series of simultaneous commands like the addition operand, and so
on, that come hand to hand with a couple of integers or characters separated by a space and a
new line when the command needs to be finished. The code is designed to read the commands,
numbers perform the operations, such as multiplication, subtraction, and once such procedures
are done and completed, the program will print out neatly the results of the operations carried
on the program

Three integers were declared and initialized to zero with the purpose of representing and
scanning the numbers gotten from the original file. The five characters corresponded to the
initials of the user name that would utilize this calculator, two of those characters represented
the Help command which had the function to explain the user all the commands involve in this
apparatus and the quit command which would confirm with the user whether it was his/her
desire to quit. The output of this program explains each function with a statement referring to the
command being processed at the moment, it prints out neatly the result of the functions
addition, subtraction, multiplication, division help and quit in the display and the file
CalcResults.dat .

The program is developed in different sections or parts of a whole instruction:


We first declare the libraries that hold the functions used in this program.

If functions are to be used in this program, the writing of the prototype are written in this section,
making sure that for the body of the function, you are returning and sending the same type of
data, and trying to not forget the semicolon otherwise the program will not compile:

In this example, a set of integers and characters are sent to the respective function and most of
them are returning a double value, one character and the Help function not returning anything to
main.

Inside of main the first thing to be done is the declaration of the variables, the pointers that will
read and write the results in the files and the opening of the used files to start processing the
information inside of CommandsProj1.dat.

The next step is to print in both the display and the file, an introduction explaining what
this calculator is and what it does. Next, an structure of the program is developed that will
determine the body of the function. We developed a loop so the program would repeat until the

user decides to end the program, a switch statement structure was developed to alternate
between the different cases inputted in the origin file.

For the bodies of the functions created, it is necessary to put the structure of each function
inside the brackets that encloses each set of instructions. A value is returned to main through
the invocation of the function inside of main. Dont forget the closure of the files in the command
Q of the program which stands for Quit command.

Das könnte Ihnen auch gefallen