Answer:
#include <string>
using namespace std;
class ContestResult{
private:
string winner;
string secondPlace;
string thirdPlace;
public:
// default constructor to initialize with empty string
ContestResult();
void setWinner(string);
void setSecondPlace(string);
void setThirdPlace(string);
string getWinner();
string getSecondPlace();
string getThirdPlace();
};
#################### ContestResult.cpp ###################
#include <string>
#include "ContestResult.h"
using namespace std;
ContestResult::ContestResult(){
winner = "";
secondPlace = "";
thirdPlace = "";
}
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;
}
#################### ContestResultTest.cpp ###################
#include <string>
#include <iostream>
#include "ContestResult.h"
using namespace std;
int main(){
// creating object of ContestResult
ContestResult c;
// settinf all members
c.setWinner("The Legend");
c.setSecondPlace("Pravesh");
c.setThirdPlace("Alex");
cout<<"Winner: "<<c.getWinner()<<endl;
cout<<"Second Place: "<<c.getSecondPlace()<<endl;
cout<<"Third Place: "<<c.getThirdPlace()<<endl;
return 0;
}
Explanation:
See answer