I need help creating a TV class/object. It should have a maximum of 10 channels
ID: 3824656 • Letter: I
Question
I need help creating a TV class/object. It should have a maximum of 10 channels and display their specific information. I've written a little bit of code but am unable to actually call to the function and print out the information for a specific channel. Near the end you'll find my attempt at the TV class. Could someone help me with the TV object and calling it in my main function? I'm not sure how to fix my private and public definitions. I believe my struggle is mainly with creating the object not manipulating it.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
int stat;
int vol = 10;
int select;
while(1){ //while loop for user selection
cout << "TV is on right now!!!"<<endl;
//TV tv(1);
cout << "Channel No: "<< tv(1)<<endl;
cout << "Sound volume is @ " << vol << " level"<<endl;
cout << "Please enter your selection: "<<endl;
cout << "1. Turn TV off"<<endl;
cout << "2. Select a different channel"<<endl;
cout << "3. Go up a channel"<<endl;
cout << "4. Go down a channel"<<endl;
cout << "5. Change 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 new channel"<<endl;
cout << "9. Remove a channel"<<endl;
cout << "10. Display all channels"<<endl;
cout << "11. Details (What am I watching right now?)"<<endl;
cout << endl<< "Please enter your input here : ";
cin >> stat;
switch(stat){
case 1: //user wants to turn off TV
cout << "TV is off right now!!!"<<endl;
cout << "Goodbye"<<endl;
break;
case 2: //user wants to select a new channel
for (int i=0;i<10;i++){
cout << tv(i)<< endl;
}
cout <<endl << "What channel would you like to watch? ";
cin >> select;
switch(select)
{
case 1:
cout << "You are watching: " << tv[0]<< endl;
}
}
}
return 0;
}
class TV
{
public:
TV(int a){
switch(a){
case 1:
cout << "Channel 1 - ESPN";
break;
case 2:
cout << "Channel 2 - World Travel";
break;
case 3:
cout << "Channel 3 - Oscar Awards";
break;
case 4:
cout << "Channel 4 - Business";
break;
case 5:
cout << "Channel 5 - World News";
break;
case 6:
cout << "Channel 6 - Local Weather";
break;
case 7:
cout << "Channel 7 - Comedy Central";
break;
case 8:
cout << "Channel 8 - Game Show";
break;
case 9:
cout << "Channel 9 - CNN";
break;
case 10:
cout << "Channel 10 - Movie : Push";
break;
}
}
private:
TV();
};
Explanation / Answer
Errors are as follows and find correct implementation below:
I have made channel variable as class variable named as a:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class TV
{
public:
int a;
TV(int a){
this->a = a;
switch(a){
case 1:
cout << "Channel 1 - ESPN";
break;
case 2:
cout << "Channel 2 - World Travel";
break;
case 3:
cout << "Channel 3 - Oscar Awards";
break;
case 4:
cout << "Channel 4 - Business";
break;
case 5:
cout << "Channel 5 - World News";
break;
case 6:
cout << "Channel 6 - Local Weather";
break;
case 7:
cout << "Channel 7 - Comedy Central";
break;
case 8:
cout << "Channel 8 - Game Show";
break;
case 9:
cout << "Channel 9 - CNN";
break;
case 10:
cout << "Channel 10 - Movie : Push";
break;
}
}
private:
TV();
};
int main(int argc, char** argv) {
int stat;
int vol = 10;
int select;
TV tv(1);
while(1){ //while loop for user selection
cout << "TV is on right now!!!"<<endl;
cout << "Channel No: "<< tv.a<<endl;
cout << "Sound volume is @ " << vol << " level"<<endl;
cout << "Please enter your selection: "<<endl;
cout << "1. Turn TV off"<<endl;
cout << "2. Select a different channel"<<endl;
cout << "3. Go up a channel"<<endl;
cout << "4. Go down a channel"<<endl;
cout << "5. Change 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 new channel"<<endl;
cout << "9. Remove a channel"<<endl;
cout << "10. Display all channels"<<endl;
cout << "11. Details (What am I watching right now?)"<<endl;
cout << endl<< "Please enter your input here : ";
cin >> stat;
switch(stat){
case 1: //user wants to turn off TV
cout << "TV is off right now!!!"<<endl;
cout << "Goodbye"<<endl;
break;
case 2: //user wants to select a new channel
for (int i=0;i<10;i++){
tv.a = i;
cout<<tv.a<<endl;
}
cout <<endl << "What channel would you like to watch? ";
cin >> select;
switch(select)
{
case 1:
tv.a = 1;
cout << "You are watching: " << tv.a << endl;
break;
case 2:
tv.a = 2;
cout << "You are watching: " << tv.a << endl;
break;
case 3:
tv.a = 3;
cout << "You are watching: " << tv.a << endl;
break;
case 4:
tv.a = 4;
cout << "You are watching: " << tv.a << endl;
break;
case 5:
tv.a = 5;
cout << "You are watching: " << tv.a << endl;
break;
case 6:
tv.a = 6;
cout << "You are watching: " << tv.a << endl;
break;
case 7:
tv.a = 7;
cout << "You are watching: " << tv.a << endl;
break;
case 8:
tv.a = 8;
cout << "You are watching: " << tv.a << endl;
break;
case 9:
tv.a = 9;
cout << "You are watching: " << tv.a << endl;
break;
case 10:
tv.a = 10;
cout << "You are watching: " << tv.a << endl;
break;
}
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.