Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add the function min as an abstract function to the class arrayListType to retur

ID: 3669440 • Letter: A

Question

Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.

I have to use this code below in the main .cpp file.

//int Main

//Data: 18 42 78 22 42 5 42 57

#include <iostream>
#include "unorderedArrayListType.h"

using namespace std;

int main()
{
    unorderedArrayListType intList(25);

    int number;

    cout << "Enter 8 integers: ";

    for (int count = 0; count < 8; count++)
    {
        cin >> number;
        intList.insertEnd(number);
    }

    cout << endl;
    cout << "intList: ";
    intList.print();
    cout << endl;

    cout << "The smallest number in intList: "
         << intList.min() << endl;
   system("pause");
   return 0;
}

Explanation / Answer

class arrayListType
{
public:
   int min();
};

class unorderedArrayListType : arrayListType
{
public:
   int a[10],i;
   unorderedArrayListType()
   {
       i=0;
   }
   void insertEnd(int n)
   {
       a[i]=n;
       i++;
   }

   int min()
   {
       int m=a[0];
       int j;

       for(j=0;j<i;j++)
       {
           if(a[j]>m)
           {
               m=a[j];
           }
       }
       return m;
   }
  
   void print()
   {
       for(int j=0;j<i;j++)
           cout<<a[j]<<endl;
   }

};
      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote