0% found this document useful (0 votes)
28 views

Lab Manual 1

The document discusses file processing and handling in C++. It defines key terms like records, files and databases. It also explains opening, writing, reading and closing files in C++. Sample code is provided to demonstrate reading from and writing to a file. Some disadvantages of file processing systems for banking applications are also discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lab Manual 1

The document discusses file processing and handling in C++. It defines key terms like records, files and databases. It also explains opening, writing, reading and closing files in C++. Sample code is provided to demonstrate reading from and writing to a file. Some disadvantages of file processing systems for banking applications are also discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Adigrat University First Laboratory manual

Electrical and Computer for Database Systems


Engineering(Computer)

File Processing

File processing is the process of creating files in a recognized medium, storing


data in them and accessing or retrieving the contents (if required). Files are used
for permanent data storage of large amounts of data. Storage of data in variables
and arrays is only temporary.

Definition of key terms:

Teller: is someone who works in a bank and customers pay money to or take
from.
Withdraw: if you withdraw money from a bank account you take it out from
that account

Deposit: if you deposit money in a bank account you go to the bank and give
your money to the teller and it will remain in the bank until you need it back.

Redundancy: unnecessary duplicates of something.

Inconsistency: contradiction of one thing with another.

Data hierarchy:

Bit-smallest data item with a value of 0 or 1.


Byte – is a collection of 8 bits. It is used to store a character, Decimal digits,
letters, and special symbols.
Field- group of characters conveying meaning.
Example: your name
Record – group of related fields. It is represented by a structure or a class
Example: In a registrar system, a record for a particular student may contain
his/her identification number, name, gender age and address and others if
needed.
File: a collection of related records. For example, a collection of student details.
Database: group of related files
Example: details about students, their courses and grades.

Data File Handling In C++


Stream. It refers to a sequence of bytes.
Text file. It is a file that stores information in ASCII characters. In text files,
each line of text is terminated with a special character known as EOL (End of
Line) character or delimiter character. When this EOL character is read or
written, certain internal translations take place.
Binary file. It is a file that contains information in the same format as it is
held in memory. In binary files, no delimiters are used for a line and no
translations occur here.
Classes for file stream operation
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.

To perform file processing in C++, header files <iostream> and <fstream>


must be included in your C++ source file.

Opening a File:
A file must be opened before you can read from it or write to it. Either
the ofstream or fstream object may be used to open a file for writing
and ifstream object is used to open a file for reading purpose only.

ollowing is the standard syntax for open() function, which is a member of


fstream, ifstream, and ofstream objects.

void open(const char *filename, ios::openmode mode);

Here, the first argument specifies the name and location of the file to be
opened and the second argument of the open() member function
defines the mode in which the file should be opened.

Mode Flag Description

ios::app Append mode. All output to that file to be appended to


the end.

ios::ate Open a file for output and move the read/write control to
the end of the file.

ios::in Open a file for reading.

ios::out Open a file for writing.

ios::trunc If the file already exists, its contents will be truncated


before opening the file.

You can combine two or more of these values by ORing them together.
For example if you want to open a file in write mode and want to
truncate it in case it already exists, following will be the syntax:

ofstream outfile;
outfile.open("file.dat", ios::out | ios::trunc );

Similar way, you can open a file for reading and writing purpose as
follows:

fstream afile;
afile.open("file.dat", ios::out | ios::in );

Closing a File
When a C++ program terminates it automatically closes flushes all the
streams, release all the allocated memory and close all the opened files.
But it is always a good practice that a programmer should close all the
opened files before program termination.

Following is the standard syntax for close() function, which is a member


of fstream, ifstream, and ofstream objects.

void close();

Writing to a File:
While doing C++ programming, you write information to a file from your
program using the stream insertion operator (<<) just as you use that
operator to output information to the screen. The only difference is that
you use anofstream or fstream object instead of the cout object.

Reading from a File:


You read information from a file into your program using the stream
extraction operator (>>) just as you use that operator to input
information from the keyboard. The only difference is that you use
an ifstream or fstream object instead of the cin object.

Read & Write Example:


Following is the C++ program which opens a file in reading and writing
mode. After writing information inputted by the user to a file named
afile.dat, the program reads information from the file and outputs it onto
the screen:

#include <fstream>
#include <iostream>
using namespace std;

int main ()
{

char data[100];

// open a file in write mode.


ofstream outfile;
outfile.open("afile.dat");

cout << "Writing to the file" << endl;


cout << "Enter your name: ";
cin.getline(data, 100);

// write inputted data into the file.


outfile << data << endl;

cout << "Enter your age: ";


cin >> data;
cin.ignore();

// again write inputted data into the file.


outfile << data << endl;

// close the opened file.


outfile.close();

// open a file in read mode.


ifstream infile;
infile.open("afile.dat");

cout << "Reading from the file" << endl;


infile >> data;

// write the data at the screen.


cout << data << endl;

// again read the data from the file and display it.
infile >> data;
cout << data << endl;

// close the opened file.


infile.close();

return 0;
}

To understand how files as used for different applications, develop a banking


application using any language that you are most familiar with. The application
should enable users to perform at least the following tasks:

1. Registration of a new customer (i.e. the system should be able to accept


the name, gender, age & address of the customer and his account number
is assigned by the manager).
2. Withdraw or deposit based on customer request.
3. Display customer’s balance and other details.
4. Delete a customer if she/he changes to other banks.
5. Show the daily transaction details.

Now try to answer the following questions:

Q1.What will you do if new requirements arise? For example, if the manager is
interested to see customers whose balance is > 1000.00 Birr or those from a
specific Zone. Do you think that this requirement can be full filled by the
application that you have developed? If not what do you recommend to be done.

Q2.Interms of redundancy, inconsistency and access problems do you think that


file-processing systems are good for banking applications?

Q3.How do you enforce integrity constraints such as the minimum amount of


money that is needed when you open a new account is 25.00 birr.

Q4.In banking systems do you think that every user has the right to access every
data. For example, is it possible for the guards in a bank to update the balance of
a customer? If not how can you enforce security measures to protect illegal
access?

Q5.Can you identify at least 5 disadvantages of file processing systems

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy