AT&T; 11:10 AM @ 21% moodle3.subr.edu Homewerk 3 Classes and Data Abstraction Yo
ID: 3589886 • Letter: A
Question
AT&T; 11:10 AM @ 21% moodle3.subr.edu Homewerk 3 Classes and Data Abstraction You have to submit the homework only through the Moodle: please do not send it to CMPS 201 Date:09.26.2017 my mailbox 1. Please design your own array-based list to hold double variables Dynamically allocate memory for that array, Ask a user to input the size of the array. Introduce insert, delete, empey, and display functions 2. Design your own linked list class to hold a series of integers. The class should have member functions for appending, inserting and deleting the nodes Do not forget to add a destructor that destroys a list. 3. Modify the list class you created in the previous programming challenges by adding a member function for inserting a new item at a specified position. A position of 0 means that the value will become the first item on the list, a position of 1 means that the value will become the second item on the list and so on A position equal to or greater than the length of the list means that the value is placed at the end of the list You should have "h les and "app files where you define classes and main code. This homework is due October 11. 2017Explanation / Answer
arrayList.h
class arrayList {
private:
double *arr;
int size;
int count;
public:
arrayList();
bool insert(double item);
bool del(double item);
void empty();
void display();
};
arrayList.cpp
#include<iostream>
#include "arrayList.h"
using namespace std;
arrayList::arrayList() {
cout << "Enter array size: ";
cin >> size;
arr = new double[size];
}
bool arrayList::insert(double item) {
if (count == size)
return false;
arr[count++]=item;
return true;
}
bool arrayList::del(double item) {
int i;
for (i = 0; i < count; i++)
if(arr[i] == item)
break;
if (i == count)
return false;
for ( ; i < count -1; i++)
arr[i] = arr[i+1];
count --;
}
void arrayList::empty() {
count = 0;
}
void arrayList::display() {
cout << "[";
for (int i = 0; i < count; i++)
if(i > 0)
cout << " " << arr[i];
else
cout << arr[i];
cout << "]" << endl;
}
bro, due to immense pressure, we are solving 1 question, or 4 sub questions. Please co-operate and post the remaining unanswered question again!