| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 582 人关注过本帖
标题:谁给我说下这个程序的思想和流程啊,看这个程序总是似懂非懂,脑子好不清晰
只看楼主 加入收藏
a378585
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2010-11-22
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:5 
谁给我说下这个程序的思想和流程啊,看这个程序总是似懂非懂,脑子好不清晰
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
struct atm
    {
       char name[20];//姓名
       char pwd[20]; //密码
       double money;   //余额
       atm *next;
    }*head,*left;

struct user
    {
        char name[20];//姓名
        char text[100];
        user *next;
    }*uhead,*uleft;


//---------------------函数声明------------------------------------------
void load();          //加载文件到链表
void menu();          //菜单
void login();         //登录
void FindStu(atm *head,char atmname[20],char atmpwd[20]);
void title();         //开始界面
void input();         //开始输入界面
struct atm *creatlink(atm *point);
struct user* creatlink_user(user *point);
void newuser(atm*pCur,atm *p);    //注册
void functiontitle(atm * userP);  //用户登录成功主界面
void cunqian(atm *p);             //用户存钱
void quqian(atm *p);              //用户取钱
void zhuanzhang(atm* head,atm *p);//用户转账
int flog_writ(atm *u,int i,double j,atm *zu);       //写日记
int lookjilu(char username[20]);//查看记录
void xiugaimima(atm *p);          //修改密码
void writ(atm* p);                //写入文件
void OutputList_log(user *head,char username[20]);


上面是头文件mytitle.h的代码


#include "mytitle.h"


//------------------------------主函数-------------------------------------
FILE *fp;
FILE *flog;
void main()
    {
        load();//加载
        menu();//菜单
    }

//----------------------------把文件的记录加载到链表----------------------
void load()
    {
open:    if((fp=fopen("user.txt","r"))==NULL)//判断文件打开是否成功
        {
            perror("打开出错");
            goto create;
        }

        struct atm *p1,*p2;

        head=p1=(struct atm*)malloc(sizeof(struct atm));//新建链表头
        strcpy(p1->name,"1");
        strcpy(p1->pwd,"1");
        p1->money=0;
        p1->next=NULL;
        while(!feof(fp))
        {
            p2=creatlink(p1);//调用函数创建新链
            fscanf(fp,"%s %s %lf\n",p2->name,p2->pwd,&(p2->money));
            p1=p2;//连接
        }
        fclose(fp);//关闭文件
        
        
        return;
        
        

create:    if((fp=fopen("user.txt","w"))==NULL)//判断文件打开是否成功
        {
            perror("创建出错");
            exit(1);  //退出
        }
    }
//---------------------------------菜单界面---------------------------------------
void menu()
    {
        while(1)
        {
            title();
            input();
        }
   
    }
//--------------------------------开始界面--------------------------------
void title()
    {
        //系统清屏
        system("cls");
        
        printf("\n\n\n");
        printf("欢迎使用武汉ATM机\n\n");
        printf("  1.注册账号\n\n");
        printf("  2.登录系统\n\n");
        printf("  3.退出\n\n");
    }



//--------------------------------开始界面输入函数-------------------------
void input()
    {
        char n ;
        printf("\n请输入命令执行: ");
      
        scanf("%c",&n);
            switch(n)
            {
                case 49 :
                //同上因为n是字符型,如果n=1,其对应的ASC值为49
                    creatlink(left);//调用函数创建新链
                    newuser(head,left);
                    break;
                case 50 :
                    login();
                    break ;
                case 51 :
                    fclose(fp);
                    printf("谢谢您的使用!\n");
                    exit(0);break;
                default :
                {
                    printf("输入错误,按回车返回\n");
                    
                    break ;
                }
             }
        getchar();
        
    }

//------------------------创建链表-------------------------------------------------------------
struct atm *
    creatlink(atm *point)//创建一个二进制数据结构体
    {
        
        left=(struct atm*)malloc(sizeof(struct atm));//创建新的结构体空间
        point->next=left;//建立两个链的链接
        left->next=NULL; //将新建的链结尾指针指向NULL,如果这是最后一个链则代表链表结束,否则会在上句被重定向到新链
        return(left);    //返回新链的地址
    }

