In: Computer Science
Class as a ChapteredVideo. The constructor should take the following parameters:
ID, length, num_chapters, chap_lengths, location, [extension]
The new parameter should be stored as their own instance variables. The ChapteredVideo object should behave as the Video. However, the method get_ID should now return a list which contains whatever the Video previously would return as its ID as the first element, followed by a list of chapter names. Each chapter name will be formed by the ID of the main video followed by ‘#’ and then the chapter number (starting at 1). For instance, a valid list could be ["123", "123#1", "123#2", "123#3"]. The ChapteredVideo class should also have a new accessor method, get_num_chapters.
Implement ChapteredVideo class as specified above.
#include<bits/stdc++.h>
using namespace std;
class ChapteredVideo
{
int ID, length, num_chapters, chap_lengths;
string location;
string extension;
vector <string> chapName;
public:
ChapteredVideo(int ID, int length, int num_chapters, int chap_lengths, string location, string extension)
{
this->ID = ID;
this->length = length;
this->num_chapters = num_chapters;
this->chap_lengths = chap_lengths;
this->location = location;
this->extension = extension;
}
vector<string> get_ID()
{
vector<string> R;
R.push_back(to_string(this->ID));
for (int i = 0; i < this->chapName.size();i++)
{
R.push_back(this->chapName[i]);
}
return R;
}
int get_num_chapters(){
return this->num_chapters;
}
void addChapName(int i){
string c = to_string(this->ID) + "#" + to_string(i);
this->chapName.push_back(c);
}
};
int main()
{
ChapteredVideo c1(123, 23, 12, 40, "C", "mp4");
for (int i = 1; i < 10;i++)
c1.addChapName(i);
vector<string> I = c1.get_ID();
for (auto itr : I)
{
cout << itr <<" ";
}
return 0;
}