#include "stdstuff.h" #include "StudentMarks.h" // constructs a new student with 0 As, 0 Bs, 0 Cs, 0 other marks StudentMarks::StudentMarks() { as = bs = cs = others = 0; } // constructs a new student with "as" As, "bs" Bs, "cs" Cs, "others" other marks StudentMarks::StudentMarks(int as, int bs, int cs, int others) { this->as = as; StudentMarks::bs = bs; this->cs = cs; StudentMarks::others = others; // this-> or StudentMarks:: only needed if argument and field names match } // the student gets an A void StudentMarks::gotA() { as++; } // the student gets a B void StudentMarks::gotB() { bs++; } // the student gets a C void StudentMarks::gotC() { cs++; } // the students gets another (lower) mark void StudentMarks::gotOther() { others++; } // prints the marks as: "As-Bs-Cs-others" void StudentMarks::printMarks() const { cout << as << "-" << bs << "-" << cs << "-" << others; } // returns the number of As this student has to date int StudentMarks::numAs() const { return as; } // returns true if the number of As and Bs is greater than the // number of Cs and other marks bool StudentMarks::mostAboveC() const { return (as+bs > cs+others); } // returns true if the student has at least as many As as the // other student, false otherwise bool StudentMarks::asManyAs(const StudentMarks &otherStudent) const { return (as >= otherStudent.as); } // returns the academic score for this student, calculated as 3 for each A, // 2 for each B, 1 for each C, and 0 for any other marks int StudentMarks::acadScore() const { return (3*as + 2*bs + cs); }