-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebit_card.h
201 lines (195 loc) · 4.15 KB
/
debit_card.h
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
195
196
197
198
199
200
201
#pragma once
#include <iostream>
#include <string.h>
#include "account.h"
#include <fstream>
using namespace std;
class Debit_card
{
long long int card_no;
int pin;
int acc_no;
char card_holder[25];
char acc_type;
public:
static long long int generate_cardnumber();
Debit_card(char *,int,char);
Debit_card();
int access();
void change_pin();
char get_type();
static int get_card(long long int,Debit_card &);
static int get_card(char *,Debit_card &);
void display();
long long int get_cardNum();
int get_AccountNum();
void set_data(char *name,int,char);
};
long long int Debit_card::get_cardNum()
{
return this->card_no;
}
char Debit_card::get_type()
{
return this->acc_type;
}
int Debit_card::get_card(char *name,Debit_card &d)
{
ifstream obj("debitcards.txt");
if(!obj.is_open())
{
return 0;
}
obj.read((char *)&d,sizeof(d));
while(!obj.eof())
{
if(!strcmp(d.card_holder,name))
{
return 1;
}
else
{
obj.read((char *)&d,sizeof(d));
}
}
if(!strcmp(d.card_holder,name))
{
return 1;
}
else
{
return 0;
}
}
int Debit_card::get_card(long long int card,Debit_card &d)
{
ifstream obj("debitcards.txt");
if(!obj.is_open())
{
return 0;
}
obj.read((char *)&d,sizeof(d));
while(!obj.eof())
{
if(d.card_no==card)
{
return 1;
}
else
{
obj.read((char *)&d,sizeof(d));
}
}
if(d.card_no==card)
{
return 1;
}
else
{
return 0;
}
}
long long int Debit_card::generate_cardnumber()
{
Debit_card d;
long long int count=1000;
ifstream obj("debitcards.txt");
if(!obj.is_open())
{
return count;
}
obj.read((char *)&d,sizeof(d));
while(!obj.eof())
{
count++;
obj.read((char *)&d,sizeof(d));
}
return count;
}
Debit_card::Debit_card()
{
card_no=0;
card_holder[0]='\0';
pin=-1;
acc_type=0;
acc_no=0;
}
int Debit_card::get_AccountNum()
{
return acc_no;
}
void Debit_card::set_data(char *name,int ac,char type)
{
this->acc_type=type;
card_no = Debit_card::generate_cardnumber();
cout<<"\nYour Card Number : "<<card_no;
strcpy(card_holder,name);
cout<<"\nEnter Your Pin : ";
cin>>pin;
this->acc_no=ac;
ofstream obj;
obj.open("debitcards.txt",ios::app);
obj.write((char *)this,sizeof(Debit_card));
obj.close();
}
Debit_card::Debit_card(char *name,int no,char type)
{
this->acc_type=type;
card_no = Debit_card::generate_cardnumber();
cout<<"\nYour Card Number : "<<card_no;
strcpy(card_holder,name);
cout<<"\nEnter Your Pin : ";
cin>>pin;
while(!(pin>=1000 && pin<=9999))
{
cout<<"\nEnter a Valid Pin Number for your account : ";
cin>>pin;
}
this->acc_no=no;
ofstream obj;
obj.open("debitcards.txt",ios::app);
obj.write((char *)this,sizeof(Debit_card));
obj.close();
}
void Debit_card::display()
{
cout<<"Card No : "<<card_no<<endl;
cout<<"Account type : "<<acc_type<<endl;
cout<<"Holder : "<<card_holder<<endl;
// cout<<"Pin : "<<pin<<endl<<endl;
}
int Debit_card::access()
{
int pin,count=4;
cout<<"\nEnter your Pin : ";
cin>>pin;
while(1)
{
if(pin==this->pin)
{
return 1;
}
count--;
if(count==0)
{
break;
}
cout<<"\nInvalid Pin...Re-Enter pin : ";
cin>>pin;
}
cout<<"\nToo many Invalid Attempts...Contact your nearest branch !\n";
return 0;
}
void Debit_card::change_pin()
{
if(access())
{
cout<<"\nEnter your new Pin : ";
cin>>pin;
fstream obj;
obj.open("debitcards.txt",ios::out | ios::in);
int count=this->card_no-1000;
obj.seekp(count*sizeof(Debit_card),ios::beg);
obj.write((char *)this,sizeof(Debit_card));
}
}