ENGN 38

Lab Programming Assignment #3

 

 

In a Physics 4AL experiment, data is taken for a distance measurement 15 times.  

The data is assumed to contain random variations about the true value.  

               

The best estimate of the true value is the average value: 

xbest = sum of all the data values / n

                   

The uncertainty can be estimated by the R/N method:

uncertainty = [maximum of all the data values - minimum of all the data values] / n
                

                                   

Write two versions of a C++ program that calculates the best estimate and the uncertainty of the Physics 4AL data. One version should use a counting loop and the other a conditional flag loop.

           

Outline of Version 1 - Counting Loop Method

    • Declare and initialize variables.
    • Ask the user how many data values they have.
    • Create a counting loop to iterate numberOfDataValues times.
      (You might want to use a 
      for loop for this.)
      For each iteration:
      • Prompt user to input the next data value.
      • Keep a running tally of the sum of the data values.
      • Keep track of the current maximum and minimum values.
    • When the loop is finished calculate the average and the uncertainty.
    • Display the output to the monitor.

Outline of Version 2 - Conditional Flag Loop Method
    • Declare and initialize variables.
    • Create a conditional flag loop to iterate until the user has entered all of the data values.
      (You might want to use a do..while interactive loop for this.)
      For each iteration:
      • Prompt user to input the next data value.
        You'll need to figure out a criteria to determine when the user is finished.
      • Keep a running tally of the sum of the data values.
      •  Keep track of the current maximum and minimum values.
      • Increment counter
    •  When the loop is finished calculate the average and the uncertainty.
    • Display the output to the monitor.

 

Physics 4AL data to be used for input

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

 

 

Output on the monitor should look like this:

Physics 4AL 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.