/************************************************/ /* ECE-1011 Spring 2003 */ /* Section:......... 0 */ /* Assignment:...... 3 */ /* Programmer:...... BAHN, William L. */ /* File Contents:... SOURCE CODE */ /* Filename:........ s30_key */ /* Due Date:........ 17 Feb 03 */ /* E-mail Address:.. wbahn@eas.uccs.edu */ /************************************************/ /*============== STANDARD LIBRARY INCLUDE FILES =============================*/ #include /* printf(), scanf() */ /*============== PROGRAMMER DEFINED CONSTANTS ===============================*/ /*****************************************************************************/ /* Version and Author Control */ /*****************************************************************************/ #define HOMEWORK (3) #define VERSION (3) #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) */ /* */ /* NOTE: If a particular CG Limit is static (does not change with weight) */ /* then code the corresponding Break Weight as MAX_GROSS. */ /*****************************************************************************/ #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 (MAX_GROSS) /*****************************************************************************/ /* Loading Condition Codes */ /*****************************************************************************/ #define WITHIN_CG (0) #define OVR_LOADED (1) #define FWD_LOADED (2) #define AFT_LOADED (3) /*****************************************************************************/ /* Symbolic Constants that are strictly internal to program */ /*****************************************************************************/ #define BLANKLINE printf("\n") #define TRUE (1==1) #define FALSE (!TRUE) /*****************************************************************************/ /*===========================================================================*/ /*=========================== MAIN FUNCTION =================================*/ /*===========================================================================*/ int main(void) { /* Variable Dictionary */ double item_wt, item_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 */ int item; int response; int invalidresponse; int continueflag; int LoadingCondition; /* Section 1 - Print out Aircraft Parameters -----------------------------*/ printf("===============================================================\n"); printf("Aircraft CG Calculator Version %i.%i\n", HOMEWORK, VERSION); printf("Programmer: %s\n", PROGRAMMER); printf("Date of Last Mod: %s\n", LASTMODDATE); printf("===============================================================\n"); BLANKLINE; 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"); if(FWD_CG_BRKGW < MAX_GROSS) /* Sloped portion of FWD CG Limit exists */ { printf(" For Aircraft Gross Weights 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); } else /* No sloped portion of FWD CG Limit exists */ { printf(" For Aircraft Gross Weights below %7.1f lb:\n", MAX_GROSS); printf(" FWD CG Limit is %6.2f\" aft of the datum.\n", FWD_CG_MINGW); } BLANKLINE; if(AFT_CG_BRKGW < MAX_GROSS) /* Sloped portion of AFT CG Limit exists */ { 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); } else /* No sloped portion of AFT CG Limit exists */ { printf(" For Aircraft Gross Weights below %7.1f lb:\n", MAX_GROSS); printf(" AFT CG Limit is %6.2f\" aft of the datum.\n", AFT_CG_MINGW); } BLANKLINE; /* Section 2 - Gather Data for CG Calculation ----------------------------*/ printf("===============================================================\n"); printf("Data Entry for Weight and Balance Computation:\n"); printf("===============================================================\n"); BLANKLINE; printf("NOTES:\n"); printf(" 1) Enter all weights in pounds.\n"); printf(" 2) Enter all locations in inches aft of the datum.\n"); BLANKLINE; gross_wt = 0.0; /* Initialize Gross Weight */ gross_mom = 0.0; /* Initialize Total Moment */ item = 0; /* Initialize Item Counter */ printf("Present Gross Weight: %6.1f lb Present CG Location: N/A\n", gross_wt); BLANKLINE; do { printf("For Item #%i:\n", ++item); printf(" Enter the weight: ...... "); scanf("%lf", &item_wt); printf(" Enter the location:..... "); scanf("%lf", &item_cg); BLANKLINE; gross_wt += item_wt; gross_mom += item_wt*item_cg; gross_cg = gross_mom / gross_wt; printf("New Gross Weight: %.1f lb New CG Location: %.2f\".\n", gross_wt, gross_cg); BLANKLINE; do { printf("Are there more items to enter? (Y/N): "); while( '\n' == (response = getchar()) ); /* Catch first character after a CR */ switch(response) { case ('Y'): case ('y'): continueflag = TRUE; invalidresponse = FALSE; break; case ('N'): case ('n'): continueflag = FALSE; invalidresponse = FALSE; break; default : printf("Invalid Entry - Try Again.\n"); invalidresponse = TRUE; break; } while( '\n' != (response = getchar()) ); /* Clear all characters until a CR */ }while (invalidresponse); } while (continueflag); BLANKLINE; /* Section 3 - Compute and output the Loading Table ----------------------*/ /* THIS SECTION SKIPPED IN THIS HOMEWORK ASSIGNMENT */ /* Section 4 - Compute and output the CG Limits --------------------------*/ printf("===============================================================\n"); printf("AIRCRAFT WEIGHT AND BALANCE REPORT \n"); printf("===============================================================\n"); BLANKLINE; printf("Your computed CG is %5.2f\" at a gross weight of %6.1f lb.\n", gross_cg, gross_wt); BLANKLINE; /* Initial values for these parameters - will be overridden if wrong */ LoadingCondition = WITHIN_CG; fwd_cg = FWD_CG_MINGW; aft_cg = AFT_CG_MINGW; /* Check for Over MAX Gross Weight Condition */ if(gross_wt > MAX_GROSS) { LoadingCondition = OVR_LOADED; } /* Compute CG Limits */ if(OVR_LOADED != LoadingCondition) /* If over MAX_GROSS, no CG Limits exist */ { /* FWD LIMIT */ if(FWD_CG_BRKGW < MAX_GROSS) /* Sloped portion of FWD CG Limit exists */ { if(FWD_CG_BRKGW < gross_wt) /* A/C GW lies on sloped portion */ { /* Compute FWD CG Limit 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); } } /* AFT LIMIT */ if(AFT_CG_BRKGW < MAX_GROSS) /* Sloped portion of AFT CG Limit exists */ { if(AFT_CG_BRKGW < gross_wt) /* A/C GW lies on sloped portion */ { /* Compute AFT CG Limit 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); } } /* Determine Loading Condition if out of limits FWD or AFT */ if(gross_cg < fwd_cg) LoadingCondition = FWD_LOADED; if(gross_cg > aft_cg) LoadingCondition = AFT_LOADED; } /* The first switch() statement performs the following pseudocode step: */ /* HANDLE OVER GROSS CONDITION */ /* if (overloaded) */ /* print out overload message including max gross weight value. */ /* else */ /* print out FWD and AFT CG Limits at the total gross weight. */ switch(LoadingCondition) { case (OVR_LOADED) : printf("*** DANGER *** OVERLOADED!\n"); BLANKLINE; printf("Aircraft exceeds the max allowable gross "); printf("weight by %6.1f lb.\n", (gross_wt - MAX_GROSS)); break; default: printf("At this weight your CG Limits are "); printf("FWD: %5.1f\" and AFT: %5.1f\"\n", fwd_cg, aft_cg); break; } BLANKLINE; /* The second switch() statement performs the following pseudocode */ /* HANDLE UNDER MAX GROSS CONDITIONS */ /* if (overloaded) */ /* do nothing (already handled above) */ /* else */ /* print out message appropriate to condition. */ switch(LoadingCondition) { case (FWD_LOADED) : printf("*** DANGER *** FORWARD LOADED!\n"); BLANKLINE; printf("Aircraft exceeds the forward CG limit by "); printf("%.1f\".\n", (fwd_cg - gross_cg)); break; case (AFT_LOADED) : printf("*** DANGER *** AFT LOADED!\n"); BLANKLINE; printf("Aircraft exceeds the aft CG limit by "); printf("%.1f\".\n", (gross_cg - aft_cg)); break; case (WITHIN_CG) : printf("*** SAFE ***\n"); BLANKLINE; printf("Aircraft loaded within allowed weight "); printf("and balance limits.\n"); break; } BLANKLINE; printf("===============================================================\n"); BLANKLINE; /* End of Program --------------------------------------------------------*/ /* Pause for User to Hit Return */ printf("Program Execution Finished - Hit 'RETURN' or 'ENTER' to exit program: "); getchar(); return(0); }