Chapter 15 Example (Malik)

 

//header file

class ListType

{

public:

    const ListType&

            operator=(const ListType& 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;

 

    ListType(int size = 0);

      //Constructor

      //Postcondition: length = 0; maxSize = size;

      //               list is an arry of size maxSize

 

private:

    int maxSize;

    int length;

    int *list;

};

 

//.cpp file for implementation of the class

#include <iostream>

  

#include "ListType.h"

 

using namespace std;

 

void ListType::print() const

{

   

}

 

void ListType::insertEnd(int item)

{

   

}

 

void ListType::destroyList()

{

   

}

 

ListType::ListType(int size)

{

    maxSize = size;

    length = 0;

 

    if (maxSize == 0)

        list = NULL;

    else

        list = new int[maxSize];

}

 

const ListType& ListType::operator=

                    (const ListType& otherList)

{

   

}

 

 

 

//main testing program

#include <iostream>

 

#include "ListType.h"

 

using namespace std;

 

int main()

{

    ListType intList1(10);             //Line 9

    ListType intList2;                 //Line 10

    ListType intList3;                 //Line 11

 

    int i;                                           //Line 12

    int number;                                      //Line 13

 

    cout << "Line 14: Enter 5 integers: ";           //Line 14

 

    for (i = 0; i < 5; i++)                          //Line 15

    {

        cin >> number;                               //Line 16

        intList1.insertEnd(number);                  //Line 17

    }

 

    cout << endl;                                    //Line 18

    cout << "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;

}