Your SlideShare is downloading. ×
0
Introduction to file organization:
◦ What? Why? How?
File organization challenge
History of File organization
Streams oper...
Dr. Hussien M. Sharaf 3
File organization : is rearranging data
structures and its operations in order to
enhance performa...
Dr. Hussien M. Sharaf 4
Data structures
RAM/Main memory
Operations for
accessing data
File structures File processing
Seco...
Dr. Hussien M. Sharaf 5
File structures: is organization of data
representation on secondary devices such as
disks.
File p...
The study of file
organization and
processing is needed in
order to retrieve data from
secondary storage into
RAM so that ...
1. Minimize number of trips to the disk in
order to get desired information.
2. Grouping related information so that we
ar...
Dr. Hussien M. Sharaf 8
Dr. Hussien M. Sharaf 9
Reading/writing data is slow (since
electronic and mechanical)
Dr. Hussien M. Sharaf 10
Dr. Hussien M. Sharaf 11
Dr. Hussien M. Sharaf 12
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and
...
ios::in Open for input operations.
ios::out Open for output operations.
ios::binary Open in binary mode.
ios::ate
Set the ...
ofstream myfile;
myfile.open ("example.bin", ios::out |
ios::app | ios::binary);
Dr. Hussien M. Sharaf 15
class default mo...
Dr. Hussien M. Sharaf 16
if (myfile.is_open())
myfile << "This is a line.n";
myfile.close();
Check that the stream is
open...
tellg() and tellp()
These two member functions return an integer
representing the current position of the get stream
point...
Dr. Hussien M. Sharaf 18
What does this program do?
- Obtain the size of a file
Check Examples 2.1 and 2.2
Write a program that generates a random array of 12
integers and then write each element into a...
Check Examples 2.1 and 2.2 using VS2008 or VS2010
Write a program that reads a given number of lines from
“ArrayElem.txt” ...
Next week is the deadline.
No excuses.
Don’t wait until last day.
I can help you to the highest limit within the next
3 da...
1. Delete the “bin” and “obj” folders.
2. Compress the solution folder using
winrar.
3. Rename the compressed file as foll...
CS215 - Lec 2   file organization
CS215 - Lec 2   file organization
Upcoming SlideShare
Loading in...5
×

CS215 - Lec 2 file organization

1,193

Published on

File management, reading and writing strings/numbers into disk

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,193
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
53
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "CS215 - Lec 2 file organization"

  1. 1. Introduction to file organization: ◦ What? Why? How? File organization challenge History of File organization Streams operations Dr. Hussien M. Sharaf 2
  2. 2. Dr. Hussien M. Sharaf 3 File organization : is rearranging data structures and its operations in order to enhance performance of data reading and writing from and to secondary storage media (disks).
  3. 3. Dr. Hussien M. Sharaf 4 Data structures RAM/Main memory Operations for accessing data File structures File processing Secondary memory (Disks)
  4. 4. Dr. Hussien M. Sharaf 5 File structures: is organization of data representation on secondary devices such as disks. File processing (Streams Operations): The processing (treatment) of data on secondary devices such as disks. It involves transferring data between secondary devices and RAM. This will be built based on your knowledge of Data Structures.
  5. 5. The study of file organization and processing is needed in order to retrieve data from secondary storage into RAM so that programs can process them. The retrieval process must be as fast as possible. Dr. Hussien M. Sharaf 6
  6. 6. 1. Minimize number of trips to the disk in order to get desired information. 2. Grouping related information so that we are likely to get everything we need with only one trip to the disk (e.g. name, address, phone number, account balance). Dr. Hussien M. Sharaf 7
  7. 7. Dr. Hussien M. Sharaf 8
  8. 8. Dr. Hussien M. Sharaf 9
  9. 9. Reading/writing data is slow (since electronic and mechanical) Dr. Hussien M. Sharaf 10
  10. 10. Dr. Hussien M. Sharaf 11
  11. 11. Dr. Hussien M. Sharaf 12
  12. 12. ofstream: Stream class to write on files ifstream: Stream class to read from files fstream: Stream class to both read and write from/to files. Dr. Hussien M. Sharaf 13
  13. 13. ios::in Open for input operations. ios::out Open for output operations. ios::binary Open in binary mode. ios::ate Set the initial position at the end of the file. If this flag is not set to any value, the initial position is the beginning of the file. ios::app All output operations are performed at the end of the file, appending the content to the current content of the file. This flag can only be used in streams open for output-only operations. ios::trunc If the file opened for output operations already existed before, its previous content is deleted and replaced by the new one. Dr. Hussien M. Sharaf 14
  14. 14. ofstream myfile; myfile.open ("example.bin", ios::out | ios::app | ios::binary); Dr. Hussien M. Sharaf 15 class default mode parameter ofstream ios::out ifstream ios::in fstream ios::in | ios::out ofstream myfile ("example.bin", ios::out | ios::app | ios::binary);
  15. 15. Dr. Hussien M. Sharaf 16 if (myfile.is_open()) myfile << "This is a line.n"; myfile.close(); Check that the stream is opened. Write data into stream. Close the stream and hence the modifications are saved into the file.
  16. 16. tellg() and tellp() These two member functions return an integer representing the current position of the get stream pointer (in the case of tellg) or the put stream pointer (in the case of tellp). seekg(count, offset) and seekp(offset, direction) These functions allow programmers to change the position of the get and put stream pointers. ios::beg offset counted from the beginning of the stream ios::cur offset counted from the current position of the stream pointer ios::end offset counted from the end of the stream
  17. 17. Dr. Hussien M. Sharaf 18 What does this program do? - Obtain the size of a file
  18. 18. Check Examples 2.1 and 2.2 Write a program that generates a random array of 12 integers and then write each element into a new line in a file “ArrayElem.txt”. Send the source code project (after zipping it) to my email: n.abdelhameed@fci-cu.edu.eg Follow instructions made in the last page. Make sure to send your ID. Students who don’t send their IDs clearly will loose marks. Dr. Hussien M. Sharaf 19
  19. 19. Check Examples 2.1 and 2.2 using VS2008 or VS2010 Write a program that reads a given number of lines from “ArrayElem.txt” and displays them into one line separated by comma “,”. Send the source code project (after zipping it) to my email: n.abdelhameed@fci-cu.edu.eg Follow instructions made in the last page. Make sure to send your ID. Students who don’t send their IDs clearly will loose marks. Dr. Hussien M. Sharaf 20
  20. 20. Next week is the deadline. No excuses. Don’t wait until last day. I can help you to the highest limit within the next 3 days. Dr. Hussien M. Sharaf 21
  21. 21. 1. Delete the “bin” and “obj” folders. 2. Compress the solution folder using winrar. 3. Rename the compressed file as follows: StudentName_ID_A1.rar StudentName_ID_A2.rar 4. Email to: n.abdelhameed@fci-cu.edu.eg with your ID in the subject. Dr. Hussien M. Sharaf 22
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×