920 likes | 1.07k Views
Computer Science 1 Week 13. This Week. QBasic Data Files Computer History PC Revolution Graphical User Interface. QBasic Data Files. Saving and retrieving data from a file. Input Data. Store Data. Output Data. Functions of a Computer. QBasic Data Files.
E N D
This Week ... • QBasic Data Files • Computer History • PC Revolution • Graphical User Interface
QBasic Data Files Saving and retrieving data from a file
Input Data Store Data Output Data Functions of a Computer
QBasic Data Files • QBasic Lite data files are text files • other languages support more complex formats • you can create files with any text editor • e.g. Windows Notepad • Text format: • Data items are separated by commas • ornew lines
Example Data File ENIAC,First Generation,1946 The Same ENIAC First Generation 1946
Open Statement • Opens a file • must be done first! • referenced by file numbers • Access Modes • Input – read data from a file • Output – write data to a file
Optional Open Statement Syntax OPEN File FOR INPUT AS # Num OPEN File FOR OUTPUT AS # Num
Minimal SyntaxInput Mode OPEN File AS # Num
Open Example OPEN "test.txt" FOR INPUT AS #1 Input Mode Text File File Number
Open Statement – Finding the Data File • If a path is not used in the Open Statement • QBasic looks in the same folder as your program • if you haven't saved your program – it can't find the data file! • So, make sure to: • save your program first • put the data file in the same folder
Close # Statement • Closes a file • which was opened previously • all open files should be closed • QBasic • automatically closes files when the the program finishes • it is still a good idea to use close
Input # Statement • Reads data from a file • first opened AS INPUT • if not, an error occurs • Assigns it to a variable • works like the normal input statement • reads as many values as variables
Input # Statement Syntax INPUT # Num, Variables # used with Open 1 or more
Example Program DIM Person as string DIM Age as integer DIM Greek as string OPEN "Name.txt" FOR INPUT AS #1 INPUT #1, Person, Age, Greek PRINT Person; " pledged "; Greek CLOSE #1 Name.txt Herky,22,Tappa Kegga Bru
Example Output Herky pledged Tappa Kegga Bru
EOF Function • Acronym for end of file • Used with a file opened for input • used to read a whole file • often used with a While Loop • Returns True when ... • the end is reached • also True if the file is not open
EOF Function Example OPEN "Test.txt" AS #1 DO WHILE NOT EOF(1) INPUT #1, Num PRINT "Read:"; Num LOOP CLOSE #1
EOF Function Example DO WHILE NOT EOF(1) INPUT #1, Num PRINT "Read:"; Num LOOP File Screen 111 222 Read: 111 Read: 222
EOF Function Example 2 DO WHILE NOT EOF(1) INPUT #1, Number LET Total = Total + Number LOOP PRINT "The total is:"; Total Running Total
EOF Function Example 2 Output 90,85,71,77,63,84,98,80 The total is 648
DO WHILE NOT EOF(1) INPUT #1, Number LET Total = Total + Number LET Count = Count + 1 LOOP PRINT "Count:"; Count PRINT "Average:"; Total / Count Running Total Item count File: 90,85,71,77,63,84,98,80
EOF Function Example 3 Output 90,85,71,77,63,84,98,80 Count: 8 Average: 81
Write # Statement • Writes data to a file • opened AS OUTPUT • if not, an error occurs • Often used with INPUT # • saves data in the format Input # can read • data items are separated by commas
Write # Statement Syntax WRITE # Num, Items # used with Open 1 or more
Write # Example OPEN "out.txt" FOR OUTPUT AS #1 WRITE #1, "Herky",22,"TKB" CLOSE #1 Herky,22,TKB
Print # Statement • Prints data to a file • opened AS OUTPUT • if not, an error occurs • Identical to normal print • semicolons append data • commas print in different "columns" • Best used for "printout" files
Print # Statement Syntax PRINT # Num, Items # used with Open 1 or more
Print # Example OPEN "out.txt" FOR OUTPUT AS #1 PRINT #1, "Herky",22,"TKB" CLOSE #1 Herky 22 TKB
QBasic Lab This Week's Exercise
Completely Census Lab • Overview • you are Herman Hollerith • It’s census time! • You will: • read actual 2000 Census data! • compute the U.S. population
Remember ... • Turn your program & your output • to Lab11 in SacCT • You must do your own work • If you do not turn in your program, you will not get credit!
4th Generation Computers Computer History
Fourth Generation Computers • 1971 to present • Use the microprocessor • "a computer on a chip" • faster, smaller & low cost • examples: Intel & Motorola processors • Gave rise to the PC Revolution
Moore’s Law • Moore's law describes a long-term trend in the history of computing hardware. The number of transistors that can be placed inexpensively on an integrated circuit doubles approximately every two years. This trend has continued for more than half a century and is expected to continue until 2015 or 2020 or later
Moore’s Law (contd.) • The capabilities of many digital electronic devices are strongly linked to Moore's law: processing speed, memory capacity, sensors and even the number and size of pixels in digital cameras. All of these are improving at (roughly) exponential rates as well. • This exponential improvement has dramatically enhanced the impact of digital electronics in nearly every segment of the world economy. Moore's law describes a driving force of technological and social change in the late 20th and early 21st centuries.
Moore’s Law (contd.) • The law is named after Intel co-founder Gordon E. Moore, who described the trend in his 1965 paper. The paper noted that the number of components in integrated circuits had doubled every year from the invention of the integrated circuit in 1958 until 1965 and predicted that the trend would continue "for at least ten years". • His prediction has proved to be uncannily accurate, in part because the law is now used in the semiconductor industry to guide long-term planning and to set targets for research and development
Graphical User Interface Computer History
Xerox Alto • Palo Alto Research Center (PARC) • one of the most famous research groups ever • developed the GUI, laser printers, SmallTalk • First built in 1973 • Prototype – never sold • some were given to universities – we have one! • graphic user interface • worked with input devices – mouse, keyset
Mouse Keyset
Xerox Star 8010 • First commercial GUI system • very little has changed in GUI design • released in 1981 • Major GUI Features • set the basic metaphors still used today • What You See Is What You Get • monochrome graphics
Xerox Star 8010 • Sold for $16,000 each! • not designed to be stand-alone system • sold in groups for offices • Demonstrated in 1979 to: • Steve Jobs – began work on Lisa • Bill Gates – began work on Windows • inspired many other systems