I need help creating a C++ class that would model a TV set. It should hold a max
ID: 3824579 • Letter: I
Question
I need help creating a C++ class that would model a TV set. It should hold a maximum of 10 channels. I want to be able to add and remove channels, I'm not sure if that's necessary in the actual class or could just be done in the main program. Here's what I have so far:
#ifndef TV_H
#define TV_H
#include <string>
using namespace std;
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();
};
#endif /* TV_H */
Trying to call this using the line
cout <<"Channel No: " << TV::TV(0)<<endl;
In my main program of course fails. I'm sure it has something to do with how I defined this class... could someone help me to simplify this?
Could I just include this in my main program code and just initialize it with the class TV(){} without having to "#include <TV.h>"
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 maximumExplanation / Answer
you are using the wrong cout statements
you just need to create the object of the TV class with the parameters and the paricular cout statement will be printed
eg TV tv(0);
please find the code
#include <iostream>
#include "tv.cpp"
using namespace std;
int main()
{
TV tv(1);
//cout <<"Channel No: "<< TV::TV(0)<<endl;
return 0;
}
tv.cpp file code
#ifndef TV_H
#define TV_H
#include <string>
#include <iostream>
using namespace std;
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();
};
#endif /* TV_H */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.