//========================================================================= #define PROGRAMMER "BAHN, William" #define PROG_CODE "bahw" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "RWA 2.6" #define REVISION (0) #define TITLE "Real World Application from Section 2.6" #define SUBTITLE "Classifying Solutions as Acidic or Nonacidic" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "rwa0206.c" //========================================================================= // PROBLEM: // // The pH of a solution is given by: // pH = -log10(mc) // where mc is the molar concentation of hydronium ions in gr-atoms/liter. // // A solution is alkaline if pH > 7 and acidic if pH < 7 // // MOD TO TEXT: Classify if Neutral if 6.9 < pH <= 7.1 // Given the molar concentration, compute the pH and classify the // solution as alkaline or acidic. Print both pH and solution type. // Continue until user indicates 'End-of-File' by typing Ctrl-Z. // PSEUDOCODE // 1) GET: The first molar concentration. // 2) LOOP: Until the user enters ^Z. // 2.1) SET: pH = -log10(mc) // 2.2) PUT: The pH to the screen // 2.3) IF: pH > 7 // 2.3.1) PUT: The solution is alkaline. // 2.4) ELSE: // 2.4.1) PUT: The solution is acidic. // 2.5) GET: The next molar concentration. // 3) PUT: Program Termination Message to screen. //== INCLUDE FILES ======================================================== #include // printf(), scanf(), EOF #include // log10() //== FUNCTION PROTOTYPES ================================================== void PrintHeader(void); //== MAIN FUNCTION ======================================================== int main(void) { double pH, mc; PrintHeader(); printf("\n"); // Print a blank line printf("Enter Ctlr-Z to quit.\n"); printf("\n"); // Print a blank line printf("Enter the first molar concentration (in gm-atoms/liter): "); while(EOF != scanf("%lf", &mc)) { pH = -log10(mc); // Calculate pH per definition printf(" pH = %5.2f ", pH); if(7.1 < pH) printf("(Alkaline)\n"); else if(6.9 > pH) printf("(Acidic)\n"); else printf("(Neutral)\n"); printf("\n"); // Print a blank line printf("Enter the next molar concentration (in gm-atoms/liter): "); } printf("\n"); // Carriage Return for input line after ^Z is entered. printf("\n"); // Print a blank line printf("PROGRAM TERMINATED BY USER\n"); return(0); } //== SUPPORT FUNCTIONS ==================================================== void PrintHeader(void) { printf("========================================" "=======================================\n"); printf("Course....... %s-%i (%s %i)\n", COURSE, SECTION, TERM, YEAR); printf("Programmer... %s (%s)\n", PROGRAMMER, PROG_CODE); printf("Assignment... %s (Rev %i) (Source Code in %s)\n", ASSIGNMENT, REVISION, FILENAME); printf("Description.. %s\n", TITLE); printf(" %s\n", SUBTITLE); printf("========================================" "=======================================\n"); return; }