• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
488 views

Problem:

I have an assignment in which i need to write program which shows missing method and need to use "this"  key. Can anyone show how this code or program would look like in Java.

The question goes as following:

define the missing method. use "this" to distinguish the local member from the parameter name.

Thanks

by (5.3k points)  

1 Answer

0 votes

Solution:

#include <iostream>

using namespace std;

/*

Define the missing member function. Use "this" to distinguish the local member from the parameter name.

*/

class DaysPlanning{

   public:

      void  SetNDays(int noDays);

      int   GetNDays() const;

   private:

      int   noDays;

};

// FIXME: Define SetNDays() member function, using "this" implicit parameter.

void DaysPlanning::SetNDays(int noDays) {

this-> noDays = noDays;

   return;

}

int DaysPlanning::GetNDays() const {

   return noDays;

}

int main() {

   DaysPlanning hPlan;

   hPlan.SetNDays(30);

   cout << hPlan.GetNDays() << endl;

   return 0;

}

Conclusion:

So we will get the output here as 30 if we run this program

by (1.4k points)  
edited by
...