本文目录一览:
求用c语言编写的程序,最好带着注释(越详细越好!!)
#includestdio.h
#includestring.h
#includestdlib.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;in;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.mon10 )
{ 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;in;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;in;i++)
if(strcmp(number,dep[i].num)==0t==dep[i].sec) break;
if(i=n||t!=dep[i].sec)
printf("没有找到该储户信息!\n");
return;
else
for(j=i+1;jn;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;in;i++)
if(strcmp(number,dep[i].num)==0t==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");
带注释的c语言程序
#includereg52.h
#define uchar unsigned char
#define uint unsigned int
bit write=0; //写24C02的标志;
sbit sda=P2^0;
sbit scl=P2^1;
sbit dula=P2^6;
sbit wela=P2^7;
uchar sec,tcnt;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay()
void delay1ms(uint z)
uint x,y;
for(x=z;x0;x--)
for(y=110;y0;y--);
void start() //开始信号
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
void stop() //停止
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
void respons() //应答
uchar i;
scl=1;
delay();
while((sda==1)(i250))i++;
scl=0;
delay();
void init()
sda=1;
delay();
scl=1;
delay();
void write_byte(uchar date)
uchar i,temp;
temp=date;
for(i=0;i8;i++)
temp=temp1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
delay();
scl=0;
delay();
sda=1;
delay();
uchar read_byte()
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i8;i++)
scl=1;
delay();
k=(k1)|sda;
scl=0;
delay();
return k;
void write_add(uchar address,uchar date)
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
uchar read_add(uchar address)
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
void display(uchar bai_c,uchar sh_c) //显示程序
dula=0;
P0=table[bai_c]; //显示第一位
dula=1;
dula=0;
wela=0;
P0=0x7e;
wela=1;
wela=0;
delay1ms(5);
dula=0;
P0=table[sh_c]; //显示第二位
dula=1;
dula=0;
wela=0;
P0=0x7d;
wela=1;
wela=0;
delay1ms(5);
void main()
init();
sec=read_add(2); //读出保存的数据赋于sec
if(sec100) //防止首次读取出错误数据
sec=0;
TMOD=0x01; //定时器工作在方式1
ET0=1;
EA=1;
TH0=(65536-50000)/256; //对TH0 TL0赋值
TL0=(65536-50000)%256; //使定时器0.05秒中断一次
TR0=1; //开始计时
while(1)
display(sec/10,sec%10);
if(write==1) //判断计时器是否计时一秒
write=0; //清零
write_add(2,sec); //在24c02的地址2中写入数据sec
void t0() interrupt 1 //定时中断服务函数
TH0=(65536-50000)/256; //对TH0 TL0赋值
TL0=(65536-50000)%256; //重装计数初值
tcnt++; //每过50ms tcnt加一
if(tcnt==20) //计满20次(1秒)时
tcnt=0; //重新再计
sec++;
write=1; //1秒写一次24C02
if(sec==100) //定时100秒,再从零开始计时
sec=0;
谁提供一原创C语言完整程序,50行以上,有程序注释,急用
#includereg52.h
#define uchar unsigned char //宏定义
#define uint unsigned int
sbit rs=P2^6; //液晶引脚位定义
sbit rw=P2^5;
sbit en=P2^7;
sbit k5=P2^3; //独立键盘位定义
sbit k6=P2^2;
sbit k7=P2^4;
sbit sda=P2^1; //EEPROM位定义
sbit scl=P2^0;
sbit JD=P1^4;
uchar i,tt,a;
char shi,fen,miao;
uchar code D[]=" 2011-3-24";
uchar code D1[]=" : : ";
void delay1() //延时函数,延时时间约4us
void start() //EEPROM中开始信号
sda=1;
delay1();
scl=1;
delay1();
sda=0;
delay1();
void stop() //EEPROM中停止信号
sda=0;
delay1();
scl=1;
delay1();
sda=1;
delay1();}
void response() //EEPROM中应答信号
uint i;
scl=0;
delay1();
scl=1;
delay1();
while((sda==1)(i250))i++)
scl=0;
delay1();
void write_byte(uchar shu)//在EEPROM中写8位2进制数
uint i;
uchar temp;
temp=shu;
for(i=0;i8;i++)
temp=temp1;
scl=0;
delay1();
sda=CY;
delay1();
scl=1;
delay1();
scl=0;
delay1();
sda=1;
delay1();
uchar read_byte()//从EEPROM中读8位2进制数
uint i;
uchar a;
scl=0;
delay1();
sda=1;
delay1();
for(i=0;i8;i++)
scl=1;
delay1();
a=(a1)|sda;
delay1();
scl=0;
delay1();
return a;
void write(uchar address,uchar date)//在EEPROM指定地址写入数据
start();
write_byte(0xa0);
response();
write_byte(address);
response();
write_byte(date);
response();
stop();}
uchar read(uchar address) //从EEPROM中指定地址读数据
uchar date;
start();
write_byte(0xa0);
response();
write_byte(address);
response();
start();
write_byte(0xa1);
response();
date=read_byte();
stop();
return date;
void delay(uchar z) //延时函数
uchar x,y;
for(x=z;x0;x--)
for(y=120;y0;y--);
write_com(uchar com) //给液晶写指令
en=0;
rs=0;
rw=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
write_date(uchar date) //给液晶写数据
en=0;
rs=1;
rw=0;
P0=date;
delay(5);
en=1;
delay(5);
en=0;
void write_sfm(uchar add,char date)//液晶在指定位置开始写指定的数
{ char x,y;
x=date/10;
y=date%10;
write_com(0x80+0x40+add);
write_date(0x30+x);
write_date(0x30+y);
void init()
{ TMOD=0x01; //定时器0的初始化
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;ET0=1;
TR0=1;
write_com(0x38); //液晶的初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(i=0;i12;i++) //显示液晶的第一行
{write_date(D[i]);br delay(20);br }
write_com(0x80+0x40);//显示液晶的第二行
for(i=0;i12;i++)
{write_date(D1[i]);br delay(20);br }
shi=read(4);//从eeprom中读值分别赋给时分秒
fen=read(5);
miao=read(2);
write_sfm(4,shi);//液晶第二行显示时分秒
write_sfm(7,fen);
write_sfm(10,miao);}
void main()
init();
while(1)
if(k5==0)
delay(5);
if(k5==0)
while(!k5);//松手检测
delay(5);
while(!k5);
a++;
TR0=0;
if(a==4)
a=0;
TR0=1;
tt=0;
switch(a)
case 1: //秒的调整
{ write_com(0x80+0x40+11);//调光标到秒的位置
write_com(0x0f); //光标闪烁
if(k6==0)
delay(5);
if(k6==0)
{ while(!k6);
delay(5);
while(!k6);
miao++;
if(miao==60)
miao=0;
write(2,miao);
write_sfm(10,miao);
write_com(0x80+0x40+11);
if(k7==0)
delay(5);
if(k7==0)
{ while(!k7);
delay(5);
while(!k7);
miao--;
if(miao0)
miao=59;
write(2,miao);
write_sfm(10,miao);
write_com(0x80+0x40+11);
} break;
case 2: //分钟的调整
{ write_com(0x80+0x40+8);//调光标到分的位置
if(k6==0)
delay(5);
if(k6==0)
{ while(!k6);
delay(5);
while(!k6);
fen++;
if(fen==60)
fen=0;
write(5,fen);
write_sfm(7,fen);
write_com(0x80+0x40+8);
if(k7==0)
delay(5);
if(k7==0)
{ while(!k7);
delay(5);
while(!k7);
fen--;
if(fen0)
fen=59;
write(5,fen);
write_sfm(7,fen);
write_com(0x80+0x40+8);
} break;
case 3: //小时的调整
{ write_com(0x80+0x40+5);//调光标到小时的位置
if(k6==0)
delay(5);
if(k6==0)
{ while(!k6);
delay(5);
while(!k6);
shi++;
if(shi==24)
shi=0;
write(4,shi);
write_sfm(4,shi);
write_com(0x80+0x40+5);
if(k7==0)
delay(5);
if(k7==0)
{ while(!k7);
delay(5);
while(!k7);
shi--;
if(shi0)
shi=23;
write(4,shi);
write_sfm(4,shi);
write_com(0x80+0x40+5);
} break;
case 0:
write_com(0x0c); //开液晶显示,不显光标,光标不闪
if(tt==20) //每过一秒时钟走一秒
tt=0;
miao++;
if(miao==60)
JD=0;
miao=0;
fen++;
if(fen==60)
fen=0;
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
write(4,shi);
write_sfm(7,fen);
write(5,fen);
write_sfm(10,miao);
write(2,miao);
if(miao==30)
JD=1;
void timer0() interrupt 1 //定时器0函数
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
C++的~~LCD时钟程序