This exercise will enhance your understanding of classes and operator overloading. Using the provided two files: classAssignmentOverloadh (gives the full definition of the class) and testProgAssignmentOpr.cpp (is the main entry point to the class usage). Do not modify any of the two files. Note that the class contains a list of integers. A member length integer which indicates the actual size of the list and another "maxSize" which indicates the maximum size that the list could read. "maxSize" is set by the constructor. "length" is kept track of when filling the list dynamically. Your job is to write the definition of the member functions defined classAssignmentOverload.h such that a- print" member method prints a message telling the user that the list is empty or prints the content of the list which is a list of integers space separated. b- "insetEnd" should wam the user if trying to insert more than the defined capacity of the list or inserts an integer into the end of the list. c- "destoryList" deallocates the content of the list and resets other members accordingly. d- The constructor creates a list of "maxSize" and should wam if maxSize is 0. e The overloaded =" operator should create a copy of the list of the same size and the same content. It should not be a simple pointer assignment which C++ does by default. f- The output should look like this: Line 15: Enter 5 integers: 19 18 3 29 Line 19: intList1: 19 18 3 2 9 Line 22: intList2: 19 18 3 29 Line 26: intList2: The list is empty. Line 28: After destroying intList2, intList1: 19 18 3 29 Line 30: After destroying intList2, intList3: 19 18 3 2 9
c++ (the question in the photo,plz don't tell me that you are not able to solve it, take your time and solve it all)
class cAssignmentOprOverload
{
public:
const cAssignmentOprOverload&
operator=(const cAssignmentOprOverload& otherList);
//Overload assignment operator
void print() const;
//Function to print the list
void insertEnd(int item);
//Function to insert an item at the end of the list
//Postcondition: if the list is not full, length++;
// list[length] = item
// if the list is full
// output an appropriate message
void destroyList();
//Function to destroy the list
//Postcondition: length = 0; maxSize = 0;
// list = NULL
cAssignmentOprOverload(int size = 0);
//constructor
//Postcondition: length = 0; maxSize = size;
// list is an arry of size maxSize
private:
int maxSize;
int length;
int *list;
};
#include <iostream>
#include "classAssignmentOverload.h"
using namespace std;
int main()
{
cAssignmentOprOverload intList1(10); //Line 10
cAssignmentOprOverload intList2; //Line 11
cAssignmentOprOverload intList3; //Line 12
int i; //Line 13
int number; //Line 14
cout << "Line 15: Enter 5 integers: "; //Line 15
for (i = 0; i < 5; i++) //Line 16
{
cin >> number; //Line 17
intList1.insertEnd(number); //Line 18
}
cout << endl << "Line 19: intList1: "; //Line 19
intList1.print(); //Line 20
intList3 = intList2 = intList1; //Line 21
cout << "Line 22: intList2: "; //Line 22
intList2.print(); //Line 23
intList2.destroyList(); //Line 24
cout << endl; //Line 25
cout << "Line 26: intList2: "; //Line 26
intList2.print(); //Line 27
cout << "Line 28: After destroying intList2, "
<< "intList1: "; //Line 28
intList1.print(); //Line 29
cout << "Line 30: After destroying intList2, "
<< "intList3: "; //Line 30
intList3.print(); //Line 31
cout << endl; //Line 32
return 0;
}
Step by step
Solved in 3 steps