Math 171 - Alexiades
                      Lab 7
            Loops, conditionals, scripts, functions

            (always read the entire Lab before you start working on it)
A. Steps in writing code:
  • Writing a program involves several steps: thinking... deciding what needs to be done, thinking...,
      organizing the tasks into an algorithm on paper, thinking..., translating to computer language on paper, thinking... ,
      executing it on paper, thinking, ... before you even sit in front of the computer.
  • Start by doing the steps first on paper, then on Matlab.

    B. Processing grades. In two parts.
      1. Part 1: function grade(Exam1, Exam2, Exam3)
       The first task is to write a function subprogram, in a file named grade.m, that:
      a. Gets scores for 3 exams: Exam1, Exam2, Exam3 as input (via arguments).
      b. Prints them (nicely, using fprintf).
      c. Finds their average: Avg.
      d. Assigns a Grade according to the scale:
          A   if Avg ≥ 90,   B   for 80 ≤ Avg < 90,   and so on, down to F for Avg < 60.
      e. Prints the Avg and Grade (nicely, using fprintf).
  • As always, at the top insert (as comments) your name, date, what the program does (documentation).

  • For a single student, this function may be called directly by passing 3 exam scores to it.
      Test and debug the function by typing, e.g.:   >> grade(90, 76, 80)   and a few others.

  • But for an entire class, that would be a pain... better to call it from a main program (often called a driver code),
      which will obtain exam scores somehow, call the function for each student, and then also find the class average.

      2. Part 2: script classGrades.m
       Create a file named classGrades.m for the script. Tasks for the main code:
      a. Generate M triples of random (integer) scores between 40 and 100, representing 3 scores for each of M students.
      b. For each student, call the grade function to obtain that student's Avg and Grade, and print them out (nicely, with fprintf).
      c. At the end, find the ClassAvg, and print it out nicely.
  • The main code should be inserted at the top of the file classGrades.m (after Name, Date, etc).
      Then insert a separation line:   %=====================================%
      Then insert the function code, and make appropriate modifications (e.g. comment out printing, since the main code will do it).
  • Debug it for M=2 , and for M=5 , and for M=20 .

    C. Prepare the file Lab7.txt  for submission:
      Once you have your program working as it should, and well commented:
      1. Turn on diary:   >> diary Lab7.txt
      2. Insert a listing of your program in the diary:   >> type classGrades.m
      3. insert a separator: %-----------------------------------------------------%
      4. Run your program:   >> classGrades   for M=4
      5. Close the diary:   >> diary off
      6. Using a PLAIN TEXT editor, edit the file Lab7.txt to clean it up,
       leaving ONLY the correct version of
    what is asked for above.
      7. Submit on Canvas before the due date.