⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 travel.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 5 页
字号:
/*

   Travel Accounting Program

   Dwayne Phillips
   November 1992

   Command Line:
      travel [return]

   Purpose:
      This program performs the same function as the
      travel accounting system used by the secretaries
      on the Wang Alliance system prior to January 1993.

      It takes input concerning a person's trip, stores
      that to a file for later use, calculates the
      money due or due back, and prints an accounting.

      It's major advantages are: (1) no more Wang, and
      (2) it saves the accounting data to a disk for
      later retrieval, editing, and printing.  The Wang
      program did not save the accounting to disk so you
      could not edit it.

      This program will run on the UNIX workstations and
      (with a minor change) on an IBM PC or clone.  It is
      written entirely in C and is basic terminal and file
      input and output.

   Files:
      The program uses two files: (1) the data file,
      and (2) a print file.

      Data File
         The data file contains the accounting data
         entered on a traveller.  This data contains
         information about the traveller, advances, and
         expenses.

         Each travel accounting has certain data items associated
         with it.  These include:
      
            Name - name of the person traveling (1)
            ORN - ORN for this travel accounting (1)
            Cash advance amount (1)
            GTR or Ticket Advance Amount - (1,many)
            Transportation Costs (1,many)
               Mode
               Carrier
               Travel Class
               Amount
            Itenerary (1,many)
               Depart Date
               Leaving Location
               Depart Time
               Depart Via
               Arrive Date
               Arrive Location
               Arrive Time
            Daily Expense (1,many)
               Max Lodging
               MIE
               Actual Lodging
               POV Miles
               POV Description
               Rental Car
               Rental Car Description
               Taxi
               Taxi Description
               Parking
               Parking Description
               Official Phone   
               Official Phone   Description
               Other Expenses
               Other Description
            Rental Car (1)
               Personal Mileage
               Total Mileage
               Total Gas

         I store these items in a data file in the 
         following order:
               name - L chars
               ORN  - L chars
               cash_advance - long
               GTR - struct GTR_struct
               ts  - struct trans_struct
               its - struct itinerary_struct
               ds  - struct daily_struct
               rs  - struct rental_struct
            

      Print File
         This program prints the results in a nice looking
         form just like the Wang program did.  Since the
         workstations are on a network with many different
         printers, the program "prints" to a temporary
         print file, and then uses the "system" command
         to print that file to a network printer.  The
         use enters the name of the desired netowrk
         printer.

   Linked Lists:
      Most of the information about the traveller is
      kept in linked lists of structures.  This is 
      because you do not know how many pieces of data
      the traveller will have when the program starts.
      Therefore, you use a linked list and allocate
      new nodes in the list as you need them.
         
      I always create at least one blank struct in
      the linked list.  That way, you can write
      something to the data file and read something
      back.

   Money:
      All money in this progam is kept in penneys
      using a long variable.  There are routines that
      transform this penney value to a float value for
      keyboard input and display and print output.

   POV:
      The POV money is kept in a long, but it is in
      penneys times ten.  This will accomodate fractions
      of cents.  For example, POV=265 for 26.5 cents a
      mile.  The POV calculations take this into account
      and divide by 10 at the appropriate time.

   Possibile Changes:
      There are three global variables you will need
      to change in the future.  These are (1) MIE 
      rates and (2) POV_RATE.  These change from
      time to time with inflation and you must update
      them.  They are in the define area before the
      main program.

   UNIX and DOS Versions:
      This program is very basic C and will run on
      UNIX and DOS platforms (and probably others too).
      You must set the values of the UNIX_SYSTEM and
      DOS_SYSTEM global variables before compiling.
      Just set them to 1 and 0.  These are in the 
      define area fbefore the main program.

   Revision History:
      Version 1 - February 1993
      Version 1.01 - 9 February 1993 
         Made a small change to get_money so it would
         not lose a penney.
      Version 1.1 - 12 February 1993
         Added the rental car structure.  Previous versions
         did not do this because the secrataries did
         not need it.  They changed their minds, so 
         I added it.
      Version 1.2 - 22 February 1993
         Made a change in the print_daily subroutine.
         If your actual lodging exceeds the max allowed
         lodging, then you must use the max lodging
         in calculations.
      Version 1.3 - 20 April 1993
         Made several changes:
         (1) Added 3 more MIE values.  Earlier versions
             only used MIE1 and MIE2.  This version uses
             MIE1 through MIE5.  This is because our
             organization changed the meals and incidental
             expense rates for the cities.  So, I
             added a couple of lines of code to the 
             MIE loop in the routines 
             edit_daily_expenses and get_daily_expenses.
             DP - 4-15-93
         (2) The program now displays the name of the
             date file right after it closes that file.
             This will help the user know where the data
             is stored.
         (3) The DOS_SYSTEM version of the program gets
             the data file name directly from the user
             for new cases.  When the user enters a file
             name, the program checks for the existance
             of that file.  If it already exists, the program
             asks for another file name.
         (4) Changed several edit functions so you can
             skip to the end of a long linked list.
             The changes were in edit_trans_cost
             edit_intinerary edit_daily_expenses
      Version 1.4 - 8 September 1993
         I changed all occurences of SAD to CAC to reflect
         our new division name.
      Version 1.5 - 21 April 1994
         (1) I ported this to Microsoft Windows using the 
             Visual C/C++ tool version 1.0.  I left it as a
             text input and output program and used the 
             Microsoft QuickWin application option.  
         (2) Microsoft did not like the "system" call so I
             added a dos_print_file function.
         (3) I revised how I switch from UNIX to DOS.  Instead
             of using ifs I now use ifdefs.
         (4) I removed all of the underscore characters
             and backspace characters from the user
             input routines.  These were always giving
             me portability problems.

*/
/*****************************************************/
/*****************************************************/
/*PAGE Includes and data structures */

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

