/* JUST DO PART 2 FOR NOW! */ #include #include #define MAX 33 /* CSC 15 Lab 10 This lab allows you to: 1. Do more problems with arrays and strings 2. Review Object Oriented concepts PART 1: Reminder: lower case alphabetical characters have ascii values 97-122, and upper case alphabetical characters have values 65-90. (int) 'A' gives you 65, and (char) 65 gives you 'A'. Implement case-insensitive equality of strings. That is, we want a function "ciequal" that takes two strings as arguments and return true if they contain the same characters regardless of case. For example, ciequal("12ABC","12abc") should return true, because all the alphabetical characters are equal regardless of case. You should break this problem down into writing several functions: */ // The following function should return 1 if the char parameter is an // Upper case alphabetical character, -1 if it's a lower case alphabetical // character, and 2 if it's not an alphabetical character (such // as '5' or '*'.) int determineType(char c1) { ... } // Use the above function to test if two chars are equal regardless of case // Hint: consider the following cases: // If one char is upper case, the other char is lower case, then // the difference between the ascii values of the two chars should be // exactly 32 (97-65). Note the sum of the results of calling determineType // on the two chars will be exactly 0 if the chars are of opposite case. // If they are not of opposite cases, then their ascii values must // be identical in order for them to be consider equal. bool cisamechar(char c1, char c2) { ... } // Now write the main function, which should return true if two strings // are equal regardless of case, and false otherwise. You need to first // determine if the strings are of the same length. bool ciequal(string a, string b) { ... } /* PART 2: This part asks you to create a class called "csc15" (he he) that contains two arrays. One array will contain strings representing the names of the students in the class. The other array will contain chars representing the letter grade for each corresponding student in the class. */ // But first, write a function (outside of the class) that takes a string, // an array of strings, and the size of the array as arguments, and return // the index of s in A, in s occurs in A, and -1 if s does not exist in A. // This should be something very similar to what we did in class, except you // should use case insensitive string equality to see if you've found the // "right" string. int findIndex(string s, string A[], int n) { ... } //Now for the class: class csc15 { private: /* The private section should contain the following: A char 'section' that identifies the particular object (section '1' or section 'A'). An integer 'size' that indicates the number of students in the class. An array of strings called Roster, of length 33 (the maximum enrollment allowed). This array will contain the names of the students in the class. NOTE that not all of this array will be filled. The cells of the array that will actually be used will be 0 to size-1. An array of chars called Grades, also of length 33 (but only the first few will be used.). This will contain the letter grade for each corresponding student in the Roster array. Use only grades 'A' 'B' and 'C' (be optimistic!) */ public: /* Recall the basics about defining functions inside classes: Think first about what pieces of information the function will need to complete its task, then about where it will obtain the information. It should either get the information directly from the variables defined in the class, or as parameters when the function is called. Look at my main function below to understand how things should be defined. */ // The constructor. The constructor should take a single char as // an argument, and use it to initialize the section variable. // It should also set size to 0 (initially, there are no students in the // class csc15(char s) {...} // Write a function 'addStudent' that takes a string (the student's name) // and a char (the student's grade) as arguments. It should insert // the name and the grade into the Roster and Grades arrays respectively, // and increment the size variable accordingly. void addStudent(string s, char g) // Write a function 'printRoster' that prints the names of everyone in // the class. // Write a function 'lookupGrade' that takes a string (a name) as // an argument and returns a char representing that student's grade. // If the student does not exist, it should return '?'. Use the // findIndex function to first determine the index of the student in the // Roster array. // Write a function 'changeGrade' that takes a name and a grade as // arguments, and modifies the given student's grade. If the student // is not in the class, no action should be taken. This should be very // similar to the above function. // Write a function 'whogot' that takes a char grade as argument, and // prints out every student in the class who's getting that grade: void whogot(char g) // Write a function 'classGPA' that computes the grade point average // of everyone in the class. A represents 4.0, B 3.0, and C 2.0. Of // course this function should return a double. Hint: first find the // grade point sum. }; // class csc15 // My main function should work with your program: int main() { csc15 sec1('1'); csc15 secA('A'); sec1.addStudent("Larry",'B'); sec1.addStudent("Harry",'C'); sec1.addStudent("Mary",'A'); sec1.addStudent("Gary",'B'); sec1.printRoster(); sec1.changeGrade("Larry",'A'); cout << "\nclass gpa == " << sec1.classGPA() << endl; cout << "People who got A's:\n"; sec1.whogot('A'); cout <<" Harry's grade is " << sec1.lookupGrade("Harry") << endl; return 0; }