个人记账系统课程设计报告

实现代码如下:

APtr del(APtr headPtr) {

APtr p1; APtr p2; int n,i; char date[12];

if(headPtr==NULL) { printf(\ return (headPtr); } printf(\选择删除方式,输入序号:\\n\ printf(\按序号删除一条记录\\n\ \按时间删除一条记录\\n\ \删除全部记录\\n\ scanf(\ if(i==1) { printf(\输入要删除的记录序号:\ scanf(\ p1=headPtr;

while(p1->num!=n&&p1->next!=NULL) {

11

p2=p1; p1=p1->next; }

if(p1->num==n) //p1的num等于n {

if(p1==headPtr) { headPtr=headPtr->next; }

else { p2->next=p1->next; }

free(p1); printf(\删除成功\\n\ } else

printf(\记录不存在,序号错误\\n\ }

else if(i==2) { printf(\输入要删除记录的日期:\ scanf(\ p1=headPtr;

while(strcmp(date,p1->date)!=0&& p1->next!=NULL) { p2=p1; p1=p1->next; } if(strcmp(date,p1->date)==0) { if(p1==headPtr) { headPtr=headPtr->next; } else { p2->next=p1->next; } free(p1); printf(\删除成功\\n\ }

12

else printf(\记录不存在\\n\ } else if(i==3) {

while(headPtr!=NULL) {

p1=headPtr; headPtr=headPtr->next; free(p1); } printf(\删除成功\\n\ }

return(headPtr); }

4.账单查找

实现代码如下: /*4.按num查询*/

APtr num_search(APtr headPtr,int num) {

APtr cPtr;

printf(\ \ if (headPtr->num==num) printf(\

headPtr->date,headPtr->in_out,headPtr->amount,headPtr->kind,headPtr->remain); else {

cPtr=headPtr;

13

while (cPtr!=NULL&&cPtr->num!=num) {

cPtr=cPtr->next; }

if (cPtr!=NULL) {

printf(\ cPtr->date,cPtr->in_out,cPtr->amount,cPtr->kind,cPtr->remain); return cPtr; } else printf(\该条记录不存在\\n\ } return cPtr; }

/*5.按date查询*/

void date_search(APtr headPtr,char date[]) {

APtr cPtr;

int m=0;

printf(\ \ cPtr=headPtr;

while(cPtr!=NULL) { if (strcmp(cPtr->date,date)==0) { printf(\ cPtr->date,cPtr->in_out,cPtr->amount,cPtr->kind,cPtr->remain); m=m+1; }

cPtr=cPtr->next; } if(m==0) { printf(\该条记录不存在\\n\ } }

5.账单排序浏览

14

实现代码如下:

void date_sort(APtr *sPtr) {

APtr pPtr=NULL,cPtr=NULL,t1Ptr=NULL,t2Ptr=NULL; int i,j;

for (i=0;i

pPtr=*sPtr; cPtr=(*sPtr)->next; for (j=0;j

if (strcmp(pPtr->date,cPtr->date)>0&&pPtr==*sPtr) {

pPtr->next=cPtr->next; cPtr->next=pPtr; t1Ptr=pPtr; pPtr=cPtr; cPtr=t1Ptr; *sPtr=pPtr; } else {

if (strcmp(pPtr->date,cPtr->date)>0) {

t1Ptr->next=cPtr; cPtr->next=pPtr; pPtr->next=t2Ptr; t1Ptr=pPtr; pPtr=cPtr; cPtr=t1Ptr; } }

if (cPtr->next!=NULL) {

t1Ptr=pPtr; pPtr=cPtr;

cPtr=cPtr->next; t2Ptr=cPtr->next;

15

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4