Lesson 4, Introduction to Problem Solving
Part 2c

You have been asked by your instructor to write a computer program that will figure out what a student's course average will be at the end of the course.  The assignment average will be 50% of their grade.  Exam 1 and Exam 2 grades are both 15% of their grade.  The final exam grade is 20% of their grade.  There is an advanced version of this course with different weights.  For the advanced class:  Assignments 25%, Exam 1 and Exam 2 are worth 15% each, and the final exam is worth 45%.  When you run the program it will provide let the user know if it is a regular or advanced course and what their course average is. 

Break down this problem into:

1.  Assumptions:
2.  Input
3.  Calculations:
4.  Output

Scroll down for the answer after you try to do it yourself first

 

 

 

 

 

 

 

 

 

 

 

 

Assumptions:
Weight of scores is constant for regular and advanced classes
Only 4 scores will be provided
One student's scores will be presented at a time
The average of the assignments will not be calculated in the program
regular assignment weight = .50
regular exam 1 weight = .15
regular exam 2 weight = .15
regular final exam weight = .20
advanced assignment weight = .25
advanced exam 1 weight = .15
advanced exam 2 weight = .15
advanced final exam weight = .45

Input:
a.  Assignment Average
b.  Exam 1 score
c.  Exam 2 score
d.  Final Exam Score
e.  Is this course advanced? yes/no

Calculations:

1. If class type = "regular" then
    a.  AssignWt = Assignment Average * regular assignment weight
    b.  Exam1Wt = Exam 1 score * regular exam 1 weight
    c.  Exam2Wt = Exam 2 score * regular exam 1 weight
    d.  FinalExamWt = Final Exam score * regular final exam weight
2.  If class type = "advanced" then
    a.  AssignWt = Assignment Average * advanced assignment weight
    b.  Exam1Wt = Exam 1 score * advanced exam 1 weight
    c.  Exam2Wt = Exam 2 score *  advanced exam 2 weight
    d.  FinalExamWt = Final Exam score * advanced final exam weight

3. FinalAverage = AssignWt + Exam1Wt + Exam2Wt + FinalExamWt

4. 
    a.  Output:  "You are in the " class type   "class"
    b.  Output:  "Your Final Average is " FinalAverage

