程序设计工程训练报告C语言程序设计个人财务管理系统课程名称C语言程序设计工程训练姓名院(系)信息科学与技术学院专业班级学号指导教师教务处制目录1、需求分析 (1)2系统总框图与功能模块说明 (1)2、1系统总框图 (1)2、2功能模块说明 (1)3系统设计 (2)3、1主要结构体 (2)3、2主要功能函数 (2)4系统调试 (3)4、1、程序开始执行时系统的所显示的页面: (3)4、2、选择退出系统: (3)4、3、选择登陆,并且输入的帐号与密码都正确: (3)4、4、用户输入的帐号不正确: (4)4、5、用户输入的帐号正确,密码不正确: (4)4、6、用户进行具体操作: (5)5总结 (6)6源程序清单 (6)1、需求分析编写一个个人财政支出管理系统,主要解决的问题就是作为一个系统而言,它所要面对不只就是某一个人而言,而就是要面对很多的用户。
那么想要解决这一问题,就必须要求这个系统能够存储许多用户的基本信息与记录。
同时也要求系统能够对不同的用户的身份进行查找与验证。
在验证通过之后,在对其进行用户所要求的操作。
作为一个财政支出系统,那么就要求对于用户关于金钱的每一项操作都要有相应的记录,同时并允许用户对于每一条整体的记录进行操作,例如可以根据时间来查找某一确定日期就是否进行了收入或者支出的操作,也可以根据特定的需要来删除某一条整体的记录。
但不允许对每条记录的单项数据进行更改,因为不管就是收入还就是支出,所涉及的金额都就是固定的,时间也就是固定的,所以系统不允许用户对其进行操作。
除此之外,还必须有足够大的空间来存储新的记录。
所以此程序就就是基于这个思想而编写出来的,基本满足了用户对于一个财政支出管理系统所要求的相关功能。
2系统总框图与功能模块说明2、1系统总框图2、2功能模块说明(1)old_record( ):此函数由系统自行调用,作用就是将所有用户信息存入系统。
(2)void save( ): 此函数的作用就是将结构体数组中的信息写入文件存储,由系统调用。
(3)load( ):此函数的作用就是将结构体数组中写入文件的信息读出,由系统调用。
(4)lookup_accounts( ):此函数的作用就是将用户输入的帐号与系统中的所有帐号进行对比,查瞧系统中就是否有此帐号。
(5) check_code( ):此函数就是作用就是在系统查询到了帐号之后,对用户输入的帐号与密码进行检验,瞧就是否相对应。
(6)print_message( ):此函数的功能就是在系统检查了用户输入的帐号与密码之后,如果用户通过了系统的检查,在此显示用户可见的基本信息。
(7)find_record( ):此函数的作用就是根据用户输入的日期进行查找操作。
(8)insert_record( ):此函数的功能就是在记录中增加一条新的记录,这个记录由用户输入。
(9)del_record( ):此函数的功能就是根据用户的输入的位置,将相应位置的记录删除。
(10)sum_num( ):此函数的功能就是计算所有收入与支出的总与,计算全部的收入的总合,计算全部输出的总合。
(11)打印输出记录的函数:在本程序中一共有三个打印输出记录的函数,分别为all_print( )、acc_print( )、pay_print( )这三个函数。
它们的功能依次就是打印输出全部记录,打印输出输入记录,打印输出支出记录。
(12)mian( ):在主函数中,可以根据用户的选择来操作系统允许用户使用的功能,也可以随时退出这个系统。
3系统设计3、1主要结构体个人信息账户信息3、2主要功能函数old_record( ) //将所有用户信息存入系统print_message( ) //显示用户可见的基本信息sum_num( ) //计算所有收入与支出的总与all_print( )、acc_print( )、pay_print( ) //打印输出全部记录,打印输出输入记录,打印输出支出记录4系统调试4、1、程序开始执行时系统的所显示的页面:4、2、选择退出系统:4、3、选择登陆,并且输入的帐号与密码都正确:4、4、用户输入的帐号不正确:4、5、用户输入的帐号正确,密码不正确:4、6、用户进行具体操作:5总结本程序在编写就是,主要就就是基于用户的角度去分析该如何设计此程序,与编写功能模块的。
在编写程序时,所有的数据都就是对结构体进行的操作,在此过程中,我发现了自己在对指针操作的时候,尤其就是对指向结构体数组的指针与指向结构体的指针的操作都不够熟练。
但在编写完此程序之后,我感觉自己对语法的应用有了明显的提高。
6源程序清单#include<stdio、h>#include<string、h>#define null 0#define max 20#define ok 1struct record{char date[20];char operate[20];int num;};struct list_record{char account[20];char code[20];char name[20];int rec_len;struct record rec[max];}r[max];//系统原有数据,用户不可知int old_record( struct list_record r[]){int i;for(i=0;i<3;i++)r[i]、rec_len=4;strcpy(r[0]、account,"1001");strcpy(r[1]、account,"1002");strcpy(r[2]、account,"1003");strcpy(r[0]、code,"111111");strcpy(r[1]、code,"222222");strcpy(r[2]、code,"333333");strcpy(r[0]、name ,"wang");strcpy(r[1]、name ,"li");strcpy(r[2]、name ,"zhang");strcpy(r[0]、rec[0]、date,"07-01-01"); strcpy(r[0]、rec[1]、date,"07-02-01"); strcpy(r[0]、rec[2]、date,"07-03-01"); strcpy(r[0]、rec[3]、date,"07-04-01"); strcpy(r[1]、rec[0]、date,"07-01-02"); strcpy(r[1]、rec[1]、date,"07-02-02"); strcpy(r[1]、rec[2]、date,"07-03-02"); strcpy(r[1]、rec[3]、date,"07-04-02"); strcpy(r[2]、rec[0]、date,"07-01-03"); strcpy(r[2]、rec[1]、date,"07-02-03"); strcpy(r[2]、rec[2]、date,"07-03-03"); strcpy(r[2]、rec[3]、date,"07-04-03"); strcpy(r[0]、rec[0]、operate,"in"); strcpy(r[0]、rec[1]、operate,"out"); strcpy(r[0]、rec[2]、operate,"in"); strcpy(r[0]、rec[3]、operate,"out"); strcpy(r[1]、rec[0]、operate,"out");strcpy(r[1]、rec[1]、operate,"in"); strcpy(r[1]、rec[2]、operate,"out"); strcpy(r[1]、rec[3]、operate,"in"); strcpy(r[2]、rec[0]、operate,"in"); strcpy(r[2]、rec[1]、operate,"out"); strcpy(r[2]、rec[2]、operate,"in"); strcpy(r[2]、rec[3]、operate,"out"); r[0]、rec[0]、num=3000;r[0]、rec[1]、num=-1500;r[0]、rec[2]、num=2500;r[0]、rec[3]、num=-1000;r[1]、rec[0]、num=-3000;r[1]、rec[1]、num=5000;r[1]、rec[2]、num=-1000;r[1]、rec[2]、num=2000;r[2]、rec[0]、num=1000;r[2]、rec[1]、num=-1500;r[2]、rec[2]、num=3000;r[2]、rec[2]、num=-500;return ok;}//将数据写入文件void save( ){FILE *fp;int i;if((fp=fopen("wenjian","wb"))==null) {printf("can not open the file、\n"); return;}for(i=0;i<max;i++)if(fwrite(&r[i],sizeof(struct list_record),1,fp)!=1)printf(" error、\n");fclose(fp);}//文件读出void load( ){FILE *fp;int i;if((fp=fopen("wenjian","rb"))==null){printf("can not open infile、\n");return;}for(i=0;i<max;i++)if(fread(&r[i],sizeof(struct list_record),1,fp)!=1){if(feof(fp))(fclose(fp));return;}fclose(fp);}//将用户输入的帐号与系统中原有帐号比较,查找用户帐号int lookup_accounts( struct list_record r[],char acc[]){int i;for(i=0;i<3;i++)if(strcmp(r[i]、account,acc)==0){return ok;}printf("帐号不存在,请重新输入!\n");return null;}//检查密码函数struct list_record check_code(struct list_record r[],char acc[],char c[]) {int i;struct list_record a;strcpy(a、account,"0");strcpy(a、code,"0");a、rec_len=0;for(i=0;i<a、rec_len;i++){strcpy(a、rec[i]、date,"0");strcpy(a、rec[i]、operate,"0");a、rec[i]、num=0;}for(i=0;i<3;i++)if(strcmp(r[i]、account,acc)==0)if(strcmp(r[i]、code,c)==0)return r[i];printf("the code is wrong,please input again!\n");return a;}//显示用户基本信息void print_message( struct list_record *p){printf("姓名:%s\n",p->name);printf("帐号:%s\n",(*p)、account);}//根据用户输入的日期,查找记录int find_record( struct list_record *p,char d[]){int i;for(i=0;i<(*p)、rec_len;i++){if(strcmp((*p)、rec[i]、date,d)==0){printf("date operate money\n");printf("%s ",(*p)、rec[i]、date);printf("%s ",(*p)、rec[i]、operate);printf("%d \n",(*p)、rec[i]、num);return ok;}}if(i==(*p)、rec_len)printf("the date is not exit!\n");return null;}//插入函数,根据用户输入的信息,增加记录int insert_record( struct list_record *p,struct record *p1,int lop) {int i;if((lop<1)||(lop>((*p)、rec_len+1))){printf("the position is wrong、\n");return 0;}else{for(i=(*p)、rec_len;i>lop-1;i--){strcpy((*p)、rec[i]、date,(*p)、rec[i-1]、date);strcpy((*p)、rec[i]、operate,(*p)、rec[i-1]、operate);(*p)、rec[i]、num=(*p)、rec[i-1]、num;}strcpy(p->rec[i]、date,p1->date);strcpy((*p)、rec[i]、operate,(*p1)、operate);(*p)、rec[i]、num=(*p1)、num;(*p)、rec_len++;return ok;}}// 删除记录函数int del_record( struct list_record *p,int lop2){int i;if((lop2<1)||(lop2>(*p)、rec_len)){printf("the position is wrong、\n");return null;}else{for(i=lop2-1;i<(*p)、rec_len-1;i++){strcpy((*p)、rec[i]、date,(*p)、rec[i+1]、date);strcpy((*p)、rec[i]、operate,(*p)、rec[i+1]、operate);(*p)、rec[i]、num=(*p)、rec[i+1]、num;}(*p)、rec_len--;return ok;}}//输出全部记录函数void all_print( struct list_record *p){ int i;printf("date operate num\n");for(i=0;i<(*p)、rec_len;i++){ printf("%s ",(*p)、rec[i]、date);printf("%s ",(*p)、rec[i]、operate);printf("%d ",(*p)、rec[i]、num);printf("\n");}}//计算总的钱数int sum_num( struct list_record *p){int i;int sum=0;int sum_in=0;int sum_out=0;for(i=0;i<(*p)、rec_len;i++){sum+=(*p)、rec[i]、num;if((*p)、rec[i]、num>0)sum_in+=(*p)、rec[i]、num;if((*p)、rec[i]、num<0)sum_out+=(*p)、rec[i]、num;}printf("总金额为: %d\n",sum);printf("总收入为: %d\n",sum_in);printf("总支出为: %d\n",sum_out);return ok;}//输出收入记录int acc_print( struct list_record *p){int i;int sum_acc=0;printf("date operate num\n");for(i=0;i<(*p)、rec_len;i++)if((*p)、rec[i]、num>0){sum_acc+=(*p)、rec[i]、num;printf("%s ",(*p)、rec[i]、date);printf("%s ",(*p)、rec[i]、operate);printf("%d ",(*p)、rec[i]、num);printf("\n");}printf("总收入金额为: %d\n",sum_acc);return ok;if(sum_acc==0)printf("there is no account、\n");return null;}//输出支出记录int pay_print( struct list_record *p){int i;int sum_pay=0;printf("date operate num\n"); for(i=0;i<p->rec_len;i++)if((*p)、rec[i]、num<0){sum_pay+=(*p)、rec[i]、num;printf("%s ",(*p)、rec[i]、date);printf("%s ",(*p)、rec[i]、operate);printf("%d ",(*p)、rec[i]、num);printf("\n");}printf("总的支出为: %d\n",sum_pay);return ok;if(sum_pay==0)printf("there is no payout、\n");return null;}void main( ){int j=0,n=0;int x,k,lop1,lop2;char data1[20];char accou[20],cod[20];struct record *p0;struct record a;struct list_record b;struct list_record *p;b、rec_len=0;p0=&a;old_record(r);save( );load( );printf(" 欢迎使用个人财政支出管理系统!\n");printf("------------------------------------------------------------\n");printf("| |\n"); printf("| 1、登陆系统|\n"); printf("| 2、退出系统|\n"); printf("| |\n"); printf("------------------------------------------------------------\n");scanf("%d",&x);if(x==0)printf(" 感谢您使用本系统,再见!\n");else{do{printf("请输入帐号:"); //while(j<3);scanf("%s",accou);if(lookup_accounts(r,accou)){ printf("请输入密码:"); //while(j<3);scanf("%s",cod);b=check_code(r,accou,cod);if(b、rec_len==0){do{b=check_code(r,accou,cod); //while(n>3)scanf("%s",cod);n++;}while(n<3);if(n=3)printf("您的密码不正确,请退出系统,谢谢使用,再见!\n");break;}else{printf("---------------请选择您要进行的操作-------------------\n");printf("| |\n"); //while(j<3);printf("| 2、查找记录|\n");printf("| 3、增加记录|\n");printf("| 4、删除记录|\n");printf("| 5、输出所有记录|\n");printf("| 6、输出所有收入记录|\n");printf("| 7、输出所有支出记录|\n");printf("||\n");printf("-----------------------------------------------------|\n");p=&b;print_message(p);do{scanf("%d",&k); //while(k>0)if(k==10)printf("感谢您使用本系统,再见!\n");if(k==2){printf("请输入您要查询的日期:");scanf("%s",data1);find_record(p,data1);}if(k==3){printf("请输入您要插入的位置:\n");scanf("%d",&lop1);printf("请输入您要添加的记录:\n");printf("日期:");scanf("%s",p0->date);printf("操作:");scanf("%s",p0->operate);printf("金额:");scanf("%d",&(p0->num));insert_record(p,p0,lop1);}if(k==4){printf("请输入您要删除的记录的位置:\n");scanf("%d",&lop2);del_record(p,lop2);}if(k==5){all_print(p);sum_num(p);}if(k==6)acc_print(p);if(k==7)pay_print(p);}while(k>0);break;}}j++;}while(j<3);printf("感谢您使用本系统,再见!\n"); }}(2)量化评分表请学生将下面成绩评定表复制到报告的最后一页(单独一页)。