nothing worth knowing can be taught - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

nothing worth knowing can be taught

Description:

Lecture 8 ...nothing worth knowing can be taught. Oscar Wilde. Quiz #2 solutions ... Can't read in first couple of integers, then couple of characters in one ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 11
Provided by: Alexi79
Learn more at: https://cs.nyu.edu
Category:

less

Transcript and Presenter's Notes

Title: nothing worth knowing can be taught


1
Lecture 8
nothing worth knowing can be taught Oscar Wilde
2
Quiz 2 solutions
3
One more nuance on input...
  • Cant read in first couple of integers, then
    couple of characters in one read/readln statement

4
More on loops
  • Changing variables
  • Changing loop count
  • Changing max

5
Average revisited
  • PROGRAM Average
  • VAR iSum, iCount, iGrade, iNumberOfGrades
    integer
  • BEGIN
  • write( 'Please enter the number of grades '
    )
  • readln( iNumberOfGrades )
  • iSum 0
  • FOR iCount 1 TO iNumberOfGrades DO
  • BEGIN
  • write( 'Enter grade ', iCount, ' ' )
  • readln( iGrade )
  • iSum iSum iGrade
  • END
  • writeln( 'Your average is ', (iSum /
    iNumberOfGrades)22 )
  • END.

6
Nested loops
  • Why do we need this???
  • For example, compute class average!

7
Class average
  • PROGRAM ClassAverage
  • VAR iGradeCount, iStudentCount, iGrade, iSum
    integer
  • iNumberOfGrades, iNumberOfStudents integer
  • BEGIN
  • write( 'Please enter the number of students
    ' )
  • readln( iNumberOfStudents )
  • write( 'Please enter the number of grades '
    )
  • readln( iNumberOfGrades )
  • iSum 0
  • FOR iStudentCount 1 TO iNumberOfStudents
    DO
  • FOR iGradeCount 1 TO iNumberOfGrades DO
  • BEGIN
  • write( 'Enter grade ',
    iGradeCount, ' of student ', iStudentCount, ' '
    )
  • readln( iGrade )
  • iSum iSum iGrade
  • END
  • writeln( 'Class average is ',
  • (iSum / (iNumberOfGrades
    iNumberOfStudents) )22 )
  • END.

8
Triangle program
  • PROGRAM Triangle
  • USES Crt
  • VAR iNumberOfLines, iNumberOfColumns integer
  • iLoopCount1, iLoopCount2, iNumberOfStars
    integer
  • BEGIN
  • ClrScr
  • iNumberOfLines 10
  • iNumberOfColumns 20
  • FOR iLoopCount1 1 TO iNumberOfLines DO
  • BEGIN
  • iNumberOfStars 2iLoopCount1 -
    1
  • write( ' ' iNumberOfColumns - (
    iNumberOfStars DIV 2 ) )
  • FOR iLoopCount2 1 TO
    iNumberOfStars DO
  • write( '' )
  • writeln
  • END
  • END.

9
Homework
  • Read Chapter 5 sections 4 and 10
  • Program 3 Page 204 15 a,b
  • due Wed. October 14

10
Programs from this lecture
  • Changing variables inside the loop
  • Changing loop counter and boundary
  • Mixed input
  • Personal average
  • Class average
  • Triangle
Write a Comment
User Comments (0)
About PowerShow.com