//------------------------注册输入-------------------------------------------------------------
void newuser(atm *pCur,atm *p)
    {   
        atm *phead=pCur->next;
        char user[20];
        printf("请输入用户名\n");
        scanf("%s",user);
        while(NULL!=phead)
        {  
            if(0==strcmp(phead->name,user))//找到了
            {
                printf("注册失败,已存在用户%s!\n",user);
                return;
            }
            phead=phead->next;//取下一个结点
         }
        strcpy(p->name,user);
        printf("请输入密码\n");
        scanf("%s",&p->pwd);
        printf("请输入金额\n");
        scanf("%lf",&p->money);
        fprintf(fp,"%s %s %lf\n",p->name,p->pwd,p->money);
        printf("注册成功!");
        if (0!=flog_writ(p,1,0,p))
        {
            printf("写入记录失败!\n");
        }
        else
        {
            fclose(flog);
            system("echo %date:~0,10%-%time%>>user1.txt");
        }
        writ(head);
        main();
    }

//-----------------------------登录---------------------------------------------------------------
void login()
    {
           char atmname[20];
           char atmpwd[20];
           char kikyo;
           printf("是否要登录<y/n>\n");
           getchar();
           scanf("%c",&kikyo);
           if (( 'Y'==kikyo) || ( 'y'==kikyo))
           {
               printf("请输入用户:\n");
               scanf("%s",atmname);
               printf("请输入密码:\n");
               scanf("%s",atmpwd);
               FindStu(head,atmname,atmpwd);
           }
    }
//------------------------登录检查----------------------------------------------------------------
void FindStu(atm *head,char atmname[20],char atmpwd[20])
    {
   
          if (NULL == head)
            {
                printf("链表中数据为空!");
                return;
            }

            int finded=0;//没有找到
      
            atm *pCur=head;
            while(NULL !=pCur)
            {  
                if(0==strcmp(pCur->name,atmname) && 0==strcmp(pCur->pwd,atmpwd))
               {
                    //找到了
                   printf("登录成功!\n");

                   if (0!=flog_writ(pCur,2,0,pCur))
                   {
                      printf("写入记录失败!\n");
                   }
                   else
                   {
                      fclose(flog);
                      system("echo %date:~0,10%-%time%>>user1.txt");
                   }
                   printf("%s\t\t%s\t\t%lf\n",pCur->name,pCur->pwd,pCur->money);
                   finded=1;
                   functiontitle(pCur);      
               }
               pCur=pCur->next;//取下一个结点
            }
            if (0==finded) printf("\n对不起,没有找到用户为%s的信息!\n",atmname,atmpwd);
            return ;
    }

//----------------------------------------------------用户功能开始界面---------------------------------------------------------------//
void functiontitle(atm * userP)
    {   
        char n;
        //系统清屏
        system("cls");
        
cxin:    printf("\n\n\n");
        printf("欢迎用户%s登陆本系统\n\n",userP->name);
        printf(" 1.存钱\n\n");
        printf(" 2.取钱\n\n");
        printf(" 3.转账\n\n");
        printf(" 4.查询余额\n\n");
        printf(" 5.查询记录\n\n");
        printf(" 6.修改密码\n\n");
        printf(" 7.退卡\n\n");
        printf("请输入您要操作的命令:\n");
        getchar();  //过滤
        scanf("%c",&n);
        char username[20];
        strcpy(username,userP->name);
        switch(n)
        {
           case 49 :                       //存钱
               cunqian(userP);
               goto cxin;
           case 50:                        //取钱
               quqian(userP);
               goto cxin;
           case 51:                        //转账
               zhuanzhang(head,userP);
               goto cxin;
           case 52:                        //余额查询
               printf("您的余额为:%lf\n",userP->money);
               goto cxin;
           case 53:                        //查看记录
               lookjilu(username);
               goto cxin;
           case 54:                      //修改密码
               xiugaimima(userP);
               goto cxin;
           case 55:
               //退出
               writ(head);
               main();
               break;
           default :
                {
                    printf("输入错误,按回车返回\n");
                    goto cxin;
                }
        }
    }

