Respuesta :
Answer:
Here is the complete member function:
void CablePlan::SetNumDays(int numDays) { //member function of class CablePlan which take numDays as parameter
this->numDays = numDays; // refers to the fields numDays of CablePlan class using this keyword
return; }
Explanation:
The complete program is:
#include <iostream> //to use input output functions
using namespace std; //to identify objects like cin cout
class CablePlan{ //class
public: //public methods of class
void SetNumDays(int numDays); //method of class CablePlan that takes numDays as parameter to set the days
int GetNumDays() const; // method of class CablePlan to get no of days
private: //private data member of class CablePlan
int numDays; //private data member of class CablePlan that holds no of days
};
// FIXME: Define SetNumDays() member function, using "this" implicit parameter.
void CablePlan::SetNumDays(int numDays) { /
this->numDays = numDays; // used to refer to numDays variable of CablePlan class using this keyword
return;}
int CablePlan::GetNumDays() const { //define member function GetNumDays
return numDays;}
int main() { //start of main function
CablePlan house1Plan; //creates object of CablePlan class
house1Plan.SetNumDays(30); //uses object to call member function of CablePlan passing value 30 to it in order to set no of days
cout << house1Plan.GetNumDays() << endl; //uses object to call member function of CablePlan to get the no of days (numDays)
return 0;}
Here this keyword is used to refer to the field i.e. numDays of CablePlan class. This distinguishes local member numDays from parameter numDays using this with -> symbol.
'this' pointer retrieves the object's numDays which is hidden by the local variable numDays . The output of this program is:
30

Answer:
this.numDays = numDays;
Explanation:
You just need one line of code. "this." to access the class member, and the "." is the member access operator.