C语言银行储蓄系统源码

2025-05-27 0 16

本文为大家分享了C语言银行储蓄系统源码,实现银行的各项功能,供大家参考,具体内容如下

?

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

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414
#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <string.h>

void openaccount();//开户

void save();//存款

void withdraw();//取款

void showAccount();//查询

void transferAccounts();//转账

void reportLoss(); //挂失

void cancelLoss(); //解除挂失

void cancelAccount(); //注销账户

void updatePassword(); //更改密码

int load();//登陆账号

int accountnum=0;//定义全局变量,用来计算账户数目

int nowaccount=0;//登录成功是的账户

struct Bank

{

char account[20]; //账号

char password[10]; //密码

char name[20]; //用户名

int balance;//账户余额

int state;//状态

}; //结构体

struct Bank banks[100];

int load()

{

int right=0,i=0,j;

int r1,r2;

char ch;

char account1[20]= {0};

char password1[10]= {0};

printf("登陆\\n请输入账号:\\n");

scanf("%s",account1);

printf("请输入密码:\\n");

while((ch=getch())!='\\r')

{

password1[i++]=ch;

putchar('*');

}

for(j=0; j<accountnum; j++)

{

r1=strcmp(account1,banks[j].account);

r2=strcmp(password1,banks[j].password);

if(r1==0&&r2==0)

{

nowaccount=j;

if(banks[j].state==0)

{

printf("登录成功!\\n");//登录成功

right=1;

}

else if(banks[j].state==1)

{

printf("您的账户处于挂失状态,请解挂\\n");

right=3;

}

else if(banks[j].state==2)

{

printf("账户已经销户\\n");

right=2;

}

break;

}

}

if(right==0)

printf("登陆失败!\\n");

return right;

}

int main()

{

int i=0,num;

char a[100];

FILE *fp;

if((fp=fopen("account.txt","r"))==NULL)

{

if((fp=fopen("account.txt","w"))==NULL)

{

printf("失败!\\n");

exit(1);

}

}

while(fscanf(fp,"%s%s%s%d%d",banks[i].account,banks[i].name,banks[i].password,&banks[i].balance,&banks[i].state)!=EOF)

{

accountnum++;

i++;

}

fclose(fp);

printf("欢迎来到我的银行\\n");

while(1)

{

printf("请选择业务:\\n");

printf("1.开户 2.存款 3.取款\\n");

printf("4.查询 5.转账 6.挂失\\n");

printf("7.解挂 8.销户 9.改密\\n");

printf("-1.退出\\n");

scanf("%s",a);

num=atoi(a);

if(num==1)

openaccount();//开户

else if(num==2)

save();//存款

else if(num==3)

withdraw();//取款

else if(num==4)

showAccount();//查询

else if(num==5)

transferAccounts();//转账

else if(num==6)

reportLoss(); //挂失

else if(num==7)

cancelLoss(); //解挂

else if(num==8)

cancelAccount(); //注销账户

else if(num==9)

updatePassword(); //更改密码

else if(num==-1)

{

printf("欢迎下次再来\\n");

break;

}

else

printf("抱歉,没有此业务\\n");

}

if((fp=fopen("account.txt","w"))==NULL)

{

printf("失败!\\n");

exit(1);

}

for(i=0; i<accountnum; i++)

{

fprintf(fp,"%s\\t%s\\t%s\\t%d\\t%d\\n",banks[i].account,banks[i].name,banks[i].password,banks[i].balance,banks[i].state);

}

fclose(fp);

return 0;

}

void openaccount()

{

int i=0,j=0;

int r;

char ch;

char password1[10]= {0};

printf("账户(十位数):\\n");

scanf("%s",banks[accountnum].account);

while(banks[accountnum].account[i]!='\\0')

i++;

if(i!=10)

{

printf("输入账号有误\\n");

return;

}

i=0;

printf("姓名:\\n");

scanf("%s",banks[accountnum].name);

printf("密码:\\n");

while((ch=getch())!='\\r')

{

banks[accountnum].password[i++]=ch;

putchar('*');

}

printf("\\n");

printf("再次输入密码:\\n");

while((ch=getch())!='\\r')

{

password1[j++]=ch;

putchar('*');

}

printf("\\n");

r=strcmp(banks[accountnum].password,password1);

if(r!=0)

{

printf("两次密码不相同,开户失败!\\n");

return;

}

banks[accountnum].balance=0;

banks[accountnum].state=0;

accountnum++;

printf("开户成功\\n");

}

void save()

