Answer to Question #207820 in C++ for champu

Question #207820

Suppose that you have a mobile phone. Initially the phone has a net value of 35000/-, it has

been used for 0 Hrs and its battery can last for 12 Hrs. Now after every month the phone is

used for 200 hrs on average and its battery backup time decreases by 4%. After every 4%

decrease in battery backup time, the price decreases by 700/-. You need to write a program by

using the concept of operator overloading to calculate the minimum number of months in

which the battery backup time will become less than or equal to 5 hrs and display the net

value and total hours of use and battery backup time of the mobile phone after those months.


1
Expert's answer
2021-06-17T04:40:53-0400
#include <iostream>
class Mobile
{
public:
	void set_limit(double n)
	{
		battery_limit = n;
	}
	void get_info() 
	{
		double p = price;
		int m = use_month;
		double b = battery;
		double t = use_time;
		while (b > battery_limit) 
		{
			m += 1;
			t += 200;
			b = b - b * percent / 100;
			p = p - price_dec;
		}
		std::cout << "Number of months: " << m << std::endl;
		std::cout << "Operating hours: " << t << std::endl;
		std::cout << "Phone cost: " << p << std::endl;
		std::cout << "Battery life: " << b << std::endl;
	}
	friend void operator < (Mobile& mobile, double n);


private:
	double price{ 35000 };
	double use_time{ 0 };
	int use_month = 0;
	double battery{ 12 };
	double battery_limit{ 0};
	double percent{ 4 };
	double price_dec{ 700 };
	double time_inc{ 200 };
};
void  operator < ( Mobile& mobile, double n)
{
	mobile.set_limit(n);
	mobile.get_info();
}


int main()
{
	Mobile test;
	// Overloaded operator call
	test < 5;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS