1 / 15

Samples (Selection, Loop, and Function)

Samples (Selection, Loop, and Function). Problem 1.

axel
Download Presentation

Samples (Selection, Loop, and Function)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Samples (Selection, Loop, and Function)

  2. 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.

  3. 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.

  4. Problem 1 • How many selections? • Passing? • Marginal? • Error?

  5. Problem 1 Y Error • Sequence? N N Passing? Y N Marginal? Y End

  6. Problem 1 Page 234-235

  7. 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.

  8. 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

  9. Problem 2 • Sequence? • Repetition? • Termination Condition? • If selection? • Average amount, total amount, number of females and males.

  10. Problem 2 Y End? N N Y Female Number of female Total amount (female) Number of male Total amount (male) End

  11. Problem 2 Page 294-296

  12. Problem 3 ***** ***** ***** ***** ***** * ** *** **** ***** 5?   *****  * *** ***** ******* *********

  13. 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

  14. 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

More Related