Title: Samples (Selection, Loop, and Function)
1Samples (Selection, Loop, and Function)
2Problem 1
- Many universities send warning notices to
freshmen who are in danger of failing a class.
Your program should calculate the average of
three test grades and print out a students ID
number, average, and whether or not the student
is passing. Passing is a 60-point average or
better. If the student is passing with less than
a 70 average, the program should indicate that he
or she is marginal.
3Problem 1
- Input student ID number followed by three test
grades. The student ID number is of type long to
accommodate larger values such as nine-digit
social security numbers. - Output
- Echo print
- ID, average grade, passing/failing, marginal, and
error message if any of the test scores are
negative.
4Problem 1
- How many selections?
- Passing?
- Marginal?
- Error?
5Problem 1
Y
Error
N
N
Passing?
Y
N
Marginal?
Y
End
6Problem 1
Page 234-235
7(No Transcript)
8Problem 2
- Youve been hired by a law firm that is working
on a sex discrimination case. Your firm has
obtained a file of incomes, incfile, that
contains the salaries for every employee in the
company being sued. Each salary amount is
preceded by F for female or M for male. As a
first pass in the analysis of this data, youve
been asked to compute the average income for
females and the average income for males.
9Problem 2
- Input a file, incFile, (run-time filename) of
floating-point salary amounts, with one about per
line. Each amount is preceded by a character F
for female and M for male. - Output
- Echo print
- Number of females and their average income
- Number of males and their average income
10Problem 2
- Sequence?
- Repetition?
- Termination Condition?
- If selection?
- Average amount, total amount, number of females
and males.
11Problem 2
Y
End?
N
N
Y
Female
Number of female Total amount (female)
Number of male Total amount (male)
End
12Problem 2
Page 294-296
13Problem 3
5?
?
?
?
14Problem 4
Input Date
Seed Date Sunday
Total0 For (ism1 iltim-1i) total total
days_of_ith_month TotalTotal d1 Id For
example, 2, 30 27 2, its Tuesday 307 2,
its Tuesday
15Problem 4
Seed Date Sunday
Input Date
Total0 For (iim1 iltsm-1i) total total-
days_of_ith_month TotalTotal- is
-days_of_im-id For example, -5, -33 -57 2,
its Tuesday -337 2 , its Tuesday