// CS2310 Exercise 9 // // Name _______________________ // // Chapter 13, p759 - 8 (c, d) // // Given the following declarations, write functions // to do the following tasks: // // 1. If the string in mammal is greater than // "Opossum" lexicographically, increment // counter greaterOpossum; // 2. If the string in mammal is less than or // equal to "Jackal", decrement counter // lessEqJackal. // // The animal names will be read in from file // "mammals.txt". // // Hint: use strcmp to do the comparison. Depending // on the return value of strcmp (<, =, or > 0), // determine each string comes first in the // lexicographic order. #include #include #include using namespace std; typedef char String30[31]; String30 mammal; int greaterOpossum=0; int lessEqJackal=23; // Note mammal, greaterOpossum and lessEqJackal are // declared globally and thus can be accessed anywhere // of the program. void GreaterOpossum(void) { // Write the missing code here to do the following: // If the string in mammal is greater than // "opossum" lexicographically, increment // counter greaterOpossum // Note animal names read from the file are not // capitalized. } void LessEqJackal(void) { // Write the missing code here to do the following: // If the string in mammal is less than or // equal to "jackal", decrement counter // lessEqJackal // Note animal names read from the file are not // capitalized. } int main() { ifstream mammals; mammals.open("mammals.txt"); if (!mammals) { cout << "Cannot open file mammals.txt. Program terminated!" << endl; exit(0); } // Read in animal names and update counters while (mammals) { mammals >> mammal; cout << mammal << endl; GreaterOpossum(); LessEqJackal(); } cout << endl; // Print out counters cout << "Number of mammals greater than Opossum is: " << greaterOpossum << endl; cout << "The count after deducting the number of mammals less than or equal to Jackal is: " << lessEqJackal << endl; return 0; }