//---------------------------------用户存钱--------------------------------------------------
void cunqian(atm *p)
    {   
        double i;
        printf("请输入您要存的金额:\n");
        scanf("%lf",&i);
        (p->money)+=i;
        printf("操作成功,您现在的余额为:%lf\n",p->money);
        if (0!=flog_writ(p,3,i,p))
        {
            printf("写入记录失败!\n");
        }
        else
        {
            fclose(flog);
            system("echo %date:~0,10%-%time%>>user1.txt");
        }
        return;
     }
//----------------------------------用户取钱--------------------------------------------------
void quqian(atm *p)
   {
        double i;
        printf("请输入您要取的金额:\n");
        scanf("%lf",&i);
        if(i>=(p->money))
        {
            printf("卡上余额不足,无法取钱!\n");
            return;
        }
        (p->money)-=i;
        printf("操作成功,您现在的余额为:%lf\n",p->money);
        if (0!=flog_writ(p,4,i,p))
        {
            printf("写入记录失败!\n");
        }
        else
        {
            fclose(flog);
            system("echo %date:~0,10%-%time%>>user1.txt");
        }
        return;
   }
//-------------------------------用户转账-----------------------------------------------------
void zhuanzhang(atm* head,atm *p)
    {
     char user[20];
     double i;
     atm *pCur=head->next;
     printf("请输入您要转向用户的用户名:\n");
     scanf("%s",user);
     
         while(NULL!=pCur)
        {  
             if(0==strcmp(pCur->name,user))
            {
                            //找到了
                           printf("请输入您要输入的金额:\n");
                           scanf("%lf",&i);
                           if(i>=(p->money))
                           {
                              printf("转账失败,您的余额不足!\n");
                              return;
                           }
                           else
                           {
                               p->money-=i;
                               pCur->money+=i;
                               printf("转账成功!您当前余额为:%lf\n",p->money);
                                if (0!=flog_writ(p,5,i,pCur))
                                {
                                    printf("写入记录失败!\n");
                                }
                                else
                                {
                                    fclose(flog);
                                    system("echo %date:~0,10%-%time%>>user1.txt");
                                }
                                return;
                           }
             }
             else
             pCur=pCur->next;//取下一个结点
         }
         printf("\n对不起,没有找到用户为%s的信息!\n",user);
         return ;
    }
//------------------------------------保存修改-------------------------------------------------------
void writ(atm* p)
   {   
       atm *pCur=p->next;
       if((fp=fopen("user.txt","w"))==NULL)
       {
         perror("打开出错");
         return;
       }
       while(NULL==!pCur)
       {
           fprintf(fp,"%s %s %lf\n",pCur->name,pCur->pwd,pCur->money);
           pCur=pCur->next;
       }
       fclose(fp);//关闭文件
       free(head);
       return;
   }
//-------------------------------修改密码---------------------------------------------------------
void xiugaimima(atm *p)
   {   
        char a[20];
        char b[20];
        printf("请输入您的密码:\n");
        scanf("%s",a);
        if(0==(strcmp(p->pwd,a)))
        {
input:       printf("请输入您的新密码\n");
            scanf("%s",a);
            printf("请确认密码:\n");
            scanf("%s",b);
            if(0==(strcmp(a,b)))
            {
                strcpy(p->pwd,b);
                printf("密码修改成功!\n");
                if (0!=flog_writ(p,6,0,p))
                {
                    printf("写入记录失败!\n");
                }
                else
                {
                    fclose(flog);
                    system("echo %date:~0,10%-%time%>>user1.txt");
                }
                return;
            }
            else
            {
                printf("两次输入密码不一致!\n");
                goto input;
            }
        }
        else
        {
            printf("原始密码不正确!\n");
            return;
        }
    }
