LabGradeTrace

LabGradeTrace - Finally, the two additions are performed...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab Grade Trace Answers to Question 1: The values of the variables after being read in are: preLabPts = 17 preLabMax = 20 labPts = 23 labMax = 25 postLabPts = 12 postLabMax = 15 a. Execution of outClassAvg = preLabPts + postLabPts / preLabMax + postLabMax * 100; Multiplication and division have highest precedence and are evaluated left to right so the division is the first operation performed. The variables postLabPts and preLabMax are both integers so integer division would be used. Hence the first calculation is 12 / 20 which equals 0 The next operation is the multiplication: postLabMax * 100 = 1500
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Finally, the two additions are performed left to right: 17 + 0 + 1500 = 1517 b. Execution of inClassAvg = labPts / labMax * 100; Division and multiplication have the same precedence so evaluation is left to right. All operands are integers so integer division is used. Hence the evaluation is as follows: inClassAvg = (23 / 25) * 100 = 0 * 100 = 0 c. Execution of labGrade = OUT_WEIGHT * outClassAvg + IN_WEIGHT * inClassAvg; is as follows: labGrade = (0.4 * 1517) + (0.6 * 0) = 606 + 0 = 606.8 Question 3: Corrected Program...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online