Respuesta :
Answer:
The following program in c++ language:
#include <iostream> //Header file
using namespace std; //using Nmaespace
class Player //define a class "Player"
{
public: // access modifier
string name = ""; // declare string type variable "name" and initialize non
int score = 0; // declare integer type variable "score" and initialize 0
void setName(string name1) //define a function "setName()" which has an argument
{
name = name1;
}
void setScore (int score1) // define a function "setScore()" which has one argument
{
score = score1;
}
string getName () // define a function "getName()" which shows output
{
return name;
}
int getScore () // define a function "getScore()"
{
return score; // returning the score
}
};
int main () // main function
{
Player p1; // create a class object "p1"
p1.setName ("aaa"); // calling method setName
p1.setScore (150); // calling method setScore
cout <<"Name =" <<p1.getName ()<<endl;
cout<<"score ="<<p1.getScore ()<<endl;
}
Output:
Name = aaa
score = 150
Explanation:
Firstly, we have defined a class named "Player" and then declare two variables first one is string type i.e, "name" which is initialize to null and second one is integer type i.e, "score" which is initialize 0 then after that we have defined two functions first one is "setName()" and second one is "setScore()" for initializing the value after that we again declare two functions for returning the value of "name" and "score" which is "getName()" and "getScore()".
finally we call these method in a main() function.