Question
/* Counting letter grades */ #include /* function main begins program execution */ int main() { char grade; /* one grade */ int aCount =
/* Counting letter grades */ #include
/* function main begins program execution */ int main() {
char grade; /* one grade */ int aCount = 0, bCount = 0, cCount = 0, dCount = 0; int fCount = 0;
printf( "Enter the letter grades. " ); printf( "Enter the EOF character to end input. " );
/* loop until user types end-of-file key sequence */ while ( ( grade = getchar() ) != EOF ) {
/* determine which grade was input */ switch ( grade ) { /* switch nested in while */
case 'A': /* grade was uppercase A */
case 'a': /* or lowercase a */ ++aCount; /* increment aCount */ break; /* necessary to exit switch */
case 'B': /* grade was uppercase B */
case 'b': /* or lowercase b */ ++bCount; /* increment bCount */ break; /* exit switch */
case 'C': /* grade was uppercase C */
case 'c': /* or lowercase c */ ++cCount; /* increment cCount */ break; /* exit switch */
case 'D': /* grade was uppercase D */
case 'd': /* or lowercase d */ ++dCount; /* increment dCount */ break; /* exit switch */
case 'F': /* grade was uppercase F */
case 'f': /* or lowercase f */ ++fCount; /* increment fCount */ break; /* exit switch */
case ' ': /* ignore newlines, */ case '\t': /* tabs, */ case ' ': /* and spaces in input */
break; /* exit switch */
default: /* catch all other characters */ printf( "Incorrect letter grade entered." ); printf( " Enter a new grade. " ); break; /* optional; will exit switch anyway */
} /* end switch */
} /* end while */
/* output summary of results */ printf( " Totals for each letter grade are: " ); printf( "A: %d ", aCount ); /* number of A grades */ printf( "B: %d ", bCount ); /* number of B grades */ printf( "C: %d ", cCount ); /* number of C grades */ printf( "D: %d ", dCount ); /* number of D grades */ printf( "F: %d ", fCount ); /* number of F grades */
return 0; /* indicate program ended successfully */
} /* end function main */
What is the purpose of having two.2 .consecutive cases exp :'case 'A * :'case 'a (1 (1 ) ! What is the function of the "default".3 ? statement * What is the function of the "break".4 statement? What is the result of ? (omitting it (try it (abi 1) * Explain the function of this statement.5 * grade = getchar()) != EOF ) (Clai 1) Why do we need to use this statement.6 /* ,case ' ': /* ignore newlines /* ,case '\t': /* tabs /* case'': /* and spaces in input /* break; /* exit switch 1 (1 ) ! :Assignment.7 ********************************* ********* *************************************************** Write a program to calculate the number of population in each province (Capital, Farwaniya, Hawaley, Jahra, * .(Mubarak_Alkabeer, AlahmadeyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started