I need help creating a function, in C++, for a TV object class to delete a pre-e
ID: 3828117 • Letter: I
Question
I need help creating a function, in C++, for a TV object class to delete a pre-existing channel. These channels are basically an array of strings. How to implement the removeChannel function?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class TV //TV class
{
private:
bool switchedOn;
int currentChannel;
string channelTitle[10];
int volume;
public:
TV()
{
switchedOn = false;
currentChannel = -1;
channelTitle[0] = "ESPN";
channelTitle[1] = "World Travel";
channelTitle[2] = "Oscar Awards";
channelTitle[3] = "Business";
channelTitle[4] = "World News";
channelTitle[5] = "Local Weather";
channelTitle[6] = "Disney Channel";
channelTitle[7] = "Game Show";
channelTitle[8] = "CNN";
channelTitle[9] = "Movie - Push";
volume = 0;
}
};
void removeChannel(int number)
{
//Not sure how to go about implementing this
}
Explanation / Answer
void removeChannel(int number)
{
string newchannelTitle[sizeof(channelTitle)/sizeof(string)-1];
int j=0;
for(int i=0;i<(sizeof(channelTitle)/sizeof(string));i++){
if(number!=(i+1)){
newchannelTitle[j++]=channelTitle[i];
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.