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

C++ Virtual Function and Abstract Class Design a class called IntArray that has

ID: 666031 • Letter: C

Question

C++ Virtual Function and Abstract Class

Design a class called IntArray that has the following protected member variables Variable Names size values Description an integer, size of the array an integer pointer (which also serves as the array name) his class has the following public member functions Function Names constructor Description takes an integer parameter as the array size, dynamically creates an integer arra takes inputs from a user and assign them to the values array takes two integers i and j, returns true if i is less than j, otherwise returns false an abstract (pure virtual) function a virtual function, shows date values in the array clear up the memory space dynamically allocated in the constructor setValues compare sort showValues destructor Design a derived class called SortlntArray based on the IntArray (with public as the base access specification). This class has no its own member variables but the following public member functions: Member FunctionsDescription constructor sort takes an integer parameter and call base class constructor sorts the values array in ascending order, this function uses the compare function when sorting this function calls the sort function first, then calls the showValues function of the base class showValues Design a simple program to uses the designed classes. This program should do the following Create a SortlntArray object array1 using the constructor to specify the array size; Call setValues function of array1 Call showValues function to show the array in object array1 * . *

Explanation / Answer

working c++ code

#include <iostream>

using namespace std;
class Arrays
{
public:
   Arrays (int num); // constructor
   ~Arrays (); // destructor
   void displayMessage(); // displays welcome message
   void setValues(); // retrieves values from user and sets them to the array
   void getValues(); // allows a user to specify element to view
   void printTest(); // prints out all values in all elements
private:
   int* arrayList; // pointer to array of a user defined size
   int sizeOfArray; // size of the array

};

int main()
{
   int size = 0;

   cout << "How big would you like your array to be: ";
   cin >> size;

   Arrays arrayClass (size);
   arrayClass.displayMessage();
   arrayClass.setValues();
   arrayClass.getValues();
   arrayClass.printTest();

   return 0;
}
void Arrays :: getValues()
{
   int input_two = 0;

   while (!cin.fail() || input_two >= sizeOfArray)
   {
      cout << "Which value would you like to view? ";
      cin >> input_two;

      input_two = input_two - 1;
      cout << arrayList[input_two] << endl;
   }
}
void Arrays :: setValues()
{
   for(int i = 0; i < sizeOfArray; i++)
   {
      cout << "Enter in value number " << i + 1 << ":";
      cin >> this->arrayList[i];
   }
}
void Arrays :: printTest()
{
   for(int i = 0; i < sizeOfArray; i++)
   {
      cout << arrayList[i] << endl;
}
}
void Arrays :: displayMessage()
{
   cout << "Welcome to the Array Program!" << endl;
}
Arrays :: Arrays (int num)
{
   sizeOfArray = num;
   arrayList = new int [num];
}
Arrays :: ~Arrays ()
{
   delete [] arrayList;
}

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