Computer Science II Second With files.

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

P3- Represent how data flows around a computer system
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
J. Michael Moore Text Files CSCE 110 From James Tam’s material.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 7P. 1Winter Quarter File I/O in C Lecture.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Count and add list of numbers From user input and from file.
Pascal Programming Today Chapter 11 1 Chapter 11.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
Computer Science 1 How do you store a bunch of similar stuff?
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Sequential Processing to Update a File Please use speaker notes for additional information!
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
Chapter 14: Sequential Access Files
for Repetition Structures
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Program options Write a program for one of the following
Computer Science Dynamics.
Computer Science 2 Outline/Learning Objectives for the day:
How do you store a bunch of similar stuff?
Computer Science II First With files.
Computer Science II First With files.
Code is on the Website Outline Comparison of Excel and R
Computer Science 2 Arrays of Records.
Computer Science 1 Get out your notebook
Continue on the Array of Records program
HOW TO CREATE A CLASS Steps:
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Computer Science 2 Arrays of Records.
Computer Science 2 Getting an unknown # of …. Into an array.
Dry run Fix Random Numbers
Computer Science Dynamics.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CS150 Introduction to Computer Science 1
Computer Science Sorting.
Computer Science 2: Trees
Computer Science 2 Arrays of Records.
How do you store a bunch of similar stuff?
Computer Science 1 Warm-up: True/False Dry Run
Computer Science
See requirements for practice program on next slide.
Game Over Module 4 Lesson 2.
AP Java 9/21/2018.
Functions continued.
Computer Science 1 Online time for Graphics Program Random review
How can you make a guessing game?
Continue with Life, Magic and Catch -up
Computer Science 2 More Trees.
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Warm-up: Dry Run DIV / MOD 2nd If Then Program
Chapter 4: Repetition Structures: Looping
How can you make a guessing game?
Computer Science
Warm-up: True/False Dry Run DIV / MOD 2nd If Then Program
How do you store a bunch of similar stuff?
Computer Science I: Get out your notes.
Continue on the Valentines program
Program options Write a program for one of the following
Dry Run Fix it Write a program
CS 2 2/25/2015 File Exists?.
Random Numbers while loop
Computer Science 1 while
Computer Science 1 Get out your notebook
Dry Run Fix it Write a program
Computer Science And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and.
A bit of Review Review, Dry Run, Program.
Computer Science II First With files.
Presentation transcript:

Computer Science II Second With files

Goals for today Review file commands from last class. Be able to read a program that uses files Be able to fix a program that uses files Be able to write a program that uses files

Dry run the following code program fileOfStuff; {5 pts} type RecordType= record a,b:integer; c:real; end; filetype = file of Recordtype; var Shuttle:Recordtype; fyle:filetype; count:integer; begin assign(fyle,'stuff.dta'); rewrite(fyle); for count:= 10 to 13 do Shuttle.a:= count DIV 2; Shuttle.b:= count mod 3; Shuttle.c:= (shuttle.a+shuttle.b)/2; write(fyle,shuttle); close(fyle); reset(fyle); while not eof(fyle) do read(fyle, shuttle); if shuttle.a mod 2 = 0 then writeln(shuttle.a:5, shuttle.b:5, shuttle.c:6:2); readln; End. Dry run the following code

philephix.pas on the class website program fix’nFile; {This program is supposed to create a file of 1000 random numbers then show them on the screen} type file = file of integer; var total:integer; begin assign(file, ‘numb.skl’); reset(file); for count := 1 to file do readln(file, total); end; for count = 1 to EondOfFile do writeln(file) end. Fix File philephix.pas on the class website

File review Declare Assign(Numfile, ‘stuff.dta’); Rewrite(Numfile); Type Filetype = file of integer; Var Numfile:Filetype; Ties the file variable to the file on the disk. Creates (erases) a file to be written to. Puts information into a file. Puts an EOF marker in the file if adding to the file, and releases the file pointer. Opens a pre-existing file Checks for the end of the file Returns the number of ‘chunks’ in the file. Moves the file pointer to the ‘Position’ spot on the file Used to copy information from a file. See above. Declare Assign(Numfile, ‘stuff.dta’); Rewrite(Numfile); Write(Numfile, variable); Close(Numfile); Reset(Numfile); Eof(filename) FileSize(Filename) Seek(Filename,Position); Read(Numfile,Variable);

First File Program 1) Input an unknown number of names into a file. Show them from the file. 2) Input: An unknown number of integers. Process: Using a file for storing the information, find the total, average, and the number of values within 3 of the average of the values. Output: A chart of the numbers entered. The average The number of values within three of the average. Example: If you enter: 3, 10, 17, 12, 8 Numbers: 3 10 17 12 8 The average = 10 The number within 3 of the average = 3 3) Add a save and load option to the life program.