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...

python program to Print Starting Series OF Indian Mobile Number for a State or operator or both

import requests import urllib.request import time from bs4 import BeautifulSoup as bs import re url = ' https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India' state_to_extract = "UE" #if set to None all state is considered telecom_to_extracted = None #if set to none all operator from particular city is extracted response = requests . get(url) print (response) soup = bs(response . text, "html.parser" ) one_a_tag = soup . findAll( 'tr' )[ 35 :] lst = [] for k in one_a_tag: s = k . findAll( 'td' ) limit = len (s) i = 0 while True : if i == limit: break no = s[i] . text i += 1 if i == limit: break operator = s[i] . text i += 1 if i == limit: break state = s[i] . text i += 1 if i == limit: break res = f "{no} {operator} {state}" if state_to_extract is None : if telecom_to_extracted is None : lst . append(no) elif telecom_to_e...

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by majority of expert bloggers for their website monetization because it is a cookie based contextual advertising system that shows targeted ads relevant to the content and reader. As bloggers are paid on per click basis, they try various ad placements on the blog to  increase the revenue  and get maximum clicks on the ad units. Well, on some blogs, you might have seen Adsense ad units placed below the post title. Do you know why? It is because the area just below the post title gets the most exposure and is the best place to put AdSense ad units to increase  Click Through Rate (CTR). Even though ads below post title work like a charm but this doesn’t mean that it will work for you as well. If you want to find out the best AdSense ads placement for your blog, try experimenting by placing ads at various locations such as header, sidebar, footer, etc. You can try other  blog monetization methods  as well to effectively monetize y...

Java API call Example using GSON, org.json.json and Jackson [ Simple Get Call] and parsing result as JSON

import com.fasterxml.jackson.databind.JsonNode ; import com.fasterxml.jackson.databind.ObjectMapper ; import com.google.gson.* ; import org.json.JSONArray ; import org.json.JSONObject ; import java.io.* ; import java.net.HttpURLConnection ; import java.net.URL ; public class APICALL { public static void main (String[] args) throws IOException { // String url="https://mocki.io/v1/19a50724-c2e5-46a1-b457-543462cdfde2"; String url= "https://jsonplaceholder.typicode.com/users" ; String line ; StringBuilder resp= new StringBuilder() ; System. out .println(url) ; HttpURLConnection con= (HttpURLConnection) new URL(url).openConnection() ; con.setRequestMethod( "GET" ) ; con.setRequestProperty( "Accept" , "application/json" ) ; System. out .println(con.getResponseMessage()) ; System. out .println(con.getContentType()) ; InputStream inputStream=con.getInput...

Binary Search Tree in C++( dynamic memory based )

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 #include<bits/stdc++.h> using namespace std; struct bst { int val; bst * left, * right; }; bst * root = nullptr; void srch ( int num,bst * head) { if (head == nullptr){ cout << " \n Number is not present \a " << endl; return ; } if (head -> val == num) { cout << " \n Number is present \n\a " ; return ; } else { if (num < head -> val) srch(num,head -> left); else srch(num,head -> right); ...

Google Sheet/Google form Script to send automated Email to users

Well many of us want to send especially bloggers sometimes want to send automated replies to user 's ..but as usual, not everyone is a code geek or lovers ... so this is a small guide to How to use Google form with Google sheet to make an automated reply link....so follow the steps accordingly. STEP 1: GOTO google Forms ... and create a form ... in my case I just take users email id and how do they get to my site. 1. GOTO   https://docs.google.com/forms?usp=mkt_forms 2. login with your account. now choose blank form. 3. in Form title write your forms name, for example, let say my form. 4. in Form description write the description let say  A simple form ... 5. now go to setting and in general tab, check collect email address. and  click on save 6. (optional) you can also ask some basic question 7. now goto responses tab now click on create new spreadsheet button. (that green icon ..) in select response, destination cho...

How to open facebook through Uninor when it is blocked

Tweet Just Follow this steps . 1. Goto www.uninor.in 2. choose your circle 3.Goto  http://www.uninor.in/customer-care/Pages/customer-complaint-log.aspx 4. Now in new complaint just type your moblie number 5.now you will receive passwrod just type in and hit submit 7. NOW select as following as type as it in every box Complaint Type   -- Select --   DND Related   GPRS   Network Related   Tariff & VAS Related   Activation/ Deactivation   Barring/ Unbarring   Balance Related    Complaint Area   -- Select --   Activation / Deactivation   PC/Modem Connectivity   Usage / Charges related   GPRS issues   Non-Uninor sites   Complaint sub Area   -- Select --   Unable to browse   Unable to download   Please ensure all questions below are answe...

Download pocket tank delux with 295 weapons free total 295 weapons version 1.6

Download Pocket Tanks Deluxe Full Version Free With 295 Weapons Pack | Size: 30MB UPDATED 2019 /19/april Description: Pocket Tanks is a 1-2 player computer game for Windows and Mac OS X, created by Blitwise Productions, developer of Super DX-Ball and Neon Wars. Adapted from Michael Welch's earlier Amiga game Scorched Tanks, this newer version features modified physics, dozens of weapons ranging from simple explosive shells to homing missiles, and the ability to move the tank. It supports several expansion packs. At the moment, players can have up to 295 different weapons total. Pocket Tanks is often abbreviated as PTanks. Have Fun! NOTE: FILE NAME IS SCRAMBLED FOR AVOIDING HARD DETECTION & FILE TAKEN DOWN . How to Play: Best with 2 players on the same computer at school or at work. UPDATED LINK https://mirr.re/d/u1Y https://nl26.seedr.cc/ff_get/447027537/ptd16.295.exe?st=lUp-PbRp4YOwToHIOGwStQ&e=1555747979 http://www.uploadmagnet.com/7gfzhbyfe...

Python program to find Sexy primes

a,b=input("Enter the Range Seprated by space ->" ).split(' ') primes=list() for i in range(int(a),int(int(b)+1)):     flag=1     for j in range(2,i):         if i%j==0:             flag=0             break     if flag==1:         primes.append(i) count=0 for j in primes:     if j+6 in primes:         count+=1 print(count). example: 4 40 output 7