-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Monday 25 April 2016

File Access Methods in C++

I have discussed the concept of "files" in my previous blog.Today I am discussing the different file access method.

File access Method

The way in which a file can be accessed is called file access method.It depends on the manner in which data is stored in the files.Different file access methods are given below:

Sequential Access Method:

                                                                   It is used to access data in the same manner in which it is stored in a file.This method reads and writes data in a sequence.In order to access the last record,it has to to read all the records before the last one.

The record is not fixed in this access method.It means that each record occupies different amount of memory.

One of its advantages is that memory is not wasted.One of its disadvantages is that it takes very long time to search a record.For example,if the user wants to search the 4th record,it has to read the first 3 records to access the 4th record.

Random Access Method:

                                          It is used to access the data directly without accessing the preceding data.This method does not read or write data in a sequence.It is faster than sequential access method.

It stores data in fixed length records.This is the main disadvantage of this access method.It wastes memory space.Suppose a record of 10 bytes is used to store a complete sentence in a file.If a sentence consists of a single letter like 'H', it will occupy 10 bytes to store this letter.

However,this method speeds up access time because the position of each record can be determined easily as each record takes fixed length.Database management systems store files in a random access format.

Saturday 23 January 2016

Concept of files in C++

Many students are confused with the concept of file handling in C++.So,today I will give you a little introduction about the concept of files in C++ which the essence of file handling.This would be a series of blogs which will help you to understand this concept easily.So,stay tuned !!1

Concept of files

As we see that a program inputs data from the user and stores it in variables.The data stored in the variables is temporary.When the program ends,all data stored in variables is also destroyed. The user has  to input data again from keyboard when the program is executed next time. the data has to be entered each time the program is executed that wastes time. The user may also type wrong data at different times.

Definition of files

A file is a collection of related records.It stores data about an entity(if you are unfamiliar with the concept of entity, remember that an entity is an object about which data is to be gathered.e.g., student is an entity). A data file can be used to provide input to a program.In can also be used to store the output of a program permanently.


Advantages of files

Now we will discuss the advantages of files in C++.

  • Files can store large amount of data permanently.
  • Files can be updated easily.
  • One file can be used by many programs for same input.
  • Files save time and effort to input data via keyboard.

Types of files

C++ provides two types of files.This categorization is based on how data is stored in files. Following are the types of files in C++.

Text files

A type of file that stores data as readable and printable characters in called text file.A source program of C++ is an example of text file.


Binary files

A type of file that stores data as non-readable binary code is called binary file.An object file of a C++ program is an example of binary file.


Reference

This reference of this article is taken from the book,Object Oriented Programming using C++(IT series).