/************************************************/ /* ECE-1011 Spring 2003 */ /* Section:......... 0 */ /* Assignment:...... 2 */ /* Programmer:...... BAHN, William L. */ /* File Contents:... SOURCE CODE */ /* Filename:........ s20_key */ /* Due Date:........ 10 Feb 03 */ /* E-mail Address:.. wbahn@eas.uccs.edu */ /************************************************/ /*============== STANDARD LIBRARY INCLUDE FILES =============================*/ #include /* printf(), scanf() */ /*============== PROGRAMMER DEFINED CONSTANTS ===============================*/ /*****************************************************************************/ /* Version and Author Control */ /*****************************************************************************/ #define VERSION (2) #define REVISION (5) #define PROGRAMMER "William L. Bahn" #define LASTMODDATE "17 FEB 2003" /*****************************************************************************/ /* Parameters for a particular type of aircraft */ /*****************************************************************************/ /* AIRCRAFT_TYPE "Text String Description" */ /* MIN_GROSS (Minimum Gross Weight in pounds) */ /* MAX_GROSS (Maximum Gross Weight in pounds) */ /* FWD_CG_MINGW (Fwd CG Limit @ MIN_GROSS) */ /* FWD_CG_MAXGW (Fwd CG Limit @ MAX_GROSS) */ /* FWD_CG_BRKGW (Weight at which FWD CG begins changing) */ /* AFT_CG_MINGW (AFT CG Limit @ MIN_GROSS) */ /* AFT_CG_MAXGW (AFT CG Limit @ MAX_GROSS) */ /* AFT_CG_BRKGW (Weight at which AFT CG begins changing) */ /*****************************************************************************/ #define AIRCRAFT_TYPE "T41-B" #define MIN_GROSS (1500.0) #define MAX_GROSS (2500.0) #define FWD_CG_MINGW (35.0) #define FWD_CG_MAXGW (40.5) #define FWD_CG_BRKGW (1950.0) #define AFT_CG_MINGW (47.0) #define AFT_CG_MAXGW (47.0) #define AFT_CG_BRKGW (1500.0) /*****************************************************************************/ #define BLANKLINE printf("\n") /*===========================================================================*/ /*=========================== MAIN FUNCTION =================================*/ /*===========================================================================*/ int main(void) { /* Variable Dictionary */ double empty_wt, empty_cg; /* Aircraft Empty Weight and CG */ double fuel_wt, fuel_cg; /* Fuel Weight and CG */ double frontpax_wt, frontpax_cg; /* Front Occupants Weight and CG */ double rearpax_wt, rearpax_cg; /* Rear Occupants Weight and CG */ double baggage_wt, baggage_cg; /* Baggage Area Weight and CG */ double misc_wt, misc_cg; /* Misc. Items Weight and CG */ double gross_wt, gross_cg, gross_mom; /* Total A/C Weight, CG, and Moment */ double dx, dy; /* Dummy variables for slope cals */ double fwd_cg, aft_cg; /* Computed CG Limits */ /* Section 1 - Print out Aircraft Parameters -----------------------------*/ printf("===============================================================\n"); printf("Aircraft CG Calculator Version %i.%i\n", VERSION, REVISION); printf("Programmer: %s\n", PROGRAMMER); printf("Date of Last Mod: %s\n", LASTMODDATE); printf("===============================================================\n"); printf("This program computes the weight and balance for an aircraft\n"); printf("described by the following CG Envelope:\n"); BLANKLINE; printf("Aircraft Type: %s\n", AIRCRAFT_TYPE); BLANKLINE; printf("Gross Weight Limitations:\n"); printf(" The minimum aircraft gross weight is %7.1f pounds.\n", MIN_GROSS); printf(" The maximum aircraft gross weight is %7.1f pounds.\n", MAX_GROSS); BLANKLINE; printf("Forward CG Limitations:\n"); printf(" For Aircraft Gross Weight below %7.1f lb:\n", FWD_CG_BRKGW); printf(" FWD CG Limit is %6.2f\" aft of the datum.\n", FWD_CG_MINGW); printf(" For Aircraft Gross Weight between %7.1f lb and %7.1f lb:\n", FWD_CG_BRKGW, MAX_GROSS); printf(" FWD CG Limit moves linearly from %6.2f\" to %6.2f\".\n", FWD_CG_MINGW, FWD_CG_MAXGW); BLANKLINE; printf("Aft CG Limitations:\n"); printf(" For Aircraft Gross Weights below %7.1f lb:\n", AFT_CG_BRKGW); printf(" AFT CG Limit is %6.2f\" aft of the datum.\n", AFT_CG_MINGW); printf(" For Aircraft Gross Weights between %7.1f lb and %7.1f lb:\n", AFT_CG_BRKGW, MAX_GROSS); printf(" AFT CG Limit moves linearly from %6.2f\" to %6.2f\".\n", AFT_CG_MINGW, AFT_CG_MAXGW); printf("===============================================================\n"); /* Section 2 - Gather Data for CG Calculation ----------------------------*/ BLANKLINE; printf("===============================================================\n"); printf("Data Entry for Weight and Balance Compution:\n"); printf("NOTES:\n"); printf(" 1) Enter all weights in pounds.\n"); printf(" 2) Enter all locations in inches aft of the datum.\n"); BLANKLINE; printf("Aircraft Empty Weight:\n"); printf(" Enter the weight: ......"); scanf("%lf", &empty_wt); printf(" Enter the location:....."); scanf("%lf", &empty_cg); BLANKLINE; printf("Fuel\n"); printf(" Enter the weight: ......"); scanf("%lf", &fuel_wt); printf(" Enter the location:....."); scanf("%lf", &fuel_cg); BLANKLINE; printf("Front Seat Occupants:\n"); printf(" Enter the weight: ......"); scanf("%lf", &frontpax_wt); printf(" Enter the location:....."); scanf("%lf", &frontpax_cg); BLANKLINE; printf("Rear Seat Occupants:\n"); printf(" Enter the weight: ......"); scanf("%lf", &rearpax_wt); printf(" Enter the location:....."); scanf("%lf", &rearpax_cg); BLANKLINE; printf("Baggage Area Contents:\n"); printf(" Enter the weight: ......"); scanf("%lf", &baggage_wt); printf(" Enter the location:....."); scanf("%lf", &baggage_cg); BLANKLINE; printf("Combined Miscellaneous Items:\n"); printf(" Enter the weight: ......"); scanf("%lf", &misc_wt); printf(" Enter the location:....."); scanf("%lf", &misc_cg); printf("===============================================================\n"); /* Section 3 - Compute and output the Loading Table ----------------------*/ /* Total Up the individual item weights */ gross_wt = gross_mom = 0.0; gross_wt += empty_wt; gross_wt += fuel_wt; gross_wt += frontpax_wt; gross_wt += rearpax_wt; gross_wt += baggage_wt; gross_wt += misc_wt; /* Total Up the individual item moments */ gross_mom = 0.0; gross_mom += empty_wt*empty_cg; gross_mom += fuel_wt*fuel_cg; gross_mom += frontpax_wt*frontpax_cg; gross_mom += rearpax_wt*rearpax_cg; gross_mom += baggage_wt*baggage_cg; gross_mom += misc_wt*misc_cg; /* Compute the total CG of all the items */ gross_cg = gross_mom / gross_wt; /* Output the Loading Table */ BLANKLINE; printf("===============================================================\n"); printf("AIRCRAFT LOADING TABLE\n"); printf("Aircraft Type: %s\n", AIRCRAFT_TYPE); printf("===============================================================\n"); printf("ITEM WEIGHT (lbs) ARM (in) MOMENT (in-lbs)\n"); printf("Empty Weight %8.1f %7.2f %10.2f\n", empty_wt, empty_cg, empty_wt*empty_cg); printf("Fuel %8.1f %7.2f %10.2f\n", fuel_wt, fuel_cg, fuel_wt*fuel_cg); printf("Front Occupants %8.1f %7.2f %10.2f\n", frontpax_wt, frontpax_cg, frontpax_wt*frontpax_cg); printf("Rear Occupants %8.1f %7.2f %10.2f\n", rearpax_wt, rearpax_cg, rearpax_wt*rearpax_cg); printf("Baggage Area %8.1f %7.2f %10.2f\n", baggage_wt, baggage_cg, baggage_wt*baggage_cg); printf("Miscellaneous %8.1f %7.2f %10.2f\n", misc_wt, misc_cg, misc_wt*misc_cg); printf("===============================================================\n"); printf("TOTAL %7.1f %6.2f %9.2f\n", gross_wt, gross_cg, gross_mom); printf("===============================================================\n"); BLANKLINE; /* Section 3 - Compute and output the CG Limits --------------------------*/ /* Compute FWD CG Limit assuming it is on the sloped portion */ dx = (FWD_CG_MAXGW - FWD_CG_MINGW); dy = (MAX_GROSS - FWD_CG_BRKGW); fwd_cg = FWD_CG_MINGW + (gross_wt - FWD_CG_BRKGW)*(dx/dy); /* Compute AFT CG Limit assuming it is on the sloped portion */ dx = (AFT_CG_MAXGW - AFT_CG_MINGW); dy = (MAX_GROSS - AFT_CG_BRKGW); aft_cg = AFT_CG_MINGW + (gross_wt - AFT_CG_BRKGW)*(dx/dy); printf("===============================================================\n"); printf("Your computed CG is %5.2f\" at a gross weight of %6.1flb.\n", gross_cg, gross_wt); BLANKLINE; printf("*** Use only those lines below whose \"if\" clause is true. ***\n"); BLANKLINE; printf("MAX GROSS WEIGHT\n"); printf("If (%6.1f lb > %6.1f lb): ", gross_wt, MAX_GROSS); printf("Aircraft is over max gross weight.\n"); BLANKLINE; printf("FWD CG LIMIT\n"); printf("If (%6.1f lb <= %6.1f lb <= %6.1f): ", MIN_GROSS, gross_wt, FWD_CG_BRKGW); printf("FWD CG LIMIT = %5.2f\"\n", FWD_CG_MINGW); printf("If (%6.1f lb <= %6.1f lb <= %6.1f): ", FWD_CG_BRKGW, gross_wt, MAX_GROSS); printf("FWD CG LIMIT = %5.2f\"\n", fwd_cg); BLANKLINE; printf("AFT CG LIMIT\n"); printf("If (%6.1f lb <= %6.1f lb <= %6.1f): ", MIN_GROSS, gross_wt, AFT_CG_BRKGW); printf("AFT CG LIMIT = %5.2f\"\n", AFT_CG_MINGW); printf("If (%6.1f lb <= %6.1f lb <= %6.1f): ", AFT_CG_BRKGW, gross_wt, MAX_GROSS); printf("AFT CG LIMIT = %5.2f\"\n", aft_cg); printf("===============================================================\n"); BLANKLINE; /* End of Program --------------------------------------------------------*/ /* Pause for User to Hit Return */ while( '\n' != getchar() ); /* Clear all characters until a CR */ printf("Program Execution Finished - Hit 'RETURN' or 'ENTER' to exit program: "); getchar(); return(0); }