求用c语言编写的程序,最好带着注释(越详细越好!!)
2个回答
2013-12-19
展开全部
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"conio.h"
#define N 20
struct depositor
{char num[20];<br> char name[20];<br> char per[20];<br> float sec;<br> float mon;<br>};
void menu();
int reads(struct depositor dep[N]);
void save(struct depositor dep[N],int n);
void add();
void del();
void change();
void show();
void main()
{
int n;
while(1)
{
menu();
printf("\n 请输入您要选择的操作序号,按回车键确认:");
scanf("%d",&n);
switch(n)
{
case 1: add();break;
case 2: show();break;
case 3: del();break;
case 4: change();break;
case 5: exit(0);
default: printf("输入错误,请输入列表中存在的序号!\n ");
}
}}
void menu()
{
printf(" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ");
printf("\n ************************* 银行个人账户管理系统*************************** ");
printf("\n 1 储户开户");
printf("\n 2 余额查询");
printf("\n 3 储户销户");
printf("\n 4 密码修改");
printf("\n 5 退出");
printf("\n ************************************************************************** ");
printf("\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ");
}
int reads(struct depositor dep[N]) // 读取储户内容
{
FILE *fp;
int i=0;
if((fp=fopen("account.dat","r"))==NULL)
{
printf("文件打开失败!\n");
return 0;
}
else
{
for(i=0;!feof(fp);i++)
fscanf(fp,"\n%s %s %s %f %f\n",dep[i].num,dep[i].name,dep[i].per,&dep[i].sec,&dep[i].mon);
}
fclose(fp);
return i;
}
void save(struct depositor dep[N],int n) // 储户保存后信息
{
FILE *fp;
int i=0;
if((fp=fopen("account.dat","w"))==NULL)
{
printf("文件打开失败!\n");
return ;
}
else
{
for(i=0;i<n;i++)
fprintf(fp,"\n%s %s %s %f %f\n",dep[i].num,dep[i].name,dep[i].per,dep[i].sec,dep[i].mon );
}
fclose(fp);
}
void add()/*储户开户*/
{
FILE *fp;
struct depositor dep;
if((fp=fopen("account.dat","a"))==NULL) //如果文件已经存在,可以追加储户信息
{
if((fp=fopen("account.dat","w"))==NULL) // 文件不存在时,创建新文件,输入储户信息
{
printf("用户不存在!\n");
return ;
}
}
printf("\n请输入储户帐号,并按回车键确认:\n");
scanf("%s",dep.num);
fprintf(fp,"\n%s\n",dep.num);
printf("\n请输入储户姓名,并用回车键确认: \n");
scanf("%s",dep.name);
fprintf(fp,"\n%s\n",dep.name);
printf("\n请输入储户身份证号,并用回车键确认: \n");
scanf("%s",dep.per);
fprintf(fp,"\n%s\n",dep.per);
printf("\n请输入储户密码,并用回车键确认: \n");
scanf("%f",&dep.sec);
fprintf(fp,"\n%f\n",dep.sec);
printf("\n请输入储户金额,并按回车键确认: \n");
scanf("%f",&dep.mon);
fprintf(fp,"\n%f\n",dep.mon);
if(dep.mon<10 )
{ printf("\n 储户金额低于十元,不予开户 \n");
return ;
}
printf("\n **********************开户成功*************************\n");
fclose(fp);
}
void show() //余额查询
{
struct depositor dep[N];
int i,n ;
char s[20];
float t ;
n=reads(dep);
printf("\n请用户输入账号,密码,用空格隔开,按回车键确认:\n");
scanf("%s %f",s,&t);
for(i=0;i<n;i++)
if (strcmp(s,dep[i].num)==0 && t==dep[i].sec) break;
if (i>=n || t!=dep[i].sec)
{
printf("\n 输入错误 \n");
return ;
}
else
{ printf("*********************储户的余额如下**********************\n");
printf(" 余额 \n");
printf("\n %11.2f \n", dep[i].mon);
printf("**********************************************************\n");
}
}
void del() /*储户信息删除函数*/
{
struct depositor dep[N];
char number[20];
float t;
int n,i,j;
n=reads(dep);
printf("\n请输入要删除储户账号,密码,用空格隔开,按回车键确认:");
scanf("%s %f",number,&t);
for(i=0;i<n;i++)
if(strcmp(number,dep[i].num)==0&&t==dep[i].sec) break;
if(i>=n||t!=dep[i].sec)
{
printf("没有找到该储户信息!\n");
return;
}
else
{
for(j=i+1;j<n;j++)
dep[j-1]=dep[j];
}
save(dep,n-1);
printf("销户成功!\n");
}
void change() //储户密码更改
{
struct depositor dep[N];
int n,i;
float t;
char number[20];
printf("\n请输入要更改密码的储户账号,密码,用空格隔开,按回车键确认:");
scanf("%s %f",number,&t);
n=reads(dep);
for(i=0;i<n;i++)
if(strcmp(number,dep[i].num)==0&&t==dep[i].sec)
break;
if(i>=n||t!=dep[i].sec)
{
printf("无此储户信息!");
return;
}
printf("\n请输入更改后密码,按回车键确认:\n");
scanf("%f",&dep[i].sec);
save(dep,n);
printf("\n修改成功\n");
}
#include<string.h>
#include<stdlib.h>
#include"conio.h"
#define N 20
struct depositor
{char num[20];<br> char name[20];<br> char per[20];<br> float sec;<br> float mon;<br>};
void menu();
int reads(struct depositor dep[N]);
void save(struct depositor dep[N],int n);
void add();
void del();
void change();
void show();
void main()
{
int n;
while(1)
{
menu();
printf("\n 请输入您要选择的操作序号,按回车键确认:");
scanf("%d",&n);
switch(n)
{
case 1: add();break;
case 2: show();break;
case 3: del();break;
case 4: change();break;
case 5: exit(0);
default: printf("输入错误,请输入列表中存在的序号!\n ");
}
}}
void menu()
{
printf(" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ");
printf("\n ************************* 银行个人账户管理系统*************************** ");
printf("\n 1 储户开户");
printf("\n 2 余额查询");
printf("\n 3 储户销户");
printf("\n 4 密码修改");
printf("\n 5 退出");
printf("\n ************************************************************************** ");
printf("\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ");
}
int reads(struct depositor dep[N]) // 读取储户内容
{
FILE *fp;
int i=0;
if((fp=fopen("account.dat","r"))==NULL)
{
printf("文件打开失败!\n");
return 0;
}
else
{
for(i=0;!feof(fp);i++)
fscanf(fp,"\n%s %s %s %f %f\n",dep[i].num,dep[i].name,dep[i].per,&dep[i].sec,&dep[i].mon);
}
fclose(fp);
return i;
}
void save(struct depositor dep[N],int n) // 储户保存后信息
{
FILE *fp;
int i=0;
if((fp=fopen("account.dat","w"))==NULL)
{
printf("文件打开失败!\n");
return ;
}
else
{
for(i=0;i<n;i++)
fprintf(fp,"\n%s %s %s %f %f\n",dep[i].num,dep[i].name,dep[i].per,dep[i].sec,dep[i].mon );
}
fclose(fp);
}
void add()/*储户开户*/
{
FILE *fp;
struct depositor dep;
if((fp=fopen("account.dat","a"))==NULL) //如果文件已经存在,可以追加储户信息
{
if((fp=fopen("account.dat","w"))==NULL) // 文件不存在时,创建新文件,输入储户信息
{
printf("用户不存在!\n");
return ;
}
}
printf("\n请输入储户帐号,并按回车键确认:\n");
scanf("%s",dep.num);
fprintf(fp,"\n%s\n",dep.num);
printf("\n请输入储户姓名,并用回车键确认: \n");
scanf("%s",dep.name);
fprintf(fp,"\n%s\n",dep.name);
printf("\n请输入储户身份证号,并用回车键确认: \n");
scanf("%s",dep.per);
fprintf(fp,"\n%s\n",dep.per);
printf("\n请输入储户密码,并用回车键确认: \n");
scanf("%f",&dep.sec);
fprintf(fp,"\n%f\n",dep.sec);
printf("\n请输入储户金额,并按回车键确认: \n");
scanf("%f",&dep.mon);
fprintf(fp,"\n%f\n",dep.mon);
if(dep.mon<10 )
{ printf("\n 储户金额低于十元,不予开户 \n");
return ;
}
printf("\n **********************开户成功*************************\n");
fclose(fp);
}
void show() //余额查询
{
struct depositor dep[N];
int i,n ;
char s[20];
float t ;
n=reads(dep);
printf("\n请用户输入账号,密码,用空格隔开,按回车键确认:\n");
scanf("%s %f",s,&t);
for(i=0;i<n;i++)
if (strcmp(s,dep[i].num)==0 && t==dep[i].sec) break;
if (i>=n || t!=dep[i].sec)
{
printf("\n 输入错误 \n");
return ;
}
else
{ printf("*********************储户的余额如下**********************\n");
printf(" 余额 \n");
printf("\n %11.2f \n", dep[i].mon);
printf("**********************************************************\n");
}
}
void del() /*储户信息删除函数*/
{
struct depositor dep[N];
char number[20];
float t;
int n,i,j;
n=reads(dep);
printf("\n请输入要删除储户账号,密码,用空格隔开,按回车键确认:");
scanf("%s %f",number,&t);
for(i=0;i<n;i++)
if(strcmp(number,dep[i].num)==0&&t==dep[i].sec) break;
if(i>=n||t!=dep[i].sec)
{
printf("没有找到该储户信息!\n");
return;
}
else
{
for(j=i+1;j<n;j++)
dep[j-1]=dep[j];
}
save(dep,n-1);
printf("销户成功!\n");
}
void change() //储户密码更改
{
struct depositor dep[N];
int n,i;
float t;
char number[20];
printf("\n请输入要更改密码的储户账号,密码,用空格隔开,按回车键确认:");
scanf("%s %f",number,&t);
n=reads(dep);
for(i=0;i<n;i++)
if(strcmp(number,dep[i].num)==0&&t==dep[i].sec)
break;
if(i>=n||t!=dep[i].sec)
{
printf("无此储户信息!");
return;
}
printf("\n请输入更改后密码,按回车键确认:\n");
scanf("%f",&dep[i].sec);
save(dep,n);
printf("\n修改成功\n");
}
2013-12-19
展开全部
要多少,啥类型
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询