{

if(load()!=1)

return;

char addmoney[10];//存入金额

int money;//将字符型转化为int型

int i=0;

printf("存入金额:\\n");

scanf("%s",addmoney);

while(addmoney[i]!='\\0')

{

if(addmoney[i]<'0'||addmoney[i]>'9')

{

printf("输入格式错误!\\n");

return;

}

i++;

}

while(addmoney[i]!='\\0')

{

if(i>9)

{

printf("金额超限\\n");

return;

}

i++;

}

money=atoi(addmoney);

if(money==0)

{

printf("存款失败\\n");

return;

}

else

{

banks[nowaccount].balance+=money;

printf("存款成功\\n");

}

}

void withdraw()

{

if(load()!=1)

return;

char reducemoney[10];//取款金额

int money,i=0;

printf("请输入取款金额\\n");

scanf("%s",reducemoney);

while(reducemoney[i]!='\\0')

{

if(reducemoney[i]<'0'||reducemoney[i]>'9')

{

printf("输入格式错误!\\n");

return;

}

i++;

}

while(reducemoney[i]!='\\0')

{

if(i>9)

{

printf("金额超限\\n");

return;

}

i++;

}

money=atoi(reducemoney);

if(money==0)

{

printf("取款失败\\n");

return;

}

else

{

if(money>banks[nowaccount].balance)

printf("您的账户没有这么多余额,取款失败!\\n");

else

{

banks[nowaccount].balance-=money;

printf("取款成功\\n");

}

}

}

void showAccount()

{

if(load()!=1&&load()!=2)

return;

printf("您的账户信息如下:\\n");

printf("账号:%s\\t余额:%d\\n",banks[nowaccount].account,banks[nowaccount].balance);

}

void transferAccounts()

{

if(load()!=1)

return;

char account1[20];

int i,judge=0,money,a;

char tramoney[10];

printf("请输入您转入的账户\\n");

scanf("%s",account1);

for(i=0; i<accountnum; i++)

{

if(strcmp(account1,banks[i].account)==0)

{

a=i;

judge=1;

break;

}

}

if(judge!=1)

{

printf("没有发现此账户\\n");

return;

}

printf("请输入转账金额\\n");

scanf("%s",tramoney);

while(tramoney[i]!='\\0')

{

if(tramoney[i]<'0'||tramoney[i]>'9')

{

printf("输入格式错误!\\n");

return;

}

i++;

}

while(tramoney[i]!='\\0')

{

if(i>9)

{

printf("金额超限\\n");

return;

}

i++;

}

money=atoi(tramoney);

if(money==0)

{

printf("转账失败\\n");

return;

}

else

{

if(money>banks[nowaccount].balance)

printf("您的账户没有这么多余额,转账失败!\\n");

else

{

banks[nowaccount].balance-=money;

banks[a].balance+=money;

printf("转账成功\\n");

}

}

}

void reportLoss()

{

if(load()!=1)

return;

banks[nowaccount].state=1;

printf("挂失成功\\n");

}

void cancelLoss()

{

int judge=0;

if(load()==3)

{

printf("立即解挂请按1,退出请按0\\n");

scanf("%d",&judge);

if(judge==1)

{

banks[nowaccount].state=0;

printf("解挂成功\\n");

}

}

else if(load()==1)

printf("账户正常\\n");

}

void cancelAccount()

{

int r;

r=load();

if(r==2)

{

printf("账户已经销户\\n");

return;

}

else if(r==3||r==0)

return;

else if(r==1)

{

printf("请将您的账户余额取完\\n");

banks[nowaccount].state=2;

banks[nowaccount].balance=0;

printf("注销成功\\n");

}

}

void updatePassword()

{

char newpassword1[10]= {0},newpassword2[10]= {0};

int i=0,j=0,r;

char ch;

if(load()!=1)

return;

printf("请输入新密码\\n");

while((ch=getch())!='\\r')

{

newpassword1[i++]=ch;

putchar('*');

}

printf("\\n");

printf("再次输入密码:\\n");

while((ch=getch())!='\\r')

{

newpassword2[j++]=ch;

putchar('*');

}

printf("\\n");

r=strcmp(newpassword1,newpassword2);

printf("r:%d",r);

if(r!=0)

{

printf("两次密码不相同,改密失败!\\n");

return;

}

i=0;

while(newpassword1[i]!='\\0')

{

banks[nowaccount].password[i]=newpassword1[i];

i++;

}

printf("改密成功\\n");

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 C语言银行储蓄系统源码 https://www.kuaiidc.com/73006.html

相关文章

发表评论
暂无评论