Question

Replace the fixed size array with a dynamic array Add a constructor that passes the size...

Replace the fixed size array with a dynamic array

Add a constructor that passes the size of the array as a parameter

Add a function that copies a dynamic array parameter into this array.

Add a copy constructor to intArray

Add a function that displays the array to a arbitrary stream

Derive intSortedArray from intArray

Add functions that enter elements into the array in sorted order

Override any base class functions that insert elements out of order.

*Note: I NEED help to write out this problem in C++ while using Visual Studio 2017 and NEED a source.cpp/main.cpp

//code

// intArray.h

class intArray
{
public:
   //constructors
   intArray();
   //destructors
   ~intArray();

   //predicates
   bool isFull();
   bool isEmpty();

   //accessors
   int getPopulation();
   int getCapacity();

   //custom methods
   void fill(int value);
   int find(int value);
   bool insertAt(int new_item, int new_position);
   void show();
private:
   int population;
   int capacity;
   int elts[16];
};

// intArray.cpp

#include <iostream>
#include <string>
#include "intArray.h"
using namespace std;

intArray::intArray()
{
   population = 0;
   capacity = 16;
}
intArray::~intArray()
{
   population = 0;
}
void intArray::fill(int value)
{
   for (int i = 0; i < population; ++i)
       elts[i] = value;
}
int intArray::find(int value)
{
   int i = 0;
   for (i = 0; i < population && elts[i] != value; ++i)
       ;
   if (i == population) i = -1;
   return i;
}
int intArray::getCapacity()
{
   return capacity;
}
int intArray::getPopulation()
{
   return population;
}
bool intArray::insertAt(int new_elt, int new_position)
{
   if (capacity <= population)
       return false;
   if (new_position < 0 || population < new_position)
       return false;

   //move the elements from new position to population - 1 down one position
   for (int i = population - 1; i >= new_position; --i)
       elts[i + 1] = elts[i];
   elts[new_position] = new_elt;
   population++;
   return true;
}
bool intArray::isEmpty()
{
   return population <= 0;
}
bool intArray::isFull()
{
   return capacity <= population;
}
void intArray::show()
{
   for (int i = 0; i < population; ++i)
       cout << elts[i] << ' ';
}

//source.cpp


#include <iostream>
#include "intArray.h"
using namespace std;

int main()
{

     return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer; //ran on dev platform

#include <iostream>
#include <string>
//#include "intArray.h"
using namespace std;

//main function
int main()
{
}


//CLASS CODE
class intArray
{
public:
//constructors
intArray();
intArray(int len);
//destructors
~intArray();

//dynamic array parameter
void addLen(int l);

//display function
void display();

//
void sortEntry(int mxIndex);
int* bs(int elt[], int l);


// ////predicates
bool isFull();
bool isEmpty();

//// //accessors
// int getPopulation();
// int getCapacity();
////
//// //custom methods
////

// void fill(int value);
// int find(int value);
// bool insertAt(int new_item, int new_position);
void show();


private:
int population;
int capacity;
// int elts[16];
int* elt;
int len;
int mxIndex;

};


intArray::intArray(int l)
{
len=l;
mxIndex=l;
elt = new int [l];

}

//dynamic array parameter
void intArray::addLen(int l){
len=l;
}
//Display function
void intArray::display(){
for (int i;i<len;i++){
cout<<elt[i];
}
}

//Function to Sort the intArray using bubbleSort
int* intArray::bs(int elt[], int l) {
bool ex;
do {
ex = false;
for (int i=0; i<l-1; i++) {
if (elt[i] > elt[i+1]) {
int temp = elt[i]; elt[i] = elt[i+1]; elt[i+1] = temp;
ex = true;
}
}
} while (ex);
return elt;
}

//Add functions that enter elements into the array in sorted order

void intArray::sortEntry(int mxIndex)
{
int i;
elt=bs(elt,i);
cout<<"Enter input = ";
cin>>i;
elt[mxIndex]=i;
elt=bs (elt,i);

}


intArray::intArray()
{
population = 0;
capacity = 16;
}

intArray::~intArray()
{
population = 0;
}

bool intArray::isEmpty()
{
return population <= 0;
}

bool intArray::isFull()
{
return capacity <= population;
}

void intArray::show()
{
for (int i = 0; i < population; ++i)
cout << elt[i] << ' ';
}

Add a comment
Know the answer?
Add Answer to:
Replace the fixed size array with a dynamic array Add a constructor that passes the size...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • //C++ program #include<iostream> using namespace std; template<typename T> class list{    private:        T*arr;   ...

    //C++ program #include<iostream> using namespace std; template<typename T> class list{    private:        T*arr;        int size;        int capacity;               void resize(){            capacity*=2;            T * newArr = new T[capacity];            for(int i=0;i<size;i++){                newArr[i] = arr[i];            }            delete(arr);            arr = newArr;                   }           public:       ...

  • USING THE C++ CODE BELOW, CAN YOU PLEASE SOLVE THE QUESTION AND EXPLAIN THE STEPS. class...

    USING THE C++ CODE BELOW, CAN YOU PLEASE SOLVE THE QUESTION AND EXPLAIN THE STEPS. class StaticStack { private: int *stack; int capacity; int top; // index of the top element public: StaticStack(int size); // constructor ~StaticStack(); bool isFull(); bool isEmpty(); void push(int); int pop(); }; #include "StaticStack.h" #include <iostream> using namespace std; StaticStack::StaticStack(int size) { stack = new int[size]; // constructing a size sized array capacity = size; top = -1; // empty stack    } StaticStack::~StaticStack() { delete...

  • 1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class...

    1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std;...

    Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std; int main(){    int rows = 5; int cols = 5; int x;    int** arr = new int[rows][cols]    cin >> x; arr[x][x] = x; cout << "arr[x][x] = " << arr[x][x];    return 0; } Question 2: Fix the code to initialize the 2D array elements to x #include <iostream> using namespace std; int main(){    int rows; int cols; int x;...

  • I need to implement raw array Stack for create empty stack, isEmpty, isFull, push, pop, and...

    I need to implement raw array Stack for create empty stack, isEmpty, isFull, push, pop, and size using below pseudo code. I need two classes with stack pseudo code implementation and the main method to demonstrate the correct working of each operation. pseudo code StackADT (using raw array) class StackADT { int top int items[] int max StackADT(int n) Initialize array to n capacity top = 0 max = n boolean isEmpty() if array has no elements return true else...

  • //Look for** to complete this program --C+ please --please add comments // using namespace std; #include...

    //Look for** to complete this program --C+ please --please add comments // using namespace std; #include <iostream> #include <stdlib.h> #include < string> #include "queue.h" //Purpose of the program: ** Algorithm: * int main() /** "A", "B", "C" in the queue //** while loop -- indefinitely { try {//** catches } //* end of loop } |/ II II II II II //File type: ** queue.cpp using namespace std; #include <iostream> #include "queue.h" // constructor queue::queue () } //destructor queue::~queue() queue::queue...

  • Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will...

    Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...

  • A library maintains a collection of books. Books can be added to and deleted from and...

    A library maintains a collection of books. Books can be added to and deleted from and checked out and checked in to this collection. Title and author name identify a book. Each book object maintains a count of the number of copies available and the number of copies checked out. The number of copies must always be greater than or equal to zero. If the number of copies for a book goes to zero, it must be deleted from the...

  • - implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h"...

    - implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h" template <typename DataType> StackArray<DataType>::StackArray(int maxNumber) { } template <typename DataType> StackArray<DataType>::StackArray(const StackArray& other) { } template <typename DataType> StackArray<DataType>& StackArray<DataType>::operator=(const StackArray& other) { } template <typename DataType> StackArray<DataType>::~StackArray() { } template <typename DataType> void StackArray<DataType>::push(const DataType& newDataItem) throw (logic_error) { } template <typename DataType> DataType StackArray<DataType>::pop() throw (logic_error) { } template <typename DataType> void StackArray<DataType>::clear() { } template <typename DataType> bool StackArray<DataType>::isEmpty() const {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT