Skip to main content

C++ Program to implement File Handling With Class Objects

Q32. Program to implement File Handling With Class Objects:

Define a class to represent a bank account. Include the following members:
  i) Depositor Name
 ii) Account Number
iii) Balance Amount

Member Function
  i) To Assign Initial values(opening balance Rs. 1000 by default)
 ii) To deposit an amount
iii) To withdraw an amount(if possible)
iv) To display the current balance

Write a file based program to store the records of at least ten accounts in “ACCOUNT_DETAIL” data file and perform the required manipulations- DEPOSIT, WITHDRAW & BAL_ENQUIRY using the file on a given account. The changes after each deposit and withdrawal should be updated in the given file.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include
#include
#include
#include

const int MAX = 100;

enum bool{_false, _true};

class Cbank{
    private:
        int accNo;
        char name[20];
        float bal;
    public:
        Cbank() : accNo(100){}
        void getAcc(int );
        bool accPresent(int );
        void saveBal(int, float );
        void dispAcc() const;
        void dispAll() const;
    };

void Cbank :: getAcc(int i){
    accNo += i;
    cout<<"\n Enter Name: ";
    cin>>name;
    cout<<"\n Enter Amount for opening Acc.: ";
    cin>>bal;
    }



bool Cbank :: accPresent(int _acnt){
    if(accNo == _acnt)
        return _true;
    else
        return _false;
    }

void Cbank :: saveBal(int type, float _amt){
    if(type == 2){      // Deposit.
        bal += _amt;
        cout<<"\n Balance Updated.";
        }
    else if(type == 3){ // Withdrawl.
        if(bal >= _amt){
            bal -= _amt;
            cout<<"\n Balance Updated.";
            }
        else
            cout<<"\n Not Enough Funds on Account, SORRY !!";
        }
    }

void Cbank :: dispAcc() const{
    cout<<"\n Account Information:-";
    cout<<"\n ~~~~~~~~~~~~~~~~~~~";
    cout<<"\n Account No.: "<    cout<<"\n Holders Name: "<    cout<<"\n Balance: "<    }

void Cbank :: dispAll() const{
    cout<    }

