|
|
#include<stdio.h>
|
|
|
#include<stdlib.h> /*其它说明*/
|
|
|
#include<string.h> /*字符串函数*/
|
|
|
#include<Windows.h>
|
|
|
#define max 100
|
|
|
#define LEN 15
|
|
|
#define N 50
|
|
|
int k = 1, n = 0, m = 0;
|
|
|
|
|
|
typedef struct Bank {
|
|
|
char no[13];//卡号
|
|
|
char name[10];//姓名
|
|
|
char sex[8];//性别
|
|
|
int balance;//余额
|
|
|
char passwd[20];
|
|
|
} bank, ban[max];
|
|
|
void fileWrite(int n, ban s);
|
|
|
void modify() {
|
|
|
int j = 0;
|
|
|
FILE * fp;
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
ban s;
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
j++;
|
|
|
}
|
|
|
n = j;
|
|
|
int i, item, num;
|
|
|
int age;
|
|
|
char sex1[8], s1[LEN + 1], s2[LEN + 1],passwd1[20],age1[10];
|
|
|
float score1;
|
|
|
printf("请输入要修改的用户的卡号:\n");
|
|
|
scanf("%s", s1);
|
|
|
for (i = 0; i<n; i++) {
|
|
|
if (strcmp(s[i].no, s1) == 0) { /*比较字符串是否相等*/
|
|
|
num = i;
|
|
|
printf("------------------\n");
|
|
|
printf("1.修改姓名\n");
|
|
|
printf("2.修改性别\n");
|
|
|
printf("3.修改密码\n");
|
|
|
printf("4.退出本菜单\n");
|
|
|
printf("------------------\n");
|
|
|
while (1) {
|
|
|
printf("请选择子菜单编号:");
|
|
|
scanf("%d", &item);
|
|
|
switch (item) {
|
|
|
case 1:
|
|
|
printf("请输入新的姓名:\n");
|
|
|
scanf("%s", s2);
|
|
|
strcpy(s[num].name, s2);
|
|
|
fileWrite(n, s);
|
|
|
break;
|
|
|
case 2:
|
|
|
printf("请输入新的性别:\n");
|
|
|
scanf("%s", &sex1);
|
|
|
strcpy(s[num].sex, sex1);
|
|
|
fileWrite(n, s);
|
|
|
break;
|
|
|
case 3:
|
|
|
printf("请输入新的密码:\n");
|
|
|
scanf("%s", &passwd1);
|
|
|
strcpy(s[num].passwd, passwd1);
|
|
|
fileWrite(n, s);
|
|
|
break;
|
|
|
case 4:
|
|
|
return;
|
|
|
default:
|
|
|
printf("请在1-4之间选择\n");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
printf("没有该卡号!!!\n");
|
|
|
}
|
|
|
}
|
|
|
system("pause");
|
|
|
}
|
|
|
void insert() {
|
|
|
int i, a, b;
|
|
|
printf("请输入待增加的用户数:\n");
|
|
|
scanf("%d", &n);
|
|
|
FILE * fp;
|
|
|
if ((fp = fopen("a.txt", "at")) == NULL) return;
|
|
|
ban s;
|
|
|
for (i = 0; i<n; i++) {
|
|
|
printf("\n请输入第%d个用户的卡号:", i + 1);
|
|
|
scanf("\n%s", &s[i].no);
|
|
|
printf("\n请输入第%d个用户的姓名:", i + 1);
|
|
|
scanf("%s", &s[i].name);
|
|
|
printf("\n请输入第%d 个用户的性别:", i + 1);
|
|
|
scanf("%s", &s[i].sex);
|
|
|
printf("\n请输入第%d 个用户的密码:", i + 1);
|
|
|
scanf("%s", &s[i].passwd);
|
|
|
//写入文件
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
|
fprintf(fp, "%s %s %s %s %d \n", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance = 0);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
printf("添加成功!!!\n");
|
|
|
system("pause");
|
|
|
}
|
|
|
void del() {
|
|
|
int j = 0;
|
|
|
FILE * fp, *fp1;
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
ban s;
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
j++;
|
|
|
}
|
|
|
n = j;
|
|
|
|
|
|
int i, flag = 0;
|
|
|
char s1[LEN + 1];
|
|
|
printf("请输入要删除用户的卡号:\n");
|
|
|
scanf("%s", s1);
|
|
|
for (i = 0; i<n; i++) {
|
|
|
if (strcmp(s[i].no, s1) == 0) {
|
|
|
flag = 1;
|
|
|
for (j = i; j<n - 1; j++) {
|
|
|
strcpy(s[j].no, s[j + 1].no);
|
|
|
strcpy(s[j].name, s[j + 1].name);
|
|
|
s[j].balance = s[j + 1].balance;
|
|
|
strcpy(s[j].sex, s[j + 1].sex);
|
|
|
strcpy(s[j].passwd, s[j + 1].passwd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (flag == 0)
|
|
|
printf("该卡号不存在!\n");
|
|
|
if (flag == 1) {
|
|
|
n--;
|
|
|
fileWrite(n, s);
|
|
|
fclose(fp);
|
|
|
printf("删除成功,显示结果请选择菜单\n");
|
|
|
|
|
|
}
|
|
|
system("pause");
|
|
|
}
|
|
|
void seek() {
|
|
|
int j = 0,flag=0;
|
|
|
FILE * fp;
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
ban s;
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
j++;
|
|
|
}
|
|
|
n = j;
|
|
|
int i = 0, item;
|
|
|
char s1[13], s2[20];
|
|
|
lable1:
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
scanf("%s", &s1);
|
|
|
if (strcmp(s1, "0") == 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
for (i = 0; i < n; i++) {
|
|
|
if (strcmp(s[i].no, s1) == 0) {
|
|
|
printf("请输入密码:\n");
|
|
|
scanf("%s", &s2);
|
|
|
if (strcmp(s[i].passwd, s2) == 0) {
|
|
|
printf("您查询的账户信息如下\n");
|
|
|
printf("卡号:%s\n", s[i].no);
|
|
|
printf("姓名:%s\n", s[i].name);
|
|
|
printf("性别:%s\n", s[i].sex);
|
|
|
printf("余额:%d\n", s[i].balance);
|
|
|
flag = 2;
|
|
|
break;
|
|
|
}
|
|
|
else {
|
|
|
printf("您输入的密码错误,请重新输入\n");
|
|
|
goto lable1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (flag != 2) {
|
|
|
printf("您输入的用户名不存在,请重新输入\n");
|
|
|
goto lable1;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
|
|
|
system("pause");
|
|
|
}
|
|
|
void save()
|
|
|
{
|
|
|
int j = 0,flag=0;
|
|
|
FILE * fp;
|
|
|
if ((fp = fopen("a.txt", "r+")) == NULL) return;
|
|
|
ban s;
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
j++;
|
|
|
}
|
|
|
n = j;
|
|
|
struct Bank *str = s;
|
|
|
int i = 0, item,save,aftersave;
|
|
|
char s1[13], s2[20];
|
|
|
lable1:
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
scanf("%s", &s1);
|
|
|
if (strcmp(s1, "0") == 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
for (i = 0; i < n; i++) {
|
|
|
if (strcmp(s[i].no, s1) == 0) {
|
|
|
printf("请输入密码:\n");
|
|
|
scanf("%s", &s2);
|
|
|
if (strcmp(s[i].passwd, s2) == 0) {
|
|
|
printf("请输入您要存款的金额:");
|
|
|
scanf("%d",&save);
|
|
|
s[i].balance = save + s[i].balance;
|
|
|
fileWrite(n, s);
|
|
|
fclose(fp);
|
|
|
printf("存款成功!\n");
|
|
|
printf("当前余额为%d元\n",s[i].balance);
|
|
|
flag = 2;
|
|
|
break;
|
|
|
}
|
|
|
else {
|
|
|
printf("您输入的密码错误,请重新输入\n");
|
|
|
goto lable1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (flag != 2) {
|
|
|
printf("您输入的用户名不存在,请重新输入\n");
|
|
|
goto lable1;
|
|
|
}
|
|
|
|
|
|
|
|
|
system("pause");
|
|
|
}
|
|
|
void fileWrite(int n, ban s) {
|
|
|
FILE *fp1;
|
|
|
int i;
|
|
|
if ((fp1 = fopen("a.txt", "w")) == NULL) return;
|
|
|
for (i = 0; i<n; i++) {
|
|
|
fprintf(fp1, "%s %s %s %s %d ", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance);
|
|
|
}
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
/* 界面*/
|
|
|
void menu() {
|
|
|
int num;
|
|
|
printf("------------------------------------------------------\n");
|
|
|
printf("------------------------------------------------------\n");
|
|
|
printf("-------------------银行管理系统-----------------------\n");
|
|
|
printf("------------------------------------------------------\n");
|
|
|
printf("------------------------------------------------------\n");
|
|
|
Sleep(3000);
|
|
|
system("CLS");
|
|
|
printf("------------------------------------------------------\n");
|
|
|
printf("----------------------请选择功能----------------------\n");
|
|
|
printf("-------------------1.查询 2.存款--------------------\n");
|
|
|
printf("-------------------3.取款 4.开户--------------------\n");
|
|
|
printf("-------------------5.销户 6.账户信息修改------------\n");
|
|
|
printf("-----------------------0.退出-------------------------\n");
|
|
|
printf("请选择菜单编号:");
|
|
|
scanf("%d", &num);
|
|
|
switch (num) {
|
|
|
case 0:
|
|
|
exit(0);
|
|
|
break;
|
|
|
case 1:
|
|
|
seek();
|
|
|
break;
|
|
|
case 2:
|
|
|
save();
|
|
|
break;
|
|
|
case 3:
|
|
|
break;
|
|
|
case 4:
|
|
|
insert();
|
|
|
break;
|
|
|
case 5:
|
|
|
del();
|
|
|
break;
|
|
|
case 6:
|
|
|
modify();
|
|
|
break;
|
|
|
default:
|
|
|
printf("请在0-6之间选择\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
while (k) {
|
|
|
system("cls");
|
|
|
menu();
|
|
|
}
|
|
|
system("pause");
|
|
|
return 0;
|
|
|
} |