COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does...
-
Upload
maude-wilcox -
Category
Documents
-
view
217 -
download
4
Transcript of COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does...
![Page 1: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/1.jpg)
COSC 1P02
Introduction to Computer Science 8.1
Cosc 1P02
“For myself, I am an optimist--it does not seem to be much use being anything else.”
Winston Churchill
![Page 2: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/2.jpg)
COSC 1P02
Introduction to Computer Science 8.2
Class Average
Marks for test in a course Average is sum divided by number of marks Running total
sum values as see them at each point sum is sum of values so far
add next value initial value (no values so far) is 0
Summation algorithm Reading data
ASCIIPrompter Writing results
ASCIDisplayer Example
![Page 3: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/3.jpg)
COSC 1P02
Introduction to Computer Science 8.6
Reading Data from a File
Tedious and error prone to enter data as program running Instead create a file of data (text editor/word processor) Reading data from a file
ASCIIDataFile fields (tab delimited)
Example data includes student number
not really a number but text String
report header, body (detail lines), summary separate methods for each part
![Page 4: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/4.jpg)
COSC 1P02
Introduction to Computer Science 8.8
End of File
Tedious and error prone for user to have to count number of pieces of data
A file contains a finite amount of data each read consumes one value eventually a read must happen when there is no more data
called End Of File (EOF) method isEOF() returns true when last read failed
because of EOF Indefinite loop
need to loop an unknown number of times loop until something happens
Example expect if student number then will be mark count number of students
![Page 5: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/5.jpg)
COSC 1P02
Introduction to Computer Science 8.10
while Statement
An indefinite loop Syntax Execution
evaluates condition if true, executes body if false, quits (continues after body)
Read to end of file loop condition always true so executes body if statement
if condition is true, executes then part then part is one statement so doesn’t need {} break statement quits whatever loop it is
executed within
![Page 6: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/6.jpg)
COSC 1P02
Introduction to Computer Science 8.13
Fill a Box
Problem packing to move
Condition Termination
infinite loop Generating random values
Math.random() Output Summation
![Page 7: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/7.jpg)
COSC 1P02
Introduction to Computer Science 8.17
High and Low Mark
Algorithm is value higher (lower) the highest (lowest) so far
Initial state? Double.MAX_VALUE
Independent ifs independent decisions
Finding maximum value pattern
![Page 8: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/8.jpg)
COSC 1P02
Introduction to Computer Science 8.21
Reports
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
![Page 9: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/9.jpg)
COSC 1P02
Introduction to Computer Science 8.23
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
![Page 10: COSC 1P02 Introduction to Computer Science 8.1 Cosc 1P02 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649f1d5503460f94c33637/html5/thumbnails/10.jpg)
COSC 1P02
Introduction to Computer Science 8.25
The End