logo资料库

C++家庭财务管理系统.doc

第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
资料共10页,剩余部分请下载后查看
#include #include #include #include typedef struct InComeSystem { char name[8]; char InComeWay[12]; int HowMuch; struct InComeSystem* next; }ICSystem,*ICSystem_; typedef struct OutComeSystem { char name[8]; char OutComeWay[12]; int HowMuch; struct OutComeSystem* next; }OCSystem,*OCSystem_; int i=0; 删除成功 //全局变量,以后会用到删除链表成员的判断,分别赋予不同的值,判断是否 /********输入新节点*********/ ICSystem* InputNew() { ICSystem *pNewNode=NULL; //新结点 pNewNode=new ICSystem; pNewNode->next=NULL; //新结点插入到单链表的尾部,pNewNode->pNext 为空 //输入新结点的家庭财务收入信息(姓名,收入方式,具体金额) printf("请输入家庭收入信息[收入者姓名,收入方式(如工资、股票),收入金额]:\n"); printf("========================================="); printf("\n 收入者姓 名:"); scanf("%s",&pNewNode->name); fflush(stdin); printf("收入的方 式:"); scanf("%s",&pNewNode->InComeWay); fflush(stdin); printf("收入的金 额:"); scanf("%d",&pNewNode->HowMuch); fflush(stdin); printf("======================================\n"); return pNewNode; }
/********建立链表************/ struct InComeSystem *creat() { ICSystem *pHead=NULL; ICSystem *pTail=NULL; //当前的尾部结点 ICSystem *pNewNode=NULL; //新结点 char comfirm; while(1) { pNewNode=new ICSystem; pNewNode->next=NULL; //新结点插入到单链表的尾部,pNewNode->pNext 为空 pNewNode=InputNew(); if (pHead==NULL) { pHead=pTail=pNewNode;//如果插入的为第一个结点,则它既是首结点也是尾结点。 } else { //往尾部添加节点 pTail->next=pNewNode;//把新结点接到原链表的后面 pTail=pNewNode; //当前新结点设为尾结点 } fflush(stdin);//清除输入缓冲区 printf("继续增加吗?(Y/N):"); scanf("%c",&comfirm); if (comfirm=='N'||comfirm=='n') } break; //是否继续增加结点 // delete pNewNode; 这里是中途 break 退出,保存有数据,不能直接 delete return pHead; } //-------------------------从头部开始遍历并输出结果---------------------------- void OutputList(ICSystem *head) { if (head==NULL) { printf("链表中数据为空!"); return; }
//财务收入信息(姓名,收入方式,具体金额) printf(" 家庭财务收入信 \n"); printf("======================================\n"); printf("姓名\t\t 方式\t\t 金额\t\t\n"); ICSystem *pCur=head; while(pCur!=NULL) { printf("%s\t\t%s\t\t%d\t\t\n",pCur->name,pCur->InComeWay,pCur->HowMuch) pCur=pCur->next; } 息 ; } //-------------------头部插入新节点--------------------- ICSystem* InsertByHead(ICSystem *head,ICSystem *pNew) { ICSystem *pNewHead=NULL; pNew->next=head; pNewHead=pNew; return pNewHead; //返回新的头部 //新结点的下一结点是头部 } //--------------------删除任意节点------------------------ ICSystem* { DeleteNode(ICSystem *head,char name[10],char way[10],int howmuch) ICSystem *pCur=head; ICSystem *pPre=head; ICSystem *pNewHead=head; while(pCur!=NULL) { if((strcmp(pCur->name,name)==0) && (strcmp(pCur->InComeWay,way)==0) && ((pCur->HowMuch==howmuch)?1:0)) break; //如果找到结点,则退出 else i=0; //设定全局变量 i 等于 0,表示不存在次节点 pPre=pCur; pCur=pCur->next; //pPre 记录尾结点的前一个结点 } if(pCur==NULL) {
printf("没有找到节点"); return head; i=0; //设定全局变量 i 等于 0,表示不存在该节点 } else { if(pCur==head) { //如果找的记录是头部结点 pNewHead=pCur->next; delete pCur; i=1; //设定全局变量 i 等于 1,表示存在该节点,并且删除成功 } else {//任意结点 pPre->next=pCur->next; //前一结点的 next 是下个结点的 next, //即前一结点的下一结点是 它下下个结点,把 pCur 断开. //pCur->pNext=NULL; delete pCur; //删除被断开的 pCur i=1; //设定全局变量 i 等于 1,表示存在该节点,并且删除成功 } } return pNewHead; //返回 } /****************************************************************************** */ /***********************以上代码是收入模块的所有操作 ****************************/ /****************************************************************************** */ /********输入新节点*********/ OCSystem* InputNew_() { OCSystem *pNewNode=NULL; //新结点 pNewNode=new OCSystem; pNewNode->next=NULL; //新结点插入到单链表的尾部,pNewNode->next 为空 //输入新结点的家庭财务支出信息(姓名,收入方式,具体金额) printf("请输入家庭支出信息[消费者姓名,消费方式(如工资、股票),消费金额]:\n"); printf("========================================="); printf("\n 消费者姓 名:"); scanf("%s",&pNewNode->name); fflush(stdin); printf("消费的方
式:"); scanf("%s",&pNewNode->OutComeWay); fflush(stdin); printf("消费的金 额:"); scanf("%d",&pNewNode->HowMuch); fflush(stdin); printf("======================================\n"); return pNewNode; } /********建立链表************/ struct OutComeSystem *creat_() { OCSystem *pHead=NULL; OCSystem *pTail=NULL; //当前的尾部结点 OCSystem *pNewNode=NULL; //新结点 char comfirm; while(1) { pNewNode=new OCSystem; pNewNode->next=NULL; //新结点插入到单链表的尾部,pNewNode->next 为空 pNewNode=InputNew_(); if (pHead==NULL) { pHead=pTail=pNewNode;//如果插入的为第一个结点,则它既是首结点也是尾结点。 } else { //往尾部添加节点 pTail->next=pNewNode;//把新结点接到原链表的后面 pTail=pNewNode; //当前新结点设为尾结点 } fflush(stdin);//清除输入缓冲区 printf("继续增加吗?(Y/N):"); scanf("%c",&comfirm); if (comfirm=='N'||comfirm=='n') } break; //是否继续增加结点 // delete pNewNode; 这里是中途 break 退出,保存有数据,不能直接 delete return pHead; } //-------------------------从头部开始遍历并输出结果---------------------------- void OutputList_(OCSystem *head)
{ if (head==NULL) { printf("链表中数据为空!"); return; } 息 h); } //财务支出信息(姓名,支出方式,具体金额) printf(" 家庭财务支出信 \n"); printf("======================================\n"); printf("姓名\t\t 方式\t\t 金额\t\t\n"); OCSystem *pCur=head; while(pCur!=NULL) { printf("%s\t\t%s\t\t%d\t\t\n",pCur->name,pCur->OutComeWay,pCur->HowMuc pCur=pCur->next; } //-------------------头部插入新节点--------------------- OCSystem* InsertByHead_(OCSystem *head,OCSystem *pNew) { OCSystem *pNewHead=NULL; pNew->next=head; pNewHead=pNew; return pNewHead; //返回新的头部 //新结点的下一结点是头部 } //--------------------删除任意节点------------------------ OCSystem* { DeleteNode_(OCSystem *head,char name[10],char way[10],int howmuch) OCSystem *pCur=head; OCSystem *pPre=head; OCSystem *pNewHead=head; while(pCur!=NULL) { if((strcmp(pCur->name,name)==0) && (strcmp(pCur->OutComeWay,way)==0) && ((pCur->HowMuch==howmuch)?1:0)) break; //如果找到结点,则退出 else i=0; //设定全局变量 i 等于 0,表示不存在次节点
pPre=pCur; pCur=pCur->next; //pPre 记录尾结点的前一个结点 } if(pCur==NULL) { printf("没有找到节点"); return head; i=0; //设定全局变量 i 等于 0,表示不存在该节点 } else { if(pCur==head) { //如果找的记录是头部结点 pNewHead=pCur->next; delete pCur; i=1; //设定全局变量 i 等于 1,表示存在该节点,并且删除成功 } else {//任意结点 pPre->next=pCur->next; //前一结点的 next 是下个结点的 next, //即前一结点的下一结点是 它下下个结点,把 pCur 断开. //pCur->pNext=NULL; delete pCur; //删除被断开的 pCur i=1; //设定全局变量 i 等于 1,表示存在该节点,并且删除成功 } } return pNewHead; //返回 } /****************************************************************************** */ /***********************以上代码是支出模块的所有操作 ****************************/ /****************************************************************************** */ void menu(void) { system("cls"); (单向链表)家庭财务管理系统\n"); printf("\n\t\t\t printf("\t\t\t|————————————————|\n"); printf("\t\t\t|\t printf("\t\t\t|\t [1] 建立收入数据表 \t |\n"); \t |\n");
printf("\t\t\t|\t [3] 插入新收入信息\t |\n"); printf("\t\t\t|\t [5] 删除某收入信息\t |\n"); printf("\t\t\t|\t [7] 显示收入表信息 \t |\n"); printf("\t\t\t|\t [0] 退 出 \t\t |\n"); printf("\t\t\t|\t printf("\t\t\t|————————————————|\n"); \t |\n"); printf("\t\t\t|————————————————|\n"); printf("\t\t\t|\t printf("\t\t\t|\t [2] 建立消费数据表 \t |\n"); printf("\t\t\t|\t [4] 插入新消费信息\t |\n"); printf("\t\t\t|\t [6] 删除某消费信息\t |\n"); printf("\t\t\t|\t [8] 显示消费表信息 \t |\n"); printf("\t\t\t|\t [0] 退 出 \t\t |\n"); printf("\t\t\t|\t printf("\t\t\t|————————————————|\n"); printf("\t\t\t 请输入你的选项(0-8):"); \t |\n"); \t |\n"); } void main() { int choose; ICSystem *phead=NULL; OCSystem *phead_=NULL; ICSystem *pNew=NULL; OCSystem *pNew_=NULL; static char name[10]; char name_[10]; char icway[10]; char icway_[10]; int int money; money_; static static static static static while(1) { menu();//显示菜单 fflush(stdin);//清除输入缓冲区 scanf("%d[0-9]",&choose); system("cls"); switch(choose) { case 1: //建立新表 phead=creat(); break; case 2:
分享到:
收藏