#define L            100
#define LPP           66
#define TAB            5
#define END_OF_LIST 0x00

   /* Here are the money values that
      change with inflation.  Recall, the 
      POV_RATE is in cents times ten.  The
      MIE rates are in cents. 

      Changed from 3 MIE rates to 5 MIE
      rates - DP - 4/15/93 
      
      Change - added the letter L
      after the numbers - DP - 4-21-94 */      
      
#define MIE1           0L
#define MIE2        2600L
#define MIE3        3000L
#define MIE4        3400L
#define MIE5        3800L
#define POV_RATE     250L

   /* Here are the globals you set before
      compiling for UNIX or DOS. 
      
      To run the UNIX version you need
      #ifdef UNIX_SYSTEM
      #undef DOS_SYSTEM
      
      To run the DOS version you need
      #undef UNIX_SYSTEM
      #ifdef DOS_SYSTEM */
      
#undef  UNIX_SYSTEM
#define DOS_SYSTEM     1



   /* Here are the structures.  Most of these are
      for linked lists that the program creates
      dynamically as it goes along. */

   /* The Month-Day-Year Structure */
struct MDY_struct{
   short month;
   short day;
   short year;
};

   /* The Transportation Cost Structure */
struct trans_struct{
   char   mode[L];
   char   carrier[L];
   char   travel_class[L];
   long   amount;
   struct trans_struct *next;
};

   /* The Itenerary Structure */
struct itinerary_struct{
   struct MDY_struct depart_date;
   char   leave_loc[L];
   long   depart_time;
   char   depart_via[L];
   struct MDY_struct arrive_date;
   char   arrive_loc[L];
   long   arrive_time;
   struct itinerary_struct *next;
};

   /* The Daily Expense Structure */
struct daily_struct{
   struct MDY_struct today;
   long   max_lodging;
   long   mie;
   long   actual_lodging;
   long   pov_miles;
   char   pov_desc[L];
   long   rental_car;
   char   rental_car_desc[L];
   long   taxi;
   char   taxi_desc[L];
   long   parking;
   char   parking_desc[L];
   long   phone;
   char   phone_desc[L];
   long   other;
   char   other_desc[L];
   struct daily_struct *next;
};

   /* The GTR Advance Structure */
struct GTR_struct{
   long   GTR;
   struct GTR_struct *next;
};

   /* The Rental Car Structure */
