ENGN 38

Lab Programming Assignment #5

 

 

You are to modify Lab Programming Assignment #3.

  • If you didn't modularize the program for Lab Programming Assignment #3, do it now.
                   
  • Change the program to read input from an input file.
    Use the first number method for reading data from an input file.
    Note: You do not have to prompt the user when the program reads input from a file.

                                         
  • Change the program to write the output to an output file.
    Also have the program display the output to the monitor.
                                 

Suggested structure of your program:


            preprocessor directives

            function prototypes

 

 

               main function

                                invoke function that givesinstructions

                                invoke function to open files

                                invoke function to input and process data

                                invoke function to output the data

                                invoke function to close files

 

          function definitions

                                 

Notes: 

The instructions function should only display instructions to the monitor.
(Wouldn't it be silly to write them to a file?)

                           

Create just one function to open both the input file and the output file.

Create just one function to close both the input file and the output file.
                       

For now, you will have to create just one function to perform both the input of the data and the processing of the data. 

Later, when we know how to use arrays, you will be able to make these two seperate functions.                

           
                                     

 

Challenge yourself:

Re-do the lab twice. 

First use the trailer method for reading data from an input file. 

Then use the eof method for reading data from an input file.


              

 

Your input file should look like this:

15

2.34

2.43

2.30

2.29

2.41

2.42

2.33

2.31

2.39

2.40

2.32

2.37

2.42

2.38

2.35

           

 

 

Your output file should look like this:

Distance (meters)

2.34

2.43

2.30

2.29

2.41

2.42

2.33

2.31

2.39

2.40

2.32

2.37

2.42

2.38

2.35

 

 

Physics 4 AL   Laboratory Results

 

Distance  =   xxx.xx  +&-  x.xx  (meters)

 

To turn in:            

Print out your source code and program output making sure that the formatting is up to C++ standards and professional in appearance.  If this does not fit on one page, delete enough so that it does. (Please do not make font size less than 10 points.) What to delete? What to keep? Make sure that you at least have the header as shown in Lab#1 (your student number, your name, the class identifier, the lab number) and the output from your program. As space permits, include any other essentials as you deem appropriate. Make sure that everything is clearly labeled and easy to read and follow. Have this one page ready to turn in by the due date.