Define a class bill that calculate the telephone bill of a consumer consumed in a month.
For first 100 calls,rate is 0.60 rupees per call.
For next 100 calls,rate is 0.80 rupees per call.
For next 100 calls,rate is 1.20 rupees per call.
Above 300 calls,rate is 1.50 rupees per call.
Fixed monthly rental applicable to all consumers:125 rupees
Answers
Answer:
// In C++
class Bill {
public:
float telephone_bill( int no_of_calls )
{ if (no_of_calls <= 0)
{ return 125; }
else if ( no_of_calls <= 100 )
{ float sum = 0;
no_of_calls = (float)no_of_calls;
sum = 125 + no_of_calls*0.60;
return sum; }
else if (no_of_calls <= 200)
{
float sum = 0;
no_of_calls = no_of_calls - 100;
no_of_calls = (float)no_of_calls;
sum = 125 + 60 + no_of_calls*0.80;
return sum;
}
else if (no_of_calls <= 300)
{
float sum = 0;
no_of_calls = no_of_calls - 200;
no_of_calls = (float)no_of_calls;
sum = 125 + 60 + 80 + no_of_calls*1.20;
return sum;
}
else if (no_of_calls > 300)
{
float sum = 0;
no_of_calls = no_of_calls - 300;
no_of_calls = (float)no_of_calls;
sum = 125 + 60 + 80 + 120 + no_of_calls*1.50;
return sum;
}
else { cout<<"Invalid"; }
} // function end
}; // class end
Explanation:
I made this class like this so that you can understand the logic, and can copy if you want to, in any other programming language.