/* Change: * - Global for loop variable instantiations * - See below for others */ int main() { // Changed number of records, only 4 const int NUM = 4; // Declare new paintings Painting pictures[NUM]; for(int i = 0; i < NUM; ++i) { // Declare new instance Painting temp; // Set the data temp.setData(); // Check if it is famous (to increase cost) if(isPaintingFamous(temp)) { // Create a Famous painting FamousPainting tempFamous(temp.getTitle(), temp.getArtist()); // Copy to the temporary class, default contructor should be fine temp = tempFamous; } // Added array index pictures[i] = temp; } // Cleaned up for loop for (int i = 0; i < NUM; i++) // Added index pictures[i].showPainting(); // Return for main function return 0; }
/* Change: * - See bellow for more changes * - Pass painting by reference, do not invoke copy contructor */ bool isPaintingFamous(Painting &painting) { // Setup Local Vars // Deafult, assume not famous bool isFamous = false; const int NUM = 4; string artists[NUM] = { "Degas", "Monet", "Picasso", "Rembrandt" }; // Changed to int, no need for char // Fixed arraym cause segmentation fault in CC not in clang/g++ for (int x = 0; x < NUM; x++) // Use passed in data, update how array displays variable if (painting.getArtist() == artists[x]) // If match, fame is true isFamous = true; return isFamous; }