struct rental_struct{
   long personal_mileage;
   long total_mileage;
   long total_gas;
};


   /* Here are the functions I needed to define. */
float  dollars_of();
long   calculate_mie();
long   get_money();
long   pennies_of();
struct GTR_struct        * get_GTRs();
struct trans_struct      * get_transportation_cost();
struct itinerary_struct  * get_itinerarys();
struct daily_struct      * get_daily_expenses();
struct rental_struct     * get_rental_expenses();
struct GTR_struct        * retrieve_GTRs();
struct trans_struct      * retrieve_transportation_cost();
struct itinerary_struct  * retrieve_itinerarys();
struct daily_struct      * retrieve_daily_expenses();
struct rental_struct     * retrieve_rental_expenses();
struct itinerary_struct  * traverse_itinerary();
/*****************************************************/
/*****************************************************/
/*PAGE main */

main(argc, argv)
   int  argc;
   char *argv[];
{
   int   choice, i, not_finished = 1, lines=0;
   long  cash_advance; /* the cash advance           */ 
   short days=0;

   char  data_file_name[L],
         date_string[L],
         name[L],
         ORN[L],
         print[L],
         print_file_name[L],
         printer_name[L],
         r[L];

      /* Declare the two files */
   FILE *data_file, *print_file;
       
      /* Declare the pointers for the
         linked lists. */
   struct GTR_struct       *GTR;
   struct trans_struct     *ts;
   struct itinerary_struct *its;
   struct daily_struct     *ds;
   struct rental_struct    *rs;
   struct MDY_struct       first_day, last_day;


   get_date(date_string);

   GTR = END_OF_LIST;
   ts  = END_OF_LIST;
   its = END_OF_LIST;
   ds  = END_OF_LIST;
   rs  = END_OF_LIST;


      /* Start the basic loop which continues
         until the user says quit. */
   while(not_finished){
      show_main_menu();
      gets(r);
      choice = atoi(r);

       switch(choice){
          case 0:
             printf("\nTHE END\n\n");
             not_finished = 0;
             break;


                  /* Process new travel accounting */
          case 1:
             printf("\ncase 1");

                /* Get the input from the user */

                /* get traveller's name and ORN */
             get_name(name);
             get_orn(ORN);
 
             get_data_file_name(name, date_string, data_file_name);
             data_file = fopen(data_file_name, "w");
             if(data_file == '\0'){
                printf("\nERROR: Could not create data file %s",
                          data_file_name);
                exit(-1);
             }  /* ends opening data file */
 
                /* get the Cash Advance */
             printf("\n\tCash Advance Amount? ");
             cash_advance = get_money();
       
                /* get the GTR or Ticket Advance(s) */
             GTR = get_GTRs();
 
                /* get the transportation cost structure(s) */
             ts = get_transportation_cost();
 
                /* get the itinerary structure(s) */
             its = get_itinerarys();
             get_first_last_dates(its, &first_day, &last_day);
         
                /* get the daily expenses */
             ds = get_daily_expenses(&first_day, &last_day, &days);

                /* get the rental car expenses if any */
             rs = get_rental_expenses();
 
                /* save the data to the data file */
             fwrite(name, (L*sizeof(char)), 1, data_file);
             fwrite(ORN,  (L*sizeof(char)), 1, data_file);
             fwrite(&cash_advance, sizeof(long), 1, data_file);
             save_GTRs(GTR, data_file);
             save_transportation_cost(ts, data_file);
             save_itinerarys(its, data_file);
             save_daily_expenses(ds, data_file);
             save_rental_expenses(rs, data_file);
             fclose(data_file);
             printf("\n\nWrote your data to file: %s",
                    data_file_name);

             printf("\nDo you want to print? (y or n)");
             gets(print);

             if(print[0] == 'y' || print[0] == 'Y'){
                tmpnam(print_file_name);
                print_file = fopen(print_file_name, "wt");
                if(print_file == '\0'){
                   printf("\nERROR Could not open print file %s",
                           print_file_name);
                   exit(2);
                }  /* ends if could not open print file */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -