Question

C++ Write the definition of a class  ContestResult containing: An data member winner of type  string , initialized...

C++

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.

This is what I have so far:
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();
};

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;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, Please find my implementation.

Please let me know in case of any issue.

####################   ContestResult.h ###################

#include
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
#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
#include
#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: "<    cout<<"Second Place: "<    cout<<"Third Place: "<

   return 0;
}

→ secondweek secondweek g++ ContestResultTest.cpp ContestResult.cpp → secondweek ./a . out Winner: The Legend Second Place: P

Add a comment
Know the answer?
Add Answer to:
C++ Write the definition of a class  ContestResult containing: An data member winner of type  string , initialized...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a full class definition for a class named ContestResult , and containing the following members:...

    Write a full class definition for a class named ContestResult , and containing the following members: A data member winner of type string , initialized to the empty string. A data member secondPlace of type string , initialized to the empty string. A 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...

  • c++ class and member function

    Write a full class definition for a class named ContestResult , and containing the following members: A data member winner of type string , initialized to the emptystring. A data member secondPlace of type string , initialized to the empty string. A data member thirdPlace of type string , initialized to the empty string. A memberfunction called setWinner that has one parameter, whose value it assigns to the data member winner

  • Write a full class definition for a class named Player , and containing the following members: A data member name of t...

    Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...

  • Code Lab Help (C++)

    Write the interface (.h file) of a class Player containing:A data member name of type string .A data member score of type int .A member function called setName that accepts a parameter and assigns it to name . The function returns no value.A member function called setScore that accepts a parameter and assigns it to score . The function returns no value.A member function called getName that accepts no parameters and returns the value of name .A member function called...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Java Write a class named CheckingAccount containing: An instance variable named balance of type double, initialized...

    Java Write a class named CheckingAccount containing: An instance variable named balance of type double, initialized to 0. A method named deposit that accepts a parameter of type double. The value of the balance instance variable is increased by the value of the parameter. A method named withdraw that accepts a parameter of type double. The value of the balance instance variable is decreased by the value of the parameter. A method named getBalance that accepts no parameters, returns the...

  • Write a class called Player that has four data members: a string for the player's name,...

    Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...

  • This is the code I wrote for myprogramminglab It works for 8 out of 9 inputs they use and I...

    Write a full class definition for a class named GasTank , and containing the following members:A data member named amount of type double.A constructor that no parameters. The constructor initializes the data member amount to 0.A function named addGas that accepts a parameter of type double . The value of the amount instance variable is increased by the value of the parameter.A function named useGas that accepts a parameter of type double . The value of the amount data member...

  • Python Write the definition of a class Counter containing: An instance variable named counter of type...

    Python Write the definition of a class Counter containing: An instance variable named counter of type int An instance variable named limit of type int. A constructor that takes two int arguments and assigns the first one to counter and the second one to limit A method named increment. It does not take parameters or return a value; if the instance variable counter is less than limit, increment just adds one to the instance variable counter. A method named decrement....

  • Write a class definition for a Rectangle. The data fields should be: • An integer for...

    Write a class definition for a Rectangle. The data fields should be: • An integer for the value of the width of the Rectangle • An integer for the value of the height of the Rectangle An integer for the value of the area of the Rectangle It must have: . A default constructor A constructor that has a parameters for width and height and assigns them to the member variables. • The class should have mutators for all of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT