Question

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
1 0
Add a comment Improve this question Transcribed image text
Answer #1
#include
using namespace std;
class ContestResult
{
string winner=" ";

string secondPlace=" ";
string thirdPlace= " ";
void setWinner(string x)
{
winner=x;
}
void setSecondPlace(string y)
{
secondPlace=y;
}
void setThirdPlace(string z)
{
thirdPlace=z;
}
string getWinner()
{
return winner;
}
string getSecondPlace()
{
return secondPlace;
}
string getThirdPlace()
{
return thirdPlace;
}
};
Add a comment
Answer #2
class ContestResult{
public:
string winner;
string secondPlace;
string thirdPlace;

void ContestResult(){
winner = " ";
secondPlace = " ";
thirdPlace = " ";
}
void ContestResult(string win, string sec, string thr){
winner = win;
secondPlace = sec;
thirdPlace = thr;
}
void setScore (string win){
winner = win;
}
};
Add a comment
Know the answer?
Add Answer to:
c++ class and member function
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++ 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...

  • 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...

  • c ++ Create a class Book with the data members listed below.     title, which is...

    c ++ Create a class Book with the data members listed below.     title, which is a string (initialize to empty string)     sales, which is a floating point value (as a double, initialize to 0.0) Include the following member functions:     Include a default constructor,     a constructor with parameters for each data member (in the order given above),     getters and setter methods for each data member named in camel-case. For example, if a class had a data...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • 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...

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