13.5 Focus on Software Engineering: Separating Class Specification from Implementation: 10853

Question

Write the implementation (.cpp file) of the  ContestResult class from the previous exercise. Again, the class contains:
An instance variable  winner of type  string , initialized to the empty string.
An instance variable  secondPlace of type  string , initialized to the empty string.
An instance variable  thirdPlace of type  String , initialized to the empty string.
A function called  setWinner that has one parameter, whose value it assigns to the instance variable  winner .
A function called  setSecondPlace that has one parameter, whose value it assigns to the instance variable  secondPlace .
A function called  setThirdPlace that has one parameter, whose value it assigns to the instance variable  thirdPlace .
A function called  getWinner that has no parameters and that returns the value of the instance variable  winner .
A function called  getSecondPlace that has no parameters and that returns the value of the instance variable  secondPlace .
A function called  getThirdPlace that has no parameters and that returns the value of the instance variable  thirdPlace .

Solution
void ContestResult::setWinner (string theWinner)
{
    winner = theWinner;
}

void ContestResult::setSecondPlace (string theSecondPlace)
{
    secondPlace = theSecondPlace;
}

void ContestResult::setThirdPlace (string theThirdPlace)
{
    thirdPlace = theThirdPlace;
}

string ContestResult::getWinner ()
{
    return winner;
}

string ContestResult::getSecondPlace()
{
    return secondPlace;
}

string ContestResult::getThirdPlace()
{
    return thirdPlace;
}

1 comment:

  1. 10852

    class ContestResult{
    private:
    string winner;
    string secondPlace;
    string thirdPlace;

    public:
    void setWinner(string w);
    void setSecondPlace(string s);
    void setThirdPlace(string t);
    string getWinner();
    string getSecondPlace();
    string getThirdPlace();
    };

    ReplyDelete