Assignment 8 Solutions
Solution school.cc code:
/******************************************************************* * Name: Brenda Student * Date: 4/21/14 * Course: CSCI 132 Section 01 * Assignment: Assignment 8 * Instructor: Royden * Program: schools.cc * Purpose: Implements the functions in the Schools class ***************************************************************************/ #include "school.h" School:: School () { /*Pre: None *Post: All ratings set to zero */ women = 0; rateAI = 0; rateSys = 0; rateTheory = 0; effectiveness = 0; ratePubs = 0; overallRating = 0; } School:: School (string myName, string myState, int theWomen, int myRateAI, int myRateSys, int myRateTheory, int myEffectiveness, int myRatePubs) { /*Pre: myName and myState are strings. *Post: All parameters are assigned to the appropriate member variables of the School object.*/ name = myName; state = myState; women = theWomen; rateAI = myRateAI; rateSys = myRateSys; rateTheory = myRateTheory; effectiveness = myEffectiveness; ratePubs = myRatePubs; overallRating = 0; } void School::printSchoolInfo () { /*Pre: None *Post: Print out information of the given School object */ cout << endl; cout << "Name: " << name << endl; cout << "State: " << state << endl; cout << "Rating of number of women PhD's: " << women << endl; cout << "Rating of AI program: " << rateAI << endl; cout << "Rating of Systems program: " << rateSys << endl; cout << "Rating of Theory program: " << rateTheory << endl; cout << "Effectiveness rating: " << effectiveness << endl; cout << "Rating of faculty publications: " << ratePubs << endl; cout << "Overall rating: " << overallRating << endl; cout << endl; } void School :: computeRating (int weightWomen, int weightAI, int weightSys, int weightTheory, int weightEffect, int weightPubs) { /*Pre: Parameters are integers between 1 and 5. *Post: Compute the overallRating for a School object given the parameter weights. */ overallRating = (weightWomen * women) + (weightAI * rateAI) + (weightSys * rateSys); overallRating += (weightTheory * rateTheory) + (weightEffect * effectiveness); overallRating += weightPubs * ratePubs; } bool operator ==(const School &x, const School &y) /*Pre: x and y are School objects *Post: Returns true if the overallRating of x is equal to the overallRating of y */ { return x.overallRating == y.overallRating; } bool operator !=(const School &x, const School &y) /*Pre: x and y are School objects *Post: Returns true if the overallRating of x is not equal to the overallRating of y */ { return x.overallRating != y.overallRating; } bool operator >=(const School &x, const School &y) /*Pre: x and y are School objects *Post: Returns true if the overallRating of x is greater than or equal to the overallRating of y */ { return x.overallRating >= y.overallRating; } bool operator <=(const School &x, const School &y) /*Pre: x and y are School objects *Post: Returns true if the overallRating of x is less than or equal to the overallRating of y */ { return x.overallRating <= y.overallRating; } bool operator >(const School &x, const School &y) /*Pre: x and y are School objects *Post: Returns true if the overallRating of x is greater than the overallRating of y */ { return x.overallRating > y.overallRating; } bool operator <(const School &x, const School &y) /*Pre: x and y are School objects *Post: Returns true if the overallRating of x is less than the overallRating of y */ { return x.overallRating < y.overallRating; }
Home | | Syllabus | | Assignments | | Lecture Notes