Question: C++ Linux Need help with lab assignment, instructions and code posted below IntegerList.cpp #include #include #include IntegerList.h using namespace std; IntegerList::IntegerList(int size) { list =
C++ Linux
Need help with lab assignment, instructions and code posted below

IntegerList.cpp
#include
#include
#include "IntegerList.h"
using namespace std;
IntegerList::IntegerList(int size)
{
list = new int[size];
numElements = size;
for (int ndx = 0; ndx
list[ndx] = 0;
}
IntegerList::~IntegerList()
{
delete [] list;
}
IntegerList::IntegerList(const IntegerList &obj)
{
numElements = obj.numElements;
list = new int[numElements];
for (int i = 0; i
list[i] = obj.list[i];
}
const IntegerList IntegerList::operator=(const IntegerList &right)
{
delete [] list;
numElements = right.numElements;
list = new int[numElements];
for (int i = 0; i
list[i] = right.list[i];
return *this;
}
bool IntegerList::isValid(int element) const
{
bool status;
if (element = numElements)
status = false;
else
status = true;
return status;
}
void IntegerList::setElement(int element, int value)
{
if (isValid(element))
list[element] = value;
else
{
cout
exit(EXIT_FAILURE);
}
}
int IntegerList::getElement(int element) const
{
if (isValid(element))
return list[element];
else
{
cout
exit(EXIT_FAILURE);
}
}
void IntegerList::displayList() const
{
for (int i = 0; i
cout
cout
}
IntegerList.h
// Specification file for the the IntegerList class.
#ifndef INTEGERLIST_H
#define INTEGERLIST_H
class IntegerList
{
private:
int *list; // Pointer to the array.
int numElements; // Number of elements.
bool isValid(int) const; // Validates subscripts.
public:
IntegerList(int); // Constructor
~IntegerList(); // Destructor
void setElement(int, int); // Sets an element to a value
int getElement(int) const; // Returns an element
void displayList() const; // Display list
IntegerList(const IntegerList &obj);
const IntegerList operator=(const IntegerList &right);
};
#endif
Main.cpp
// This program demonstrates the IntegerList class.
#include
#include "IntegerList.h"
using namespace std;
int main()
{
const int SIZE = 20;
IntegerList numbers(SIZE);
for (int x = 0; x
numbers.setElement(x, x);
numbers.displayList();
IntegerList numbers2 = numbers; // Copy Constructor
numbers2.displayList();
numbers.setElement(5, 24);
numbers.setElement(7, -4);
numbers.setElement(12, 12345);
numbers.displayList();
numbers2.displayList();
cout
IntegerList numbers3(4);
numbers3.displayList();
numbers3 = numbers; // Assignment
numbers3.displayList();
numbers.setElement(5, -17);
numbers3.displayList();
numbers.displayList();
cout
numbers = numbers2 = numbers3;
numbers.displayList();
numbers2.displayList();
numbers3.displayList();
cout
numbers.setElement(0, 12345);
numbers2.setElement(1, 12345);
numbers3.setElement(2, 12345);
numbers.displayList();
numbers2.displayList();
numbers3.displayList();
return 0;
}
2. In this exercise we will update the IntegerList class implementation and the main.cpp file to better understand what functions are called and when. (a) In the main.cpp file, put cout statements to track when you enter and exit the two functions PopulateList and PopulateList2. For example, place cout output.txt The output of prog will be written to the file output.txt. It works well in this case since the integer list test program does not take any input from the user. If your program does take input, using this command will not show the user any prompts. Look over the output of the program and compare it to the code of the test file. Now answer the following questions. (a) What is the big difference between the calls to PopulateList and PopulateList2? Why are these calls different, what is causing it and what is the difference in the results? (b) List all of the output that is created from the two lines. IntegerList 13; 13=11+12; You may ignore all the calls to the [] operator. For all the other lines of output, state where they come from and why. (c) Which constructor is called on the line, IntegerList 14=13; Put your answers in the end of main.cpp as comments
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
