Write the definition of a class ContestResult containing: An data member winner of type string, initialized to the empty string. An data member secondPlace of type string, initialized to the empty string. An data member thirdPlace of type string, initialized to the empty string. A member function called setWinner that has one parameter, whose value it assigns to the data member winner. A member function called setSecondPlace that has one parameter, whose value it assigns to the data member secondPlace. A member function called setThirdPlace that has one parameter , whose value it assigns to the data member thirdPlace. A member function called getWinner that has no parameters and that returns the value of the data member winner. A member function called getSecondPlace that has no parameters and that returns the value of the data member secondPlace. A member function called getThirdPlace that has no parameters and that returns the value of the data member thirdPlace

1
Write the definition of a class ContestResult containing: An data member winner of type string, initialized to the empty string. An data member secondPlace of type string, initialized to the empty string. An data member thirdPlace of type string, initialized to the empty string. A member function called setWinner that has one parameter, whose value it assigns to the data member winner. A member function called setSecondPlace that has one parameter, whose value it assigns to the data member secondPlace. A member function called setThirdPlace that has one parameter , whose value it assigns to the data member thirdPlace. A member function called getWinner that has no parameters  and that returns the value of the data member winner. A member function called getSecondPlace that has no parameters and that returns the value  of the data member secondPlace. A member function called getThirdPlace that has no parameters and that returns the value of the data member thirdPlace

LANGUAGE: C++

CHALLENGE:

Write the definition of a class ContestResult containing: An data member winner of type string, initialized to the empty string. An data member secondPlace of type string, initialized to the empty string. An data member thirdPlace of type string, initialized to the empty string. A member function called setWinner that has one parameter, whose value it assigns to the data member winner. A member function called setSecondPlace that has one parameter, whose value it assigns to the data member secondPlace. A member function called setThirdPlace that has one parameter , whose value it assigns to the data member thirdPlace. A member function called getWinner that has no parameters and that returns the value of the data member winner. A member function called getSecondPlace that has no parameters and that returns the value of the data member secondPlace. A member function called getThirdPlace that has no parameters and that returns the value of the data member thirdPlace

SOLUTION:



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

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

One comment

  • GFYS says:

    That answer is WRONG!!!

    The real answer is below

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

    public:
    void setWinner(string x){
    winner = x;
    }
    void setSecondPlace(string x){
    secondPlace = x;
    }
    void setThirdPlace(string x){
    thirdPlace = x;
    }
    string getWinner() {return winner;}
    string getSecondPlace(){ return secondPlace; }
    string getThirdPlace() { return thirdPlace; }
    };

Add comment