Answer to Question #156844 in C++ for Dumby

Question #156844

UML AND C++


Given the class diagram below, create a simple Television remote controlled

application. Classes and functions shown in the diagram must be complete and

properly declared.


Television.            Remote C

+Channel:integer.  +RChannel:integer

+Volume:integer.   +RVolume: integer

+Status:integer.    +RStatus: integer

+DisplayVolume(). +DecreaseVolume()

+DisplayChannel(). +IncreaseVolume()

              |     +SetChannel()

              |    +TurnOn()

               |    +TurnOff()

----- | ---------------------------------

| |

CableTV. RegularTV

+MaxChannel:integer + MaxChannel:Integer

+SetiStatus() +SetiStatus()


Use the following program description:

 The program has 2 TV objects. One as Cable TV and the other is Regular TV

 Ask the user to enter the type of Television. This will automatically turn on the

Television.

 The change of channel and volume shall only be done when the tv is on (Status

=1).

 Changes in channels and volume must be handled by an object of RemoteC.

 The initial channel for Cable TV is 10 while Regular TV is 2. Initial volume regardless

of the type of Television is 10. Display these values once the TV is turned on.

 Ask the user for an action (change volume or change channel).

 The maximum channel for Cable TV is 50 while Regular TV is 10. Maximum

Volume is 100. Action is invalid if the changes exceeds to its maximum value.

 Continue to ask user for an action until the user enters ‘0’ (zero) to turn off the TV


1
Expert's answer
2021-01-24T11:10:17-0500
#include <iostream>
using namespace std;


class Television
{
private:
	int Channel=2;
	int Volume=10;
	int RChannel=10;
	int RVolume=10;
	int Status = 0;
	int RStatus = 0;
public:
	void DisplayVolume(int t)
	{
		if ((t == 1)&&(Status==1))
		{
			cout << Volume<<endl;
		}
		else if ((t == 2) && (RStatus == 1))
		{
			cout << RVolume << endl;
		}
		if ((Status == 0) && (RStatus == 0))
		{
			cout << "The TV is off" << endl;
		}
		
	}
	void DisplayChannel(int t)
	{
		if ((t == 1) && (Status == 1))
		{
			cout << Channel << endl;
		}
		else if ((t == 2) && (RStatus == 1))
		{
			cout << RChannel << endl;
		}
		if ((Status == 0) && (RStatus == 0))
		{
			cout << "The TV is off" << endl;
		}
	}
	void DecreaseVolume(int t)
	{
		if ((Status == 0) && (RStatus == 0))
		{
			cout << "The TV is off" << endl;
		}
		if ((t == 1) && (Status == 1))
		{
			if (Volume > 1)
			{
				Volume--;
			}
			else
			{
				cout << "This is the minimum volume" << endl;
			}
		}
		else if ((t == 2) && (RStatus == 1))
		{
			if (RVolume > 1)
			{
				RVolume--;
			}
			else
			{
				cout << "This is the minimum volume" << endl;
			}
		}
	}
	void IncreaseVolume(int t)
	{
		if ((Status == 0) && (RStatus == 0))
		{
			cout << "The TV is off" << endl;
		}
		if ((t == 1) && (Status == 1))
		{
			if (Volume < 100)
			{
				Volume++;
			}
			else
			{
				cout << "This is the maximum volume" << endl;
			}
		}
		else if ((t == 2) && (RStatus == 1))
		{
			if (RVolume < 100)
			{
				RVolume++;
			}
			else
			{
				cout << "This is the maximum volume" << endl;
			}
		}
	}
	void SetChannel(int t,int k)
	{
		if ((Status == 0) && (RStatus == 0))
		{
			cout << "The TV is off" << endl;
		}
		if ((Status != 0) || (RStatus != 0))
		{
			if ((t == 1) && (Status == 1))
			{
					Channel = k;
			}
			else if ((t == 2) && (RStatus == 1))
			{
					RChannel = k;
			}
		}
	}
	void TurnOn(int t) {
		if (t == 1)
		{
			Status=1;
		}
		else if (t == 2)
		{
			RStatus = 1;
		}
	}
	void TurnOff(int t) {
		if (t == 1)
		{
			Status = 0;
		}
		else if (t == 2)
		{
			RStatus = 0;
		}
	}
};


class CableTv
{
private:
	int const CMaxChannel=50;
	int const MaxChannel=10;
public:
	int SetiStatus(int t,int k)
	{
		int p;
			if ((t == 1)&&(k<=MaxChannel)&&(k>=1))
			{
				p = 1;
				return p;
			}
			else if ((t == 2) && (k <= CMaxChannel) && (k >= 1))
			{
				p = 1;
				return p;
			}
	}
};


int main()
{
	Television RemoteC;
	CableTv RegularTV;
	int p=1, t, k;
	cout << "Enter the TV type (1 - regular, 2-cable): ";
	cin >> t;
	RemoteC.TurnOn(t);
	while (p != 0)
	{
		cout << "The number of this channel: ";
		RemoteC.DisplayChannel(t);
		cout << "The value of the volume: ";
		RemoteC.DisplayVolume(t);
		cout << "To change the channel number, press 1, to increase the volume 2, to decrease 3, to turn off the TV 0: ";
		cin >> p;
		if (p == 1)
		{
			cout << "Enter the channel number: ";
			cin >> k;
			if (RegularTV.SetiStatus(t, k))
			{
				RemoteC.SetChannel(t, k);
			}
		}
		if (p == 2)
		{
			RemoteC.IncreaseVolume(t);
		}
		if (p == 3)
		{
			RemoteC.DecreaseVolume(t);
		}
		system("cls");
	}
    RemoteC.TurnOff(t);
	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