ExercisesΒΆ

  1. The following sample file called studentdata.txt contains one line for each student in an imaginary class. The student’s name is the first thing on each line, followed by some exam scores. The number of scores might be different for each student.

    joe 10 15 20 30 40
    bill 23 16 19 22
    sue 8 22 17 14 32 17 24 21 2 9 11 17
    grace 12 28 21 45 26 10
    john 14 32 25 16 89
    

    Using the text file studentdata.txt write a program that prints out the names of students that have more than six quiz scores.


    
    
    

    (ex_6_1)


    
    
    

    (ch_files_q1answer)

  2. Using the text file studentdata.txt (shown in exercise 1) write a program that calculates the average grade for each student, and print out the student’s name along with their average grade.


    
    
    

    (ex_10_2)

  3. Using the text file studentdata.txt (shown in exercise 1) write a program that calculates the minimum and maximum score for each student. Print out their name as well.


    
    
    

    (ex_6_3)


    
    
    

    (ch_files_q3answer)

  4. Here is a file called labdata.txt that contains some sample data from a lab experiment.

    44 71
    79 37
    78 24
    41 76
    19 12
    19 32
    28 36
    22 58
    89 92
    91 6
    53 7
    27 80
    14 34
    8 81
    80 19
    46 72
    83 96
    88 18
    96 48
    77 67
    

    Interpret the data file labdata.txt such that each line contains a an x,y coordinate pair. Write a function called plotRegression that reads the data from this file and uses a turtle to plot those points and a best fit line according to the following formulas:

    \(y = \bar{y} + m(x - \bar{x})\)

    \(m = \frac{\sum{x_iy_i - n\bar{x}\bar{y}}}{\sum{x_i^2}-n\bar{x}^2}\)

    where \(\bar{x}\) is the mean of the x-values, \(\bar{y}\) is the mean of the y- values and \(n\) is the number of points. If you are not familiar with the mathematical \(\sum\) it is the sum operation. For example \(\sum{x_i}\) means to add up all the x values.

    Your program should analyze the points and correctly scale the window using setworldcoordinates so that that each point can be plotted. Then you should draw the best fit line, in a different color, through the points.


    
    
    

    (ex_10_4)

Next Section - Object-oriented programming