Now you need to write the Human Algorithm (step by step how would you come up with the final output:

Scroll down for the answer after you try to do it yourself first

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Human Algorithm:

Remember, we create the human algorithm from the problem statement (although we can go the other way if you find that creating the human algorithm is easier.  We start out by declaring our constants (1-8), inputting our data (9-13), doing the math (14-22) then outputting the answer (24-25)

Human Algorithm

1.  regular assignment weight = .50
2.  regular exam 1 weight = .15
3.  regular exam 2 weight = .15
4.  regular final exam weight = .20
5.  advanced assignment weight = .25
6.  advanced exam 1 weight = .15
7.  advanced exam 2 weight = .15
8.  advanced final exam weight = .45
 

9.  Input:  Assignment Average
10.  Input:  Exam 1 score
11.  Input:  Exam 2 score
12.  Input:  Final Exam Score
13.  Input:  Is this course advanced? yes/no
 

14.  If class type = "regular" then
15.      AssignWt = Assignment Average * regular assignment weight
16.      Exam1Wt = Exam 1 score * regular exam 1 weight
17.      Exam2Wt = Exam 2 score * regular exam 1 weight
18.      FinalExamWt = Final Exam score * regular final exam weight
      If class type is not "regular" then  '<--We don't number this because it's the negative of 14.
19.      AssignWt = Assignment Average * advanced assignment weight
20.      Exam1Wt = Exam 1 score * advanced exam 1 weight
21.      Exam2Wt = Exam 2 score *  advanced exam 2 weight
22.      FinalExamWt = Final Exam score * advanced final exam weight
 

23.  FinalAverage = AssignWt + Exam1Wt + Exam2Wt + FinalExamWt
 

24.  Output:  "You are in the " class type   "class"re
25.  Output:  "Your Final Average is " FinalAverage

Problem Statement (from above)

Assumptions:
regular assignment weight = .50
regular exam 1 weight = .15
regular exam 2 weight = .15
regular final exam weight = .20
advanced assignment weight = .25
advanced exam 1 weight = .15
advanced exam 2 weight = .15
advanced final exam weight = .45

Input:
a.  Assignment Average
b.  Exam 1 score
c.  Exam 2 score
d.  Final Exam Score
e.  Is this course advanced? yes/no

Calculations:

1. If class type = "regular" then
    a.  AssignWt = Assignment Average * regular assignment weight
    b.  Exam1Wt = Exam 1 score * regular exam 1 weight
    c.  Exam2Wt = Exam 2 score * regular exam 1 weight
    d.  FinalExamWt = Final Exam score * regular final exam weight
2.  If class type = "advanced" then
    a.  AssignWt = Assignment Average * advanced assignment weight
    b.  Exam1Wt = Exam 1 score * advanced exam 1 weight
    c.  Exam2Wt = Exam 2 score *  advanced exam 2 weight
    d.  FinalExamWt = Final Exam score * advanced final exam weight

3. FinalAverage = AssignWt + Exam1Wt + Exam2Wt + FinalExamWt

4. 
    a.  Output:  "You are in the " class type   "class"
    b.  Output:  "Your Final Average is " FinalAverage

 

 

 

Now we need to flowchart this Human Algorithm.  Remember each step is a different flowchart symbol.  Don't combine steps.

Scroll down for the answer after you try to do it yourself first

 

 

 

 

 

 

 

 

Flowchart:

Remember we create the flow chart directly from the human algorithm.  25 steps in the human algorithm, 25 symbols on the flowchart.  If you open your human algorithm and visual logic together on the same screen, next to each other, the flowchart should be easy to create since we have already solved the problem.

 

Human Algorithm

1.  regular assignment weight = .50
2.  regular exam 1 weight = .15
3.  regular exam 2 weight = .15
4.  regular final exam weight = .20
5.  advanced assignment weight = .25
6.  advanced exam 1 weight = .15
7.  advanced exam 2 weight = .15
8.  advanced final exam weight = .45
 

 

 

 

9.  Input:  Assignment Average
10.  Input:  Exam 1 score
11.  Input:  Exam 2 score
12.  Input:  Final Exam Score
13.  Input:  Is this course advanced? yes/no
 

 

14.  If class type = "regular" then
15.      AssignWt = Assignment Average * regular assignment weight
16.      Exam1Wt = Exam 1 score * regular exam 1 weight
17.      Exam2Wt = Exam 2 score * regular exam 1 weight
18.      FinalExamWt = Final Exam score * regular final exam weight
      If class type is not "regular" (else) then  '<--We don't number this because it's the negative of 14.
19.      AssignWt = Assignment Average * advanced assignment weight
20.      Exam1Wt = Exam 1 score * advanced exam 1 weight
21.      Exam2Wt = Exam 2 score *  advanced exam 2 weight
22.      FinalExamWt = Final Exam score * advanced final exam weight
 

23.  FinalAverage = AssignWt + Exam1Wt + Exam2Wt + FinalExamWt
 

24.  Output:  "You are in the " class type   "class"re
25.  Output:  "Your Final Average is " FinalAverage

 

 

 

 

Next you want to write the code using html Kit.

Scroll down for the answer after you try to do it yourself first

 

 

 

 

 

 

 

 

 

VBCode

We can not have any spaces in our variable (places in memory) names.  You can not use any of the Microsoft reserve words either.  You can find list of them at http://support.microsoft.com/kb/216528 You will know you have used a reserve word as a place in memory when using html kit because it will turn purple when you type it into the DIM line.  Try it by typing "Date" as a place in memory and you will see it is different than the other words you have typed.

We type the code directly from the flowchart since we have already solved the problem.  Each symbol is a line of code.  We get the DIM values from each assignment (rectangle) and each input.  Then we just type the line of code the symbol represents.  Assignments are already in vbscript syntax, for input you just add (inputbox(...)), for output you add (document.write....)

<script language=vbscript>
Option Explicit
DIM regularassignwt, regularexam1wt, regularexam2wt, regularfinalwt
DIM advanceassignwt, advanceexam1wt, advanceexam2wt, advancefinalwt
DIM assignavg, exam1, exam2, finalexam, classtype
DIM assignwt, exam1wt, exam2wt, finalexamwt, finalaverage


'assignments
regularassignwt = .50
regularexam1wt = .15
regularexam2wt = .15
regularfinalwt = .20
advanceassignwt = .25
advanceexam1wt = .15
advanceexam2wt = .15
advancefinalwt = .45

 

 

'input
assignavg = inputbox("What is the assignment average?")
exam1 = inputbox("What is the exam 1 score?")
exam2 = inputbox("What is the exam 2 score?")
finalexam = inputbox("What is the final exam score?")
classtype = inputbox("What is classtype? regular/advanced")

 

 

'calculations
if classtype = "advanced" then
    assignwt = assignAvg * advanceassignwt
    exam1wt = exam1 * advanceexam1wt
    exam2wt = exam2 * advanceexam2wt
    finalexamwt = finalexam * advancefinalwt
else
    assignwt = assignAvg * regularassignwt
    exam1wt = exam1 * regularexam1wt
    exam2wt = exam2 * regularexam2wt
    finalexamwt = finalexam * regularfinalwt
end if

FinalAverage = assignwt + exam1wt + exam2wt + finalexamwt

' output
document.write "You are in the " & classtype & " class"
document.write "<br>Your final average is " & finalaverage

</script>

 

Flowchart

 

 

 

.