Lab Manual 1
Lab Manual 1
File Processing
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.
Data hierarchy:
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.
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.
ios::ate Open a file for output and move the read/write control to
the end of 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.
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.
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
char data[100];
// again read the data from the file and display it.
infile >> data;
cout << data << endl;
return 0;
}
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.
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?