📄 travel14.c
字号:
/*****************************************************//*****************************************************//*PAGE get_first_last_dates This function traverses the itinerary linked list and returns the first departure date and the last arrival date.*/get_first_last_dates(its, first_day, last_day) struct itinerary_struct *its; struct MDY_struct *first_day, *last_day;{ int not_finished = 1; struct itinerary_struct *a; a = its; first_day->month = a->depart_date.month; first_day->day = a->depart_date.day; first_day->year = a->depart_date.year; while(not_finished){ if(a->next == END_OF_LIST) not_finished = 0; else{ a = a->next; } } /* ends while */ last_day->month = a->arrive_date.month; last_day->day = a->arrive_date.day; last_day->year = a->arrive_date.year;} /* ends get_first_last_dates *//*****************************************************//*****************************************************//*PAGE get_date This function reads the date and time and returns the date in short form in a char array.*/get_date(date_string) char date_string[];{ struct tm *time_of_day; long seconds; time(&seconds); time_of_day = localtime(&seconds); sprintf(date_string, "%d-%d-%d", time_of_day->tm_mon+1, time_of_day->tm_mday, time_of_day->tm_year);} /* ends get_date *//*****************************************************//*****************************************************//*PAGE save_GTRs This function saves the GTR linked list to the data file. You will always save at least one struct to the data file.*/save_GTRs(GTR, data_file) FILE *data_file; struct GTR_struct *GTR;{ struct GTR_struct *current; current = GTR; while(current != END_OF_LIST){ fwrite(current, sizeof(struct GTR_struct), 1, data_file); current = current->next; } /* ends while */} /* ends save_GTRs *//*****************************************************//*****************************************************//*PAGE save_transportation_cost This function saves the transportation cost linked list to the data file. You will always save at least one struct to the data file.*/save_transportation_cost(tc, data_file) FILE *data_file; struct trans_struct *tc;{ struct trans_struct *current; current = tc; while(current != END_OF_LIST){ fwrite(current, sizeof(struct trans_struct), 1, data_file); current = current->next; } /* ends while */} /* ends save_transportation_cost *//*****************************************************//*****************************************************//*PAGE save_itinerarys This function saves the itinerary linked list to the data file. You will always save at least one struct to the data file.*/save_itinerarys(its, data_file) FILE *data_file; struct itinerary_struct *its;{ struct itinerary_struct *current; current = its; while(current != END_OF_LIST){ fwrite(current, sizeof(struct itinerary_struct), 1, data_file); current = current->next; } /* ends while */} /* ends save_itinerarys *//*****************************************************//*****************************************************//*PAGE save_daily_expenses This function saves the daily expense linked list to the data file. You will always save at least one struct to the data file.*/save_daily_expenses(ds, data_file) FILE *data_file; struct daily_struct *ds;{ struct daily_struct *current; current = ds; while(current != END_OF_LIST){ fwrite(current, sizeof(struct daily_struct), 1, data_file); current = current->next; } /* ends while */} /* ends save_daily_expenses *//*****************************************************//*****************************************************//*PAGE save_rental_expenses This function saves the rental car expenses to the data file. There is only one struct. This is not a linked list.*/save_rental_expenses(rs, data_file) FILE *data_file; struct rental_struct *rs;{ fwrite(rs, sizeof(struct rental_struct), 1, data_file);} /* ends save_rental_expenses *//*****************************************************//*****************************************************//*PAGE retrieve_GTRs This function reads the GTR linked list from disk. You will always read at least one struct from disk. It returns the pointer to the front of the list.*/struct GTR_struct * retrieve_GTRs(data_file) FILE *data_file;{ int first=1, not_done=1; struct GTR_struct *current, *new1, *result; while(not_done){ new1 = (struct GTR_struct *) calloc(1, sizeof(struct GTR_struct)); new1->next = END_OF_LIST; if(first){ first = 0; result = new1; current = new1; } else{ current->next = new1; current = new1; } fread(current, sizeof(struct GTR_struct), 1, data_file); if(current->next == END_OF_LIST) not_done = 0; } /* ends while not_done */ return(result);} /* ends retrieve_GTRs *//*****************************************************//*****************************************************//*PAGE retrieve_transportation_cost This function reads the transportation cost linked list from disk. You will always read at least one struct from disk. It returns the pointer to the front of the list.*/struct trans_struct * retrieve_transportation_cost(data_file) FILE *data_file;{ int first=1, not_done=1; struct trans_struct *current, *new1, *result; while(not_done){ new1 = (struct trans_struct *) calloc(1, sizeof(struct trans_struct)); new1->next = END_OF_LIST; if(first){ first = 0; result = new1; current = new1; } else{ current->next = new1; current = new1; } fread(current, sizeof(struct trans_struct), 1, data_file); if(current->next == END_OF_LIST) not_done = 0; } /* ends while not_done */ return(result);} /* ends retrieve_transportation_cost *//*****************************************************//*****************************************************//*PAGE retrieve_itinerarys This function reads the itinerary linked list from disk. You will always read at least one struct from disk. It returns the pointer to the front of the list.*/struct itinerary_struct * retrieve_itinerarys(data_file) FILE *data_file;{ int first=1, not_done=1; struct itinerary_struct *current, *new1, *result; while(not_done){ new1 = (struct itinerary_struct *) calloc(1, sizeof(struct itinerary_struct)); new1->next = END_OF_LIST; if(first){ first = 0; result = new1; current = new1; } else{ current->next = new1; current = new1; } fread(current, sizeof(struct itinerary_struct), 1, data_file); if(current->next == END_OF_LIST) not_done = 0; } /* ends while not_done */ return(result);} /* ends retrieve_itinerarys *//*****************************************************//*****************************************************//*PAGE retrieve_daily_expenses This function reads the daily expense linked list from disk. You will always read at least one struct from disk. It returns the pointer to the front of the list.*/struct daily_struct * retrieve_daily_expenses(data_file, days) FILE *data_file; short *days;{ int first=1, not_done=1; struct daily_struct *current, *new1, *result; while(not_done){ new1 = (struct daily_struct *) calloc(1, sizeof(struct daily_struct)); new1->next = END_OF_LIST; if(first){ first = 0; result = new1; current = new1; } else{ current->next = new1; current = new1; } fread(current, sizeof(struct daily_struct), 1, data_file); *days = *days + 1; if(current->next == END_OF_LIST) not_done = 0; } /* ends while not_done */ return(result);} /* ends retrieve_daily_expenses *//*****************************************************//*****************************************************//*PAGE retrieve_rental_expenses This function reads the rental car expenses from disk. There is only one struct on the disk. This is not a linked list.*/struct rental_struct * retrieve_rental_expenses(data_file) FILE *data_file;{ struct rental_struct *result; result = (struct rental_struct *) calloc(1, sizeof(struct rental_struct)); fread(result, sizeof(struct rental_struct), 1, data_file); return(result);} /* ends retrieve_rental_expenses *//*****************************************************//*****************************************************//*PAGE print_accounting This function is the main printing routine. It calls several other routines to print the complete final travel accounting.*/print_accounting(date_string, name, ORN, days, lines, output_file, first_day, last_day, cash_advance, GTR, ts, its, ds, rs) char date_string[], name[], ORN[]; FILE *output_file; int *lines; long cash_advance; short days; struct daily_struct *ds; struct GTR_struct *GTR; struct itinerary_struct *its; struct MDY_struct *first_day, *last_day; struct trans_struct *ts; struct rental_struct *rs;{ long personal_use = 0, total_advance = 0, total_daily_cost = 0, total_expenses = 0, total_trans_cost = 0; blank_line(output_file); *lines = *lines + 1; print_header(output_file); *lines = *lines + 1; blank_line(output_file); *lines = *lines + 1; blank_line(output_file); *lines = *lines + 1; print_title(ORN, name, date_string, first_day, last_day, output_file); *lines = *lines + 4; print_advances(output_file, lines, cash_advance, GTR, &total_advance); print_equal(5, 70, output_file); increment(lines, output_file); print_trans_cost(output_file, lines, ts, &total_trans_cost); print_equal(5, 70, output_file); increment(lines, output_file); print_itinerary(output_file, lines, its); blank_line(output_file); increment(lines, output_file); print_equal(5, 70, output_file); increment(lines, output_file); print_daily(output_file, lines, ds, &total_daily_cost, first_day, last_day, its); blank_line(output_file); increment(lines, output_file); print_equal(5, 70, output_file); increment(lines, output_file); print_rental_car(rs, output_file, lines, name, &personal_use); blank_line(output_file); increment(lines, output_file); print_equal(5, 70, output_file); increment(lines, output_file); total_expenses = total_trans_cost + total_daily_cost; total_expenses = total_expenses - personal_use; print_bottom_line(output_file, lines, total_advance, total_expenses, total_trans_cost, total_daily_cost); blank_line(output_file); increment(lines, output_file);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -