Week9 - Computer Science

advertisement
COSC 1P02
Cosc 1P02
"A lie gets halfway around the world before the truth
has a chance to get its pants on.”
Sir Winston Churchill (1874-1965)
Introduction to Computer Science
9.1
COSC 1P02
Report Generation
 Most data processing involves production of a report (typically
printed)
 Report
 header
 detail lines
 summary (footer)
 Report format
 tabular in nature
 each row represents one entity (e.g. student)
 similar pieces of data (e.g. mark) in a column
 header has a title and a heading for each column
 summary may be columnar or free-form
Introduction to Computer Science
9.2
COSC 1P02
ReportPrinter
 Support for printed reports in columnar format
 title for report centered at top of page
 data written to field
 field has a name, a label and a width
 name used to specify field when writing
 label forms part of heading
 width is width of column
 report designed by setting title and adding fields
 fields added L-R across report
 handles moving to next line and pagination
 Methods
 setting title
 adding fields
 writing into fields
 Example
 PDFCreator
Introduction to Computer Science
9.4
COSC 1P02
Payroll
 Simple monthly payroll for a small company
 File of employee data
 employee number, pay rate, year-to-date gross pay
 Hours worked entered by user
 Payroll report
 employee number, pay rate, hours worked, gross pay, yearto-date gross pay
 layout & formatting
 New file of employee data
 updated year-to-date gross pay
 suitable for input for next month
 Example
 ASCIIOutputFile
 tab delimited text
 prompting
 formatting report fields
 skipping report fields
Introduction to Computer Science
9.6
COSC 1P02
Graphical User Interface
(GUI)
Introduction to Computer Science
9.10
COSC 1P02
User Interaction
 Windows with widgets to allow user interaction
 Both input (data acquisition) and output (display)
 BasicForm
 form is a window
 fields (widgets) for user interaction
 button(s) to indicate user action
 TurtleDisplayer, SoundPlayer, PictureDisplayer,
ASCIIPrompter and ASCIIDisplayer are all BasicForms
 Fields
 name
 label
 size
 position
 format
Introduction to Computer Science
9.11
COSC 1P02
Loan Calculator





Loan with compound interest
Payment and cost of borrowing
Formula
Form
Example
 BasicForm
 setting up form
 adding fields
 name, label, position
 TextFields
 size (width), format
 button
 OK by default
 reading/writing
 by field name
 awaiting user interaction
 accept
Introduction to Computer Science
9.13
COSC 1P02
Loan Calculator Revisited
 Probably want to do “what ifs”
 enter/change values and recalculate
 Multiple buttons to indicate user choice
 Calculate, Quit
 Loop until user presses Quit button
 Example
 multiple buttons
 while loop with break
 accept function method
Introduction to Computer Science
9.16
COSC 1P02
Mark Recorder
 File of marks for student work in course
 2 assignments, test and exam
 Input/update data file
 Forms-based application
 form
 load with data from file
 allow user to update
 write data to new file
 Report
 same fields as form
 Example
 loading/writing course information
 form design
 report design
 read data and fill form
 allow update
 can skip (Next)
Introduction to Computer Science
9.17
COSC 1P02
Widgets
 Interaction objects that can appear on form
 Buttons
 displayed on accept
 control interaction
 Label
 CheckBox
 RadioButton
 Slider
 Sound
 TextField
 Canvas
 TextArea
Introduction to Computer Science
9.18
COSC 1P02
Switch Statement
 Choice between a number of alternatives based on a value
 Typically used to handle user choices in GUI
 E.g. button number pressed
 Syntax
 Execution
 evaluate expression
 check each case in order to see if it matches
 if so, execute statements and break out of switch
Introduction to Computer Science
9.19
COSC 1P02
BasicForm Widgets
method
addCanvas(name,label,width,height,
x,y)
addCheckbox(name,label,x,y)
addLabel(name,label,x,y)
addRadioButtons(name,label,vertical,
x,y,button1…)
addSlider(name,label,min,max,size
x,y)
addSound(name,label,width,height,
x,y)
addTextArea(name,label,rows,columns,
x,y)
addTextField(name,label,format,width,
x,y)
placePicture(name,picture)
placeSound(name,sound)
placeTurtle(name,turtle)
meaning
adds a labeled canvas with name, width, and
height at (x,y)
adds a labeled checkbox with name at (x,y)
adds a label with name at (x,y)
adds labeled radio buttons with name vertical of
horizontal at (x,y) with button names buttoni
adds a labeled slider with name and size over
the range min to max at (x,y)
adds a labeled sound play button with name,
width and height at (x,y)
adds a labeled text area with name, rows and
columns at (x,y)
adds a labeled text field with name and format
at (x,y) and width
places picture onto the canvas name
places sound onto the player name
places turtle onto the canvas name
Introduction to Computer Science
9.22
COSC 1P02
The end
Introduction to Computer Science
9.23
Download