You are on page 1of 4

Stock Management System

Kuldeep Sahu, Electronics and Communication Branch, Nit Raipur


Abstract
In a business a proper management of order or The fstream library predefines a set of operations
stocks plays a vital role, say bulk orders like for handling file related input and output. It defines
laptops, desktops, television and so on. In order to certain classes that help one perform file input and
maintain this thing this paper will present a review output. For example, ifstream class ties a file to the
on stock management system which is made with program for input, ofstream class ties a file to the
the help of data file handling. It performs various program for output, and fstream class ties a file to
operations like entering the information of orders, the program for both input and output.
displaying the quantities so that the product is not
out of stock, modifying the information of order, ifstream An input file stream class, inherits
inserting different items, deleting the items and it functions get(), getline(), read() and
also reads the information of the customer. This functions supporting random
access( seekg() and tellg())
system is made with the help of data file handling.
ofstream An output file stream class, inherits
As data file handling helps in storing the put(), write() and functions
information of the stocks permanently in the supporting random access (seekp()
storage. In this method the seller has lifetime access and tellp())
to the information and can modify, insert, delete the fstream An input-output file stream class,
details of stocks and can regulate the availability of provides support for simultaneous
the stocks. input and output operations
Table.1.Functions of file stream classes [1]
Key words: Files, file handling, streams, stocks.

There are different types of filemode which


describes how a file is to be used: to read from it, to
Introduction write to it, to append it and so on.
Most computer programs work with files. This is
because files help in storing information Constants Meaning Stream
permanently. Word processors create document Type
files. Database programs create files of information. ios::in It opens file for reading, input ifstream
Compilers read source files and generate executable mode.
files. So, we see, it is the files that are mostly ios::out It opens file for writing, output ofstream
worked with, inside programs. A file itself is a mode.
bunch of bytes stored on some storage device like ios::trunc It causes the contents of pre- ofstream,
tape, or magnetic disks etc. existing file by the same name ifstream
to be destroyed.
In C++, file input/output facilities are implement ios::binary It causes a file to be opened in ofstream,
through a component header file of C++ standard binary mode, no character ifstream
library. This header file is fstream.h. In C++, a file, translations occur in files
opened in binary mode.
at its lowest level, is interpreted simply as a
Table.2. File Mode Constants [1]
sequence, or stream, of bytes. One aspect of the file
I/O library manages the transfer of these bytes. At
this level, the notion of a data type is absent. The five steps to use files in C++ program are:
1. Determine the type of link required, whether it is
input process, output process or both.
2. Declare a stream for the desired type of link,
ifstream, ofstream or fstream. the stocks, company of the items and their prices
3. Attach the desired file to the declared stream. respectively. If you want to add more stocks you are
4. Now process as required. provided with the option “Do want to add more”, if
5. Close the file link with stream [1]. you want you can press “Y or y” and if you don’t
While working with binary files, you do need to want then you can press “N or n”.
prefix file modes with ios::binary at the time of
opening the file. You can create the file( open them
in ios::out); read the records from binary files ( call
read() function through steam object to which file is
attached); write records in binary files (call write()
function through stream object which file is
attached). This Stock Management system is made
with the help of binary files.

Basic Operations

This stock management system provides the user to


use two profiles either you can enter into the stock Fig.3. To enter the stock information
link to deal with the stock or you can enter into the (b). If you want to see the details of the stock you
customer link to deal with the order or purchase. can choose option 2,

Fig.1. Options to login into stock or customer link

1. Login to Stock Information: In this section user is


provide with following options,

Fig.3. Display the record of stocks


(c). If the user wants to search the record, he/she
can do so by choosing the option 3, here you can
search the record by name, item code or by
company name. We can perform search in a binary
file opened in input mode by reading each record
then checking whether it is our desired record or
Fig.2. Operations for stocks not.

(a). If you want to enter the details of the stocks you


can choose option 1 and can enter the required stock
code for the various items, item name, quantity of
temp.dat and then the rest of the record is appended.
Then the original file stock.dat is deleted by issuing
the command remove(“stock.dat”); and then the
temporary file temp.dat is renamed by issuing the
command rename(“temp.dat”, “stock.dat”);.

(e). To delete a record from the stock information


you can choose option 5. Following procedure is
carried out to delete a record:
Fig.4. Options to search a record
 Firstly, determine the position of the record
to be deleted, by performing a search in the
file.
 Keep copying the records other than the
record to be deleted in a temporary file
temp.dat.
 Do not copy the record to be deleted to
temporary file temp.dat.
 Copy rest of the records to temp.dat.
 Delete original file stock.dat by using the
command remove(“stock.dat”);
 Rename temp.dat as stock.dat by using
rename(“temp.dat”, “stock.dat”);
Fig.5. Searching the record by item code

(d). If you want to insert the stock information in


the file, firstly, it’s appropriate position is
determined and then records in the file prior to this
determined position are copied to temporary file,
followed by the new record to be inserted and then
the rest of the records from the file are also copied.

Fig.7. Delete a record from a file

(f). If you want to modify a record , want to change


the item code, item name, quantity, company name
or price of the item, you can choose option 6. To
modify a record, the file is opened in I/O mode and
an important step is performed that gives the
beginning address of record being modified. After
the record is modified in memory, the file pointer is
once again placed at the beginning position of this
Fig.6. To insert a stock in the file record and then record is rewritten.

In this system the records prior to determined


position are copied to at temporary file temp.dat.
The new file is appended in this temporary file
(ii) We can display the information stored in the
system. This is done by reading the information
stored in the system which is done by the input
stream called ifstream class.
(iii) We can search the record in the stocks. Here we
are provided with various options to search like we
can search by item code, item name, company
name. We read the records and check whether it is
our desired record or not.
(iii) We can also insert new records in the file. This
is done by finding the appropriate position of the
new record then records in the file prior to this
determined position are copied to temporary file,
followed by the new record and then rest of the
records.
Fig.8. Modify a record in a file (iv)We can delete the records in the file which are
not needed.
Conclusion (v) If the user has entered some wrong information
in the file, then the user can modify the record from
File handling in C++ refers to the task of storing the stock.
data in the form of input or output produced by
running C++ programs in data file, namely, a text References
file or a binary file for future reference and analysis.
In this Stock Management system data file handling [1]. Computer Science with C++, Textbook XII,
plays a vital role because of the following reasons: Vol I, by Sumita Arora, Chapter 7 Data file
(i) It helps in preserving the data or information of handling, Page 301-337.
the stocks generated after running the program.
(ii) Using files you need not worry about the
problem of storing data in bulk.
(iii) It saves time. There are certain programs that
require a lot of input from the user. You can easily
access any part of the code with the help of certain
commands.
(iv)You can easily transfer the contents of a file
from one computer system to another without
having to worry about the loss of data.

Result
With the help of data file handling we have
successfully created a stock management system.
This system helps the user to maintain a large
amount of stocks as in case of inventory where we
can do the following operations:
(i) We can store the details of the stocks in the
system which is stored permanently in the system.
This is done with the help of output stream called
ofstream class.

You might also like