Welcome Guest.


C language course design   source code to help debug

Asked by: Pamela 218 views IT July 26, 2018


Addition: How to leave for help

Addition: #include<stdio.h>#include<stdlib.h># Include<string.h>#include<conio.h>#define MAXNAME 11 //Maximum length of family member name#define MAXDETAIL 21 //Note maximum length // custom enumeration type fi_type, used to indicate income and expense typedef Enum fi type{income=1//revenue payout=-1//expenditure} fi type; //family financial information structure typedef struct fi info{int year;int month;fi type type;char name[9];float Money;char detail[11];}fi info;//structure of financial data structure typedef struct fi data{fi info info;struct fi data*next;}fi data; fi data*head;//financial data Head node void menu(); // menu function void add income(); void search income(); void delete income(); void update income(); void add payout(); void search payout(); void delete Payout(); void update payout(); void count total(); void quit(); // void sear Void delete data(fi_type type); void update data(fi_type type); //void initialize(); void save to _file(); void clear data(); fi_data *get last(); Fi_data *get_previous(fi_data *p); void input_info(fi_info *info); void show_info(fi_data *p); void menu() { printf("\n"); printf("\t\t ~~~~~ ~~~~~~~~~~~~~~~~~\n"); printf("\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~\n"); printf("\t\t\t family financial management system\n"); printf("\t\t ~~~~~~~~~~~~~~~~~~~ ~~~\n"); printf("\t\t ~~~~~~~~~~~~~~~~~~~~~~\n"); printf("\t\t* ******************************************\n"); printf(" \t\tRevenue management: "); printf("1.Add revenue"); printf(" 2.Query revenue details\n"); printf("\t\t\t 3.Delete income"); printf (" 4. Modify revenue \n"); printf("\t\t******************************** ***********\n"); printf("\t\tExpenditure Management:"); printf("5.Add Expenditure"); Printf(" 6.Query Expenditure Details\n"); printf("\t\t\t 7.Delete Expenditure"); printf(" 8.Modify Expenses\n"); printf("\t\t** *****************************************\n"); printf("\ t\t statistic: "); printf("9.statistical total income/total expenditure\n"); printf("\t\t******************* ************************\n"); printf("\t\tExit: 0. Exit system\n"); printf(" \t\t*******************************************\n\ n\n");}void main() { int selected=0; initialize(); while(selected>=0&&selected<=9) { system("cls"); menu(); printf("\t\t> Please select the action to be performed (0-9): "); if(scanf("%d",&selected)!=1||selected<0||selected>9) { printf("\t\t> The input is incorrect! Please choose a number between (0-9)! Press any key to retry "); getchar();} else { switch(selected) { case 0:exit(0);clear_data();break; case 1:add_income();save_to_file();break; case 2: Search_income();break; case 3:delete_income();save_to_file();break; case 4:update_income();save_to_file();break; case 5:add_payout();save_to_file();break; case 6:search_payout(;;break; case 7:delete_payout();save_to_file();break; case 8:update_payout();save_to_file();break; case 9:count_total();break; } } } } void add_income()//Add Revenue { fi_data *p=(fi_data *)malloc(sizeof(fi_data)); p->next=NULL; input_info(&(p->info)); p->info.type=income; if( Head==NULL) head=p; else get_last()->next=p; }void add_payout()//add expenditure{ fi_data *p=(fi_data *)malloc(sizeof(fi_data)); p-> Next=NULL; input_info(&(p->info)); p->info.typ e=payout; if(head==NULL) head=p; else get_last()->next=p; } //Enter the function void input_info(fi_info *info) { printf("\t\t>Please enter the year Month (YYYY/M)"); scanf("%d/%d",&(info->year),&(info->month));printf("\t\t>Please enter family members Name (maximum length %d): ",MAXNAME-1); scanf("%s",info->name); printf("\t\t>enter amount:"); scanf("%f" ,&(info->money)); printf("\t\t>Please enter a comment (maximum length %d):",20); scanf("%s",info->detail); } //Find the data function void search_data(fi_type type) { int year=0; int month=0; fi_data *p=NULL; int count=0; char input=' '; while(1) {printf("\t\ t>Please enter the year and month (YYYY/M)") to be queried; if(scanf("%d/%d",&year,&month)!=2) { printf("\t\t>There is an error\ n"); } else { p=head; count=0; while(p!=NULL) { if((p->info.year==year)&&(p->info.month==month) &&(p->info.type==type)) { show_info(p); system("PAUSE"); count++; }p=p->next; } if(count= =0) { printf("\t\t>data not found\n"); } printf("\t\t>continue to find other data (y or n)"); input=getchar(); if(input =='y'||input=='Y') continue; else break; } } } //Initialize the function, read the text data void initialize() {FILE?*?fp=NULL;fi_data?*p=NULL;fi_data?*last=NULL;int?count=0;fp=fopen("data.txt","rb");if(fp==NULL){fp=fopen("data.txt","w" );fclose(fp);return;}p=(fi_data*)malloc(sizeof(fi_data));memset(p,0,sizeof(fi_data));p->next=NULL;while(fread(&( P->info),sizeof(fi_info),1,fp)==1){

1 Answers

  1. +1Votes  

    It’s ok to turn on debugging directly.

    Sharon Mitchell- July 26, 2018 |