Question
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
Drivers.cpp:#include "Hero.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
//Free the alocated memory for heroes
void deleteHeroes(std::vector<Hero *> list) {
Hero *hero;
for (int i = 0; i < list.size(); i++) {
hero = list[i];
hero->deletePowers(); //delete powers attached to hero
delete hero;
}
list.empty();
}
//read in file and add each hero as vector input
void loadHeroes(std::string filename, std::vector<Hero *> &list) {
Hero *hero;
std::ifstream infile(filename);
if (infile.is_open()) {
std::string newLine;
deleteHeroes(list); //empty the list for case of reloading
while (!infile.eof()) {
std::getline(infile, newLine);
hero = new Hero(newLine);
list.push_back(hero);
}
std::cout << list.size() << " heroes loaded." << std::endl;
}
//file does not exist
else {
std::cout << "File not found." << std::endl;
}
}
//iterate through heroes list and print each of their powers
void printRoster(std::vector<Hero *> list) {
std::cout << "The following " << list.size() << " heroes are loaded..." << std::endl;
for (int i = 0; i < list.size(); i++) {
std::cout << "--------------------" << std::endl;
list[i]->printPower();
}
}...