How to use class set a functiondouble money receive a number

How to use class set a function(double money(); receive a number and then output with this number*2) and use it in the main, cpp?

Solution

//Here number is a part of class definition.

//As your function definition money does not include any number variable i am assuming it to be part of class.

#include<iostream>
using namespace std;

class Program
{
private:
double number;
  
  
public:
  
Program()
{
number = 0;
}
  
Program(int number)
{
this->number = number;
}
  
double money()
{
return 2*number;
}
};

int main()
{
Program p(10);
cout << p.money() << endl;
return 0;
}

 How to use class set a function(double money(); receive a number and then output with this number*2) and use it in the main, cpp?Solution//Here number is a par

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site