150 likes | 224 Views
Samples (Selection, Loop, and Function). Problem 1.
E N D
Problem 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 student’s 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.
Problem 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.
Problem 1 • How many selections? • Passing? • Marginal? • Error?
Problem 1 Y Error • Sequence? N N Passing? Y N Marginal? Y End
Problem 1 Page 234-235
Problem 2 • You’ve 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, you’ve been asked to compute the average income for females and the average income for males.
Problem 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
Problem 2 • Sequence? • Repetition? • Termination Condition? • If selection? • Average amount, total amount, number of females and males.
Problem 2 Y End? N N Y Female Number of female Total amount (female) Number of male Total amount (male) End
Problem 2 Page 294-296
Problem 3 ***** ***** ***** ***** ***** * ** *** **** ***** 5? ***** * *** ***** ******* *********
Problem 4 Input Date Seed Date Sunday Total=0; For (i=sm+1; i<im-1;i++) total= total+ days_of_ith_month; Total=Total+ d1 +Id; For example, 2, 30 2%7 = 2, it’s Tuesday 30%7 = 2, it’s Tuesday
Problem 4 Seed Date Sunday Input Date Total=0; For (i=im+1; i<sm-1;i++) total= total- days_of_ith_month; Total=Total- is -days_of_im-id; For example, -5, -33 -5%7 = 2, it’s Tuesday -33%7 =2 , it’s Tuesday