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

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

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

How to Bypass Right Click Block on Any Website

In order to block the right-click activity, most websites make use of JavaScript which is one of the popular scripting languages used to enhance functionality, improve user experience and provide rich interactive features. In addition to this, it can also be used to strengthen the website’s security by adding some of the simple security features such as  disabling right-click ,  protecting images ,  hiding or masking parts of a web page  and so on. How JavaScript Works? Before you proceed to the next part which tells you how to disable the JavaScript functionality and bypass any of the restrictions imposed by it, it would be worthwhile for you to take up a minute to understand how JavaScript works. JavaScript is a client side scripting language (in most cases), which means when loaded it runs from your own web browser. Most modern browsers including IE, Firefox, Chrome and others support JavaScript so that they can interpret the code and carry out action...

[ FREE ][ more than 15 gb for free ] Offcloud vs Bitport vs Seedr :which is best among three to direct download from torrent to cloud storages like google drive ,one drive ,dropbox etc.

Offcloud : [RECOMMENDED BY ME] [AS OF 17-july-2017] Offcloud is a little different from the rest of the providers we’ve looked at, as it isn’t focused on downloading torrents. The company markets itself as “a simple, elegant and intuitive  SaaS  to retrieve any data from the cloud.” We were surprised at the amount of different sources Offcloud supports for downloading, and it even has a ticket box that allows users to suggest new sites to support.  pros: best part you can direct download to your cloud storage like google drive , mega.NZ,one drive ,Dropbox,etc.. Cons: only 3 links permitted to download over free account ..that limit is per months .. you can buy a premium account to bypass this .............. else you can also use a fake email generator and add a remote account to cloud download bypasssing above limit.. Note that Off-cloud doesn’t intend to act as a “seedbox,” which is a server used to boost a user’s ration on private trackers by perpetua...

Batch file to C++ souce code generator ...

Batch file to C++ souce code generator ... Well this project was made upon CODEBLOCK using c++ HERE IS THE SOURCE CODE: download it as .cpp form by clicking here.. mirror 1                                                   mirror 2. One drive if YOu want the exe file only then click here (500 KB) Mirror 1. MULTCLOUD  FOR PASSWORD TO THIS SITE VISIT THE FOLLOWING LINK OR SUMBIT THE FORM BELOW  >>> LINK :   https://goo.gl/forms/DiQHvEjfavsaU18U2                              or Loading...

Binary to Decimal using Stack in C

CODE 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 #include <stdio.h> #include <stdlib.h> #define SIZE 8 int STACK[SIZE],TOP =- 1 ; int power ( int i) { int res = 1 ; while (i -- ) { res = res * 2 ; } return res; } void push ( int n) { if (TOP == SIZE) printf( "OVerflow" ); else STACK[ ++ TOP] = n; } int pop () { if (TOP ==- 1 ) return - 1 ; else return STACK[TOP -- ]; } void main () { int num,i = 0 ,arr[SIZE],j,res = 0 ,temp; printf( "Enter the number" ); scanf( "%d" , & num); printf( " \n Entered number=%d \n " ,num); while (num) { arr[i ++ ] = num % 10 ; num /= 10 ; } for (j = i - 1 ;j >= 0 ;j -- ) push(arr[j]); for (j = 0 ;j < i;j ++ ) { res = res + (pop() * power(j)); } printf( " \n Result=%d" ,res); getchar...

Facebook's First Layout

... More about fb: Facebook paid a whooping $8.5 Million to buy "Fb.com" domain!! So next time instead of typing "facebook.com" you can just type in "Fb.com" to save time!! Facebook acquired the domain sometime last year from the American Farm Bureau Federation, which uses fb.org as its primary domain. At its annual meeting in Atlanta, the non-profit revealed that it earned $8.5 million on the sale of fb.com The last high-profile domain purchase by Facebook was for Facebook.com, all the way back when it was known as TheFacebook. The company paid $200,000 in August 2005 to acquire the domain, 42.5 times less than what Facebook spent to acquire fb.com. While the Facebook.com purchase was expensive for the company back then, it’s an investment that has clearly paid off. The company is obviously hoping that fb.com will also pay off. source: https://en.wikipedia.org/wiki/File:Original-facebook.jpg

Android :Edittext Format space after Each 4 digit/Character

Replace EditText with your EditText Variable 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 EditText . addTextChangedListener ( new TextWatcher () { byte count1 = 0 ; byte count2 = 0 ; @Override public void beforeTextChanged ( CharSequence s , int start , int count , int after ) { count1 = ( byte ) s . length (); } @Override public void onTextChanged ( CharSequence s , int start , int before , int count ) { count2 = ( byte ) s . length (); } @Override public void afterTextChanged ( Editable s ) { String initial = EditText . getText (). toString (); ...

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