void main(){
    int ch, i, _tot = 0;
    int _acc;
    float _amt;
    char nx;
    bool found;
    Cbank *Obank = new(Cbank[MAX]);
    fstream fstr;
    fstr.open("Bank.txt", ios::in | ios::nocreate);
    if(fstr){
        while(fstr){
            fstr.read((char *) &Obank[_tot],
sizeof(Obank[_tot]));
            _tot++;
            }
        _tot -= 2;
        }
    fstr.close();
    // Data Retrieved form Disk.
    while(1){
        clrscr();
        cout<<"\n BANK AUTOMATION";
        cout<<"\n ~~~~~~~~~~~~~~~";
        cout<<"\n 1 -> Create Account.";
        cout<<"\n 2 -> Deposit Money.";
        cout<<"\n 3 -> Withdrawl Money.";
        cout<<"\n 4 -> Balance Inqury.";
        cout<<"\n 5 -> Display Accounts.";
        cout<<"\n 6 -> Exit.";
        cout<<"\n\n Enter your choice: ";
        cin>>ch;
        clrscr();
        switch(ch){
            case 1: // Create Acc.
                while(_tot < MAX){
                    cout<<"\n Account No.: "<<_tot p="">                    Obank[_tot].getAcc(_tot);
                    cout<<"\n Want to add more (y/n): ";
                    cin>>nx;
                    _tot++;
                    if(nx == 'n')
                        break;
                    }
                break;
            case 2: // Deposit Money.
                found = _false;
                cout<<"\n Enter Account No: ";
                cin>>_acc;
                for(i=0; i<=_tot; i++){
                    if(Obank[i].accPresent(_acc)){
                        found = _true;
                        break;
                        }
                    }
                if(!found){
                    cout<<"\n Account Not Found.";
                    break;
                    }
                else{
                    cout<<"\n Enter Amount to Deposit: ";
                    cin>>_amt;
                    Obank[i].saveBal(ch, _amt);
                    }
                break;
            case 3: // Withdrawl Money.
                found = _false;
                cout<<"\n Enter Account No: ";
                cin>>_acc;
                for(i=0; i<=_tot; i++){
                    if(Obank[i].accPresent(_acc)){
                        found = _true;
                        break;
                        }
                    }
                if(!found){
                    cout<<"\n Account Not Found.";
                    break;
                    }
                else{
                    cout<<"\n Enter Amount to Withdrawl:";
                    cin>>_amt;
                    Obank[i].saveBal(ch, _amt);
                    }
                break;
            case 4: // Balance Inquiry.
                found = _false;
                cout<<"\n Enter Account No: ";
                cin>>_acc;
                for(i=0; i<=_tot; i++){
                    if(Obank[i].accPresent(_acc)){
                        found = _true;
                        break;
                        }
                    }
                if(!found){
                    cout<<"\n Account Not Found.";
                    break;
                    }
                else{
                    Obank[i].dispAcc();
                    }
                break;
            case 5: // Display Acc.
                cout<<"\n Account Information:-";
                cout<<"\n ~~~~~~~~~~~~~~~~~~~";
                cout<<"\n ACC No."<    <<"NAME"<                cout<<"\n``````````````````````````````````
  ``````````````````````````````````";
                for(i=0; i<_tot i="" p="">                    Obank[i].dispAll();
                break;
            case 6: // Exit;
                fstr.open("Bank.txt", ios::out);
                for(i=0; i<=_tot; i++)
                    fstr.write((char *) &Obank[i],
sizeof(Obank[i]));
                fstr.close();
                // Data Saved to Disk.
                delete []Obank;
                exit(1);
            default:
                cout<<"\n Enter Appropriate Choice.";
            } // end of switch.
        getch();
        } // end of while.
    } // end of main.

Comments

Popular posts from this blog

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

what is LOREM ipsum and why do designers use it

What is Lorem Ipsum? Lorem Ipsum  is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now...

DOWNLOAD SOFTWARES, GAMES , MUCH MORE BY BYPASS PAYPAL PAYMENT

Bypass Paypal Payment: Now Download, Software, Games. etc for free without paying any money. We all know that we need to pay via Paypal for download various things from Internet like Games, Ebooks, Software, etc. However this method works only few websites that have very weak security. So Today you are going to learn another method that is "Bypassing Paypal Payment". STEPS Just paste the below code in your address bar the site where the option come to pay Via Paypal CODE " javascript:top.location=document.getElementsByName('return')[0].value; javascript:void(0) " If this code worked out for you, you will be redirected to the download page, Elase bad luck, try another site SOME IMPORTANT TIPS This method is working only on those sites with weak security feature. Make sure that your browser supports JavaScript. one website on which this method are works you can try these sites which have weak security sites take it from fallowing link pastesite.com/22775

Creating an Executable Jar File

Creating a jar File in  Eclipse In  Eclipse  Help contents, expand "Java development user guide" ==> "Tasks" ==> "Creating JAR files."  Follow the instructions for "Creating a new JAR file" or "Creating a new runnable JAR file."The  JAR File  and  Runnable JAR File  commands are for some reason located under the  File menu: click on  Export...  and expand the  Java  node. Creating a jar File in  JCreator You can configure a "tool" that will automate the jar creation process.  You only need to do it once. Click on  Configure/Options . Click on  Tools  in the left column. Click  New , and choose  Create Jar file . Click on the newly created entry  Create Jar File  in the left column under  Tools . Edit the middle line labeled  Arguments:  it should have cvfm $[PrjName].jar manifest.txt *.class Click OK. Now set...

Exception Handling in Java

Exception Handling() it is an event that stops the normal flow of execution of the program and terminates the program abnormally. Exception always occurs at runtime. There Is two type of Exception: Checked Exception.:-The exception which is checked by the compiler at the compilation time. Ex: IOException,ClassNotFoundException. Unchecked Exception: The Exception which Cant be checked by the compiler at the compilation time and directly occurs at runtime is called an unchecked Exception. Ex:NullPointerException,StringIndexOutOfBoundsException. Error: Error is the type of unchecked Exception which occurs due to programmers mistake, end-user input mistake, resource unavailability or network problem etc. OutOfMemoryError StackOverFlowError etc. 5 keywords to handle Exception: try catch finally throw throws possible combination: try-catch try-catch-catch try-catch-finally try finally try-...

5 Best Popular Posts Widgets For Blogger

Adding the Popular Posts Widget for Blogger Just click on your blog title, access the "Layout" menu, click "Add a Gadget" and choose "Popular Posts". A window will appear asking you to configure the widget by choosing which posts you'll feature (e.g. those that were most viewed in the past 7 days or 30 days or from the beginning of your blog). You'll also be asked to choose how many posts you'll feature in your Popular Posts section and select if you'll show the post title only or along with the image thumbnail and/or the snippet. (Remember that each widget style has different requirements, so follow the styles and instructions carefully to find out if you need the snippet and image thumbnail or not). Popular Posts Style 1 - Box within a box This is an interesting widget style since it uses your snippet and image thumbnail in a unique way. Your snippet is written in opaque text and placed in a small transparent box. This, in turn, ...

Streamlining Java Web Application Deployment with React WAR Generator

In the ever-evolving world of web development, managing builds and deployments can often be cumbersome and error-prone. Today, we're excited to introduce a tool designed to simplify and streamline this process: the React WAR Generator . What is the React WAR Generator? The React WAR Generator is a Python-based tool that automates the creation of WAR (Web Application Archive) files for Java web applications. It caters specifically to frontend projects built with React or similar frameworks, making it easier to package and deploy your web applications to a Tomcat server. Key Features Profile-Based Builds : With support for multiple profiles ( dev , test , prod , default ), you can build your application according to different environments and configurations. Version File Generation : Optionally generate a version file that integrates versioning information directly into your TypeScript files, ensuring your build versions are always up-to-date. Tomcat Deployment : Simplify your deploy...

Windows 10 1703 Fall Creator update/upgrage brings NEW UI ... the fluent Ui

Microsoft is planning to implement these subtle design changes gradually. Some are already available in new updates to existing Windows 10 apps, and more will start to appear in Windows itself as Microsoft updates the operating system with the Fall Creators Update and future updates. "It's going to be a journey," says Microsoft director Aaron Woodman, noting that these design changes will appear over time in Windows and other products. On stage at Build today, Microsoft's Joe Belfiore demonstrated a number of Fluent Design changes. "You're going to see Fluent Design show up in the Windows shell, in our apps, and across devices," explains Joe Belfiore. Microsoft is focusing on light, depth, motion, material, and scale for its Fluent Design, with subtle changes that make the design feel like it's moving during interactions in Windows. An inking demo showed how Microsoft is bringing the pen experience across the entirety of Windows, allowing...

Binary Search Tree in Java implementation (reference based, dynamic memory)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 import java.util.Scanner ; class BST { static BST . Node root = null ; public void insert ( int num ) { if ( root == null ) { root = new BST . Node ( num ); } else { // root node is not empty BST . Node temp = root ; while ( temp != null ) { if ( num <= temp . getVal ()) { if ( temp . getLeft () != null ) temp = temp . getLeft (); ...