This is the second of a two part sequence on an introduction to Object Oriented Programming. During the fourth week of class we cover Chapter 4 of Friedman & Koffman, in which they discuss relational and logical operators, the if statement, and the switch statement. in what follows we have introduced two short and simple but complete object oriented programs, both of which using the if statement - quiz.cpp, and grade.cpp.
Program quiz.cpp is really a simple introduction and preview of program grade.cpp. The combination of the in-class and programming portions of the quiz result in a total of 25 points, and we wish to determine if we have done "good" (>= 20), "fair" (< 20 but >= 15) or "poor" (< 15). In the structure diagram below we show the flow chart which will determine this evaluation together with the implementation of this flow chart in terms of an if statement in the void method display(). Notice that we have two if statements, one nested within the other, however they have been presented as though there is a separate else-if clause in the C++ language. We will expand this approach in the second example following,

Notice in the main function how we have experimented
with the constructor, whose purpose it is to construct an object
of the class, being the student's specific quiz grade.

We now present a more complex example grade.cpp in which we evaluate and display the student's final letter grade for the quarter, based on all 8 quizzes, the 6 program exercises, 8 selected labs and the endterm test. The class Grade follows:

Notice that in this case a default constructor is used to create a student grade object, and we use a separate method assign() in order to assign values to the various grades and a separate method display() to display the values of the private variables. This is mainly in order to present different styles used in object oriented programming.
The two final methods of the class are presented as method prototypes rather than having the complete method definition in the class. The method definitions then follow the main function in a similar manner to function definitions that we used previously. We will use both approaches as appropriate in all our programs. We now present the main function followed by the two methods finalmark() and finalgrade().

Thus we first use the constructor to create a default student object, enter all five sets of grades from the keyboard, assign them to the private variables and display their values. Subsequently we invoke method finalmark() to determine the total number of grade points (out of a possible 1000 points) and finally method finalgrade() to display the student final letter grade. The method finalmark() including the relevant flow chart follows:

Since this method definition is placed outside of the class Grade and follows the main program we use the new "double colon" operator :: to indicate that the method is in fact a member function of the class Grade, and has full access to all the private variables of the class, as shown.
The final method definition finalgrade() is shown below. Notice that it is an extension of the approach that we used above in the program quiz.cpp above.

The complete source code of above two programs,
including all the relevant comments, are available in the Week
4 directory /home/condor/et181/week4 under the filenames quiz.cpp and grade.cpp.