Answer:
See explaination for Program source code.
Explanation:
The program source code below.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Show
{
private:
string title;
int viewers;
public:
Show()
{
this->title = "";
this->viewers = 0;
}
Show(string title, int viewers)
{
this->title = title;
this->viewers = viewers;
}
string getTitle(){ return this->title; }
int getViewers(){ return this->viewers; }
};
int main()
{
vector<Show> shows;
vector<string> titles;
vector<int> viewers;
ifstream inFile1("file1.txt");
ifstream inFile2("file2.txt");
string line1, line2;
if(!inFile1.is_open() || !inFile2.is_open())
{
cout << "Either of the files could not be found!\n";
exit(0);
}
getline(inFile1, line1);
if(line1.compare("Show") == 0)
{
while(getline(inFile1, line1))
{
titles.push_back(line1);
}
inFile1.close();
}
getline(inFile2, line2);
if(line2.compare("Viewer") == 0)
{
while(getline(inFile2, line2))
{
viewers.push_back(stod(line2));
}
inFile2.close();
}
for(int i = 0; i < titles.size(); i++)
{
shows.push_back(Show(titles[i], viewers[i]));
}
// display all the show details
cout << "\nALL SHOWS:\n----------\n";
for(Show show : shows)
{
cout << "Title: " << show.getTitle() << ", Number of viewers: " << show.getViewers() << endl;
}
cout << endl;
return 0;
}
See attachment for output