160 likes | 172 Views
CS1001 Lecture 13. Mid-Term Review Things You Absolutely Must Know. Program Parts. Header Specification Description Variable Listing etc Input Computation Display END PROGRAM. Program statement & Specification. Program Statements PROGRAM ProgramName END PROGRAM ProgramName
E N D
CS1001 Lecture 13 • Mid-Term Review • Things You Absolutely Must Know
Program Parts Header Specification Description Variable Listing etc Input Computation Display END PROGRAM
Program statement & Specification • Program Statements PROGRAM ProgramName END PROGRAM ProgramName • Specification (Data) IMPLICIT NONE REAL :: Variable REAL, PARAMETER :: CONS = 5.789 INTEGER :: Variable INTEGER, PARAMETER :: Constant = 1 CHARACTER :: Variable etc.
Data Naming • Variables may be mixed case, initial capital and descriptive: • InputTemperature • StepSize • Follow some naming convention, e.g., Hungarian notation • rVariable for REAL data types • iVariable for INTEGER data types • bVariable for LOGICAL data types • etc.
Specification (Initialization) • REAL initialized automatically to 0.0 • INTEGER initialized automatically to 0 • CHARACTER manually initialized: • cQuit = “c” • LOGICAL manually initialized: • bValid = .FALSE.
User Input • User is prompted with a PRINT statement: • PRINT *, “Enter a number from 1 to 10:” • User inputs data read by a READ statement: • READ *, iGuess • User inputs should be validated for range, with correction permitted
Computation & Program flow • Algorithms are procedures developed to perform some desired operation • Repetitive operations can be performed within a loop • Branching (depending on logical expressions or CASE) can be used to perform different procedures
IF Structures • Perform procedure if condition is T or skip: IF (condition) THEN procedure END IF
IF ELSE Structures • Perform one procedure if condition T otherwise do second procedure: IF (condition) THEN first procedure ELSE second procedure END IF
IF ELSE IF Structures • Perform one procedure if condition T otherwise do second procedure if second condition true, else do: IF (condition one) THEN procedure one ELSE IF (condition two) THEN procedure two ELSE procedure three END IF
DO Loops • Counter repetition: DO ControlVar = InitVal, FinalVal, Step statements END DO • DO until condition is TRUE (Pretest, Posttest, Test in the middle): DO statements IF (condition) EXIT statements END DO
Output Display • Results are displayed on the screen using PRINT statements PRINT *, “The answer is: ” , iNumberOut
Statement Summary • PROGRAM, END PROGRAM • IMPLICIT NONE • REAL, INTEGER, CHARACTER, LOGICAL, PARAMETER • PRINT, READ • IF, THEN, ELSE IF, ELSE, END IF • DO, EXIT, END DO
Nature of the Test • 10 questions total • Simple one or two line questions worth 5 points each. E.g., Declare a real variable and initialize to 27.356 REAL :: rSomeVariable rSomeVariable = 27.356 • More complex questions worth 15 points each Write an IF structure to validate a range of inputs • Multiple choice questions
Software • What You Should Bring • One 8.5 x 11-inch piece of paper with notes on both sides • Test is closed notes and closed book • Pencils • Extra paper if needed
Preparation • READ THE BOOK • Review your notes and lecture material • Review your homework and quizzes • Relax, get a good night’s sleep • Write to us if you have any questions