/
Overloaded_Constructor.cpp
74 lines (68 loc) · 1.3 KB
/
Overloaded_Constructor.cpp
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
#include<bits/stdc++.h>
using namespace std;
enum acc_type
{
CURRENT=1,SAVINGS=2,FIXED=3
};
class acc
{
private:
int acc_id;
char name[25];
acc_type type;
public:
acc();
acc(int id,char *name,int t);
acc(ifstream &fin);
void display(void);
~acc(){};
};
acc::acc()
{
int type;
cout << endl << "Enter Account ID: #";
cin >> acc_id;
cout <<endl << "Enter the name of Account Holder :";
cin>>name;
cout << endl << "Enter Account Type (CURRENT=1,SAVINGS=2,FIXED=3): ";
cin >> type;
acc::type = (acc_type) type;
}
acc :: acc(int id,char *name,int t)
{
acc_id=id;
strcpy(acc::name,name);
acc::type = (acc_type) t;
}
acc::acc(ifstream& fin)
{
fin.open("C:\\Users\\Md. Shah Arafat\\overloaded.txt",ios::in);
if (!fin)
{
cout<<endl<<"File Error : File Not Found...." << endl;
cout<<endl<<"So,No record is created,object is empty or garbage...";
return;
}
fin>>acc_id;
fin>>name;
int type;
fin>>type;
acc::type = (acc_type) type;
}
void acc::display()
{
static int out_no=1;
cout<<endl<<"Output#"<<out_no++;
char *type_name[] = {"","CURRENT","SAVINGS","FIXED"};
cout<<endl<<"Account id#"<<acc_id<<endl;
cout<<"Name : "<<name<<endl;
cout<<"Account type: "<<type_name[type]<<endl;
}
int main()
{
ifstream fin;
acc a1,a2(2,"Niton",2),a3(fin);
a1.display();
a2.display();
a3.display();
}