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

PLEASE MAKE A CLASS FILE USING THE FOLLOWING UML (Unified Modeling Language) IN

ID: 3663212 • Letter: P

Question

PLEASE MAKE A CLASS FILE USING THE FOLLOWING UML (Unified Modeling Language) IN A .H FORMAT AND NOT .CPP using C++

A .cpp code follows at the bottom to test the class

Test file.cpp:

Array List a A pointer that holds the memory address for the dynamically allocated array. nt capacity stores the number of elements of the array. capacity int length stores the number of values currently in the list. Unless the array is full, length: int the length will be less than capacity +AmayList( c int) constructor dynamically allocates an array c elements long. Stores the memory AmayList0 address in a. Sets capacity to c. Sets length to 0. +clear0 void destructor deletes the array. +insert i: int):int append( i int): int glearo empties the list. (IOW, sets length to 0 in ArrayList) +remove(i int): int +peek( i: int& int const inserto-inserts the value in parameter i into the list, IN ASCENDING SFull(): bool const ORDER. Returns 0 if successful, -1 otherwise. +isEmpty(): bool const appendo adds the value in parameter ito the end of the list. Returns 0 if +getLength(): int const successful, -1 otherwise. +find(i int) nt const remgyen removes the first value found in the list matching the value in +print) :void const parameter i. Returns 0 if successful, -1 otherwise. isEullo returns true if the list is full, false otherwise. isEmpty returns true if the list is empty, false otherwise. findo returns the element index of a value matching the value in parameter i f found in the list, -1 otherwise printQ displays the values in the list on a single line, separated by spaces. peeko assigns the value at the front of the list to reference parameter i Returns 0 if successful -1 otherwise. Does not alter the list in any way. otes: insert and append() would normally not be within the same class, as they have incompatible logic. You are including them both here to avoid writing a second class whose code differs only by one method. When I test your class, insert and append will NOT be invoked on the same object without calling clear first. This way, the object will be tested as an ordered List or an Unordered list. When could a method fail? For example, insert could fail if the array is full.

Explanation / Answer

/*
* ArrayList.h
*
* Created on: Jan 25, 2016
*      Author: Satish-Ravi
*/

#ifndef ARRAYLIST_H_
#define ARRAYLIST_H_

class ArrayList {

private:
   int *a;
   int capacity;
   int length;

public:
   ArrayList();
   ArrayList(int c);
   void clear();
   int insert(int i);
   int append(int i);
   int remove(int i);
   void print();
   bool isFull();
   virtual ~ArrayList();
};

#endif /* ARRAYLIST_H_ */


/*
* ArrayList.cpp
*
* Created on: Jan 25, 2016
*      Author: Satish-Ravi
*/

#include <iostream>
using namespace std;

#include "ArrayList.h"

ArrayList::ArrayList() {
   // TODO Auto-generated constructor stub
   capacity = 5; //default capacity
   length = 0;
   a = new int [capacity];

}

ArrayList::~ArrayList() {
   // TODO Auto-generated destructor stub
}

ArrayList::ArrayList(int c) {
   // TODO Auto-generated constructor stub
   capacity = c; //default capacity
   length = 0;
   a = new int [capacity];

}

bool ArrayList::isFull() {
   return length >= capacity;
}

int ArrayList::append(int i) {

   if(!isFull()) {
       a[length++] = i;
       return 0;
   }
   return -1;
}


int ArrayList::insert(int i) {

   if(!isFull()) {
       int k =0, j;
       int temp;
       for(k = 0; k < length;k++) {
           if(i < a[k]) {
               //now move other items to the right in the queue
               for(j = length-1; j >= k;j--) {
                   a[j+1] = a[j];
               }
               //insert
               a[k] = i;
           }
       }
       a[length++] = i;
       return 0;
   }
   return -1;
}

void ArrayList::print() {
   int k;
   for(k = 0; k < length;k++) {
       cout << a[k] << " ";
   }
   cout <<endl;
}

void ArrayList::clear() {
   length = 0;
}

int ArrayList::remove(int i) {
   //length = 0;
   int k =0, j;
           int temp;
           for(k = 0; k < length;k++) {
               if(a[k] == i) {
                   //replace this item
                   for(j = k; j < length-1;j++) {
                       a[j] = a[j+1];
                   }
                   //insert
                   length--;
                   return 0;
               }
           }
   return -1;
}

int main()
{
        ArrayList list(10);

        list.append(9);
        list.append(6);
        list.append(8);
        list.print();
        list.clear();
        list.insert(3);
        list.insert(5);
        list.insert(7);
        list.insert(9);
        list.print();
        list.remove(7);
        list.remove(6);
        list.remove(5);
        list.remove(3);
        list.remove(9);
        cout << list.remove(10) << endl;
        list.print();

        return 0;
}

--output---

9 6 8
3 5 7 9
-1

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