//-----------------------------写日记----------------------------------------------
int flog_writ(atm *u,int i,double j,atm *zu)
   {   
      
       if ((flog=fopen("user1.txt","a"))==NULL)
           goto cLog;
       else
       {
           if (1==i)       //注册
           {
              fprintf(fp,"%s  注册",u->name);
              
              return 0;
           }
           else if(2==i)  //登录
           {
              fprintf(fp,"%s  登录",u->name);
               return 0;
           }
           else if(3==i)  //存钱
           {
              fprintf(fp,"%s  存钱%lf:",u->name,j);
               return 0;
           }
           else if(4==i)  //取款
           {
              fprintf(fp,"%s  取款%lf:",u->name,j);
               return 0;
           }
           else if(5==i)  //转账
           {
               fprintf(fp,"%s  转账给%s-%lf:",u->name,zu->name,j);
               return 0;
           }
           else if(6==i)  //转账
           {
               fprintf(fp,"%s  修改密码成功:",u->name);
               return 0;
           }

cLog:  if(NULL==(flog=fopen("user1.txt","w")))
       {
           return -1;
       }
    }
}
//-----------------------查看记录-------------------------------------------------
int lookjilu(char username[20])
   {
       if((flog=fopen("user1.txt","r"))==NULL)
       {
          printf("打开文件失败");
          return -1;
       }
       else
       {
          struct user *up1,*up2;
          uhead=up1=(struct user*)malloc(sizeof(struct user));//新建链表头
          strcpy(up1->name,"");
          strcpy(up1->text,"");
          up1->next=NULL;
          while(!feof(flog))//将文件中的数据载入到新的链表
          {
            up2=creatlink_user(up1);//调用函数创建新链
            fscanf(flog,"%s  %s\n",up2->name,up2->text);
            up1=up2;//连接
          }
          fclose(flog);
          OutputList_log(uhead,username);
       }
    }
//-----------------------加载日记内容到内存----------------------------------------------------------
struct user *
    creatlink_user(user *point)
    {
        uleft=(struct user*)malloc(sizeof(struct user));//创建新的结构体空间
        point->next=uleft;//建立两个链的链接
        uleft->next=NULL; //链表结束
        return(uleft);    //返回新链的地址
    }
//-------------------------挑选,输出记录------------------------------------------------------------
void OutputList_log(user *head,char username[20])
    {
        if (NULL==(head->next))
            {
                printf("链表中数据为空!");
                return;
            }
        else
        {
           printf("            操作记录                \n");
           printf("======================================\n");
           user *pCur=uhead->next;
           while(NULL!=pCur)
            {
                if(0==strcmp(pCur->name,username))
                {
                   printf("%s\t\t %s\n",pCur->name,pCur->text);
                   pCur=pCur->next;
                }
                else
                {
                   pCur=pCur->next;
                }
            }
        }
    }
搜索更多相关主题的帖子: 流程 似懂非懂 脑子 思想 
2010-11-24 21:29
gongyaping
Rank: 4
来 自:广东肇庆怀集
等 级:业余侠客
帖 子:174
专家分:257
注 册:2010-8-1
收藏
得分:7 
太长,看得眼晕。
2010-11-25 11:41
a378585
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2010-11-22
收藏
得分:0 
已经懂了。
2010-11-25 19:10
zghnxzdcx
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:550
专家分:1176
注 册:2010-4-6
收藏
得分:7 
注释的习惯不错

你永远不可能战胜一个纯傻子,因为他会把你的智商拉到和他同一个水平,然后用他的丰富经验打败你。
2010-11-25 19:54
ting3259298
Rank: 2
等 级:论坛游民
帖 子:15
专家分:17
注 册:2010-10-22
收藏
得分:7 
注释太少了
2010-11-25 20:23
zghnxzdcx
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:550
专家分:1176
注 册:2010-4-6
收藏
得分:0 
回复 5楼 ting3259298
注释不在多,体现思路就是好的

你永远不可能战胜一个纯傻子,因为他会把你的智商拉到和他同一个水平,然后用他的丰富经验打败你。
2010-11-25 20:28
快速回复:谁给我说下这个程序的思想和流程啊,看这个程序总是似懂非懂,脑子好不 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046627 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved