Project description: Write a C++ program to represent a TV set. You must impleme
ID: 3819243 • Letter: P
Question
Project description:
Write a C++ program to represent a TV set.
You must implement the functionality below using classes.
No credits will be given if you do not use appropriate Classes, Objects and Methods.
Your program must contain the following at the minimum:
TV is on or off
TV’s current channel if it is on
Current channel programming title or name
TV’s sound volume if it is on
Your TV can hold 10 Channels maximum Your classes should provide the necessary methods to perform the following operations at the minimum:
Turn the TV on or off
Configure channels, add more channels or remove unwanted channels
Change channel by number, i.e. go to channel 7 directly
Change channel by 1, up and down
Change sound volume by specific number, i.e. 26
Change sound volume by 1, up and down
Print out the current TV’s status: for example; “You are currently watching Channel 7 - ABC news, sound volume @18”
Please implement a complete C++ program to provide the functionality described in the following screens.
Project description: Write a C++ program to represent a TV set You must implement the functionality below using classes. No credits will be given if you do not use appropriate Classes, Objects and Methods Your program must contain the following at the minimum TV is on or off TV's current channel if it is on Current channel programming title or name TV's sound volume if it is on Your TV can hold 10 channels maximum Your classes should provide the necessary methods to perform the following operations at the minimum Turn the TV on or off Configure channels, add more channels or remove unwanted channels Change channel by number e. go to channel 7 directly Change channel by 1, up and down Change sound volume by specific number i.e. 26 Change sound volume by 1, up and down Print out the current TV's status: for example; Please implement a complete C++ program to provide the functionality described in the following Screens.Explanation / Answer
#include<iostream>
using namespace std;
class TvSet{
private:
int state;
int current_channel;
char *curr_title;
int volume;
char *channel_list[11];
int no_of_channels;
public:
TvSet(){
state=1;
current_channel=9;
no_of_channels=10;
volume=24;
curr_title="CNN";
channel_list[1]="ESPN";
channel_list[2]="World Travel";
channel_list[3]= "Oscar Award";
channel_list[4]="Business";
channel_list[5]="World News";
channel_list[6]= "Local Weather";
channel_list[7]= "World Travel";
channel_list[8]="Game Show";
channel_list[9]="CNN";
channel_list[10]="Movie the initiation game";
}
// to turn the tv on
void tv_on(){
state=1;
}
// to turn the tv off
void tv_off(){
state=0;
cout<<"TV is off right now!!"<<endl;
cout<<"GoodBye ";
}
//display channel list
void display_channel(){
int i;
for(i=1;i<=no_of_channels;i++)
cout<<i<<"-"<<channel_list[i]<<endl;
}
//change channel
void changeChannel(int channel){
current_channel=channel;
curr_title=channel_list[channel];
}
//change channel up
void changeChannelUp(){
current_channel++;
curr_title=channel_list[current_channel];
}
//change channel down
void changeChannelDown(){
current_channel--;
curr_title=channel_list[current_channel];
}
//change sound volume by specific number
void setSoundVolume(int vol){
volume=vol;
}
//sound volume up
void changeVolumeUp(){
volume++;
}
//sound volume up
void changeVolumeDown(){
volume--;
}
void add_channel(){
if(no_of_channels==10){
cout<<"Currently no channel is available, please remove a channel first";
return;
}
int i;
char channel[40];
for(i=1;i<=10;i++){
if(channel_list[i]=="CHANNEL REMOVED"){
cout<<"Enter the channel you want to add ";
cin>>channel;
channel_list[i]=channel;
break;
}
}
}
void remove_channel(){
if(no_of_channels==0){
cout<<"All channels already removed"<<endl;
return;
}
int channel;
cout<<"What is the channel you would like to remove"<<endl;
cin>>channel;
no_of_channels--;
channel_list[channel]="CHANNEL REMOVED";
cout<<"Channel Succesfully removed"<<endl;
}
//to display current status
void display(){
cout<<"You are currently watching Channel "<<current_channel<<"-"<<curr_title<<",sound voulme @"<<volume<<endl;
}
};
void display_menu(){
cout<<"1 - turn TV Off"<<endl;
cout<<"2- go to a different channel"<<endl;
cout<<"3- go up a channel"<<endl;
cout<<"4 - go down a channel"<<endl;
cout<<"5- go to a different sound volume level"<<endl;
cout<<"6- go up a sound volume level"<<endl;
cout<<"7- go down a sound volume level"<<endl;
cout<<"8- add a channel"<<endl;
cout<<"9- remove a channel"<<endl;
cout<<"10- display all channels"<<endl;
cout<<"11- what am I watching right now"<<endl;
}
int main(){
TvSet t1;
int option;
t1.display();
cout<<" ";
display_menu();
cout<<"Please enter your input here ";
cin>>option;
while(1){
switch(option){
case 1: t1.tv_off();
return 0;
break;
case 2: int channel;
t1.display_channel();
cout<<"What channel would you like to watch ";
cin>>channel;
t1.changeChannel(channel);
t1.display();
break;
case 3: t1.changeChannelUp();
t1.display();
break;
case 4: t1.changeChannelDown();
t1.display();
break;
case 5:int vol;
t1.display_channel();
cout<<"What volume would you like to set ";
cin>>vol;
t1.setSoundVolume(vol);
t1.display();
break;
case 6: t1.changeVolumeUp();
t1.display();
break;
case 7: t1.changeVolumeDown();
t1.display();
break;
case 8 : t1.add_channel();
t1.display_channel();
break;
case 9 : t1.remove_channel();
t1.display_channel();
break;
case 10 : t1.display_channel();
break;
case 11 : t1.display();
break;
default : cout<<"Wrong Choice"<<endl;
}
display_menu();
cout<<"Please enter your input here ";
cin>>option;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.