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;
}
Answers for C++ Course using "Starting out with C++ : from control structures through objects" by Tony Gaddis. 7/8th ed. I used the Pearson myprogramminglab to complete the homework. Here are my solutions/answers for the exercises/labs so please use the test bank as a GUIDE if you're stuck. Let me know if you find a better solution to a problem or any of the programming challenges. Thanks in advance for your support! Send in missing programming challenges to cplusplus.answers@gmail.com
Subscribe to:
Post Comments (Atom)
10852
ReplyDeleteclass 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();
};