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;
}
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:
"< return 0;
}
C++ Write the definition of a class ContestResult containing: An data member winner of type string , initialized...
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...
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 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...
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...
Write the definition of a class car containing: 1. A data member named model of type string. 2. A data member named year of type integer. 3. A data member named mileage of type double. 4. A member method to display the fields model, year, and mileage on the standard output. For c++
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)...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. A method 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 method named useGas that accepts a parameter of type double. The value of the amount instance variable is decreased by the value of the parameter. However, if the value of amount is decreased below 0, amount...
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, 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...
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...