This is in C++ using cygwin. if you are able to label each file (x_array.h and x_array.ipp) it'll help me greatly. Here

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This is in C++ using cygwin. if you are able to label each file (x_array.h and x_array.ipp) it'll help me greatly. Here

Post by answerhappygod »

This is in C++ using cygwin.
This Is In C Using Cygwin If You Are Able To Label Each File X Array H And X Array Ipp It Ll Help Me Greatly Here 1
This Is In C Using Cygwin If You Are Able To Label Each File X Array H And X Array Ipp It Ll Help Me Greatly Here 1 (68.35 KiB) Viewed 24 times
if you are able to label each file (x_array.h and x_array.ipp)
it'll help me greatly.
Here is my h file:
#ifndef X_ARRAY_H
#define X_ARRAY_H
class X_Array
{
public:
X_Array();
~X_Array();
bool operator == (const X_Array &)
const;
bool operator !=(const X_Array &)
const;
int add(int);
void removeLast();
int getSize() const;
int getAt(int index) const;
void setAt(int index, int value);
private:
int currLength;
int maxLength;
int ** dataArray;
};
Here is my cpp file:
#include "X_Array.h"
#include <iostream>
using namespace std;
X_Array::X_Array()
{
currLength = 0;
maxLength = 1;
dataArray = new int*[maxLength];
dataArray[0] = new int[10];
}
X_Array::~X_Array()
{
for (int i = 0; i < maxLength;
i++)
{
delete[]
dataArray;
}
delete[] dataArray;
}
bool X_Array::operator == (const X_Array & rhs) const
{
if (currLength != rhs.currLength)
{
return
false;
}
for (int i = 0; i < currLength;
i++)
{
if
(getAt(i) != rhs.getAt(i))
{

return false;
}
}
return true;
}
bool X_Array::operator !=(const X_Array & rhs) const
{
return !(*this == rhs);
}
int X_Array::add(int value)
{
if (currLength == maxLength * 10)
{
int ** temp
= new int*[maxLength + 1];
for (int i
= 0; i < maxLength; i++)
{

temp = dataArray;
}

temp[maxLength] = new int[10];
delete[]
dataArray;
dataArray =
temp;

maxLength++;
}
dataArray[currLength / 10][currLength %
10] = value;
currLength++;
return currLength - 1;
}
void X_Array::removeLast()
{
if (currLength == 0)
{

return;
}
currLength--;
if (currLength == (maxLength - 1) *
10)
{
int ** temp
= new int*[maxLength - 1];
for (int i
= 0; i < maxLength - 1; i++)
{

temp = dataArray;
}
delete[]
dataArray[maxLength - 1];
delete[]
dataArray;
dataArray =
temp;

maxLength--;
}
}
int X_Array::getSize() const
{
return currLength;
}
int X_Array::getAt(int index) const
{
if (index < 0 || index >=
currLength)
{
return
0;
}
return dataArray[index / 10][index %
10];
}
void X_Array::setAt(int index, int value)
{
if (index < 0 || index >=
currLength)
{

return;
}
dataArray[index / 10][index % 10] =
value;
}
For this assignment you will: • Correct any errors noted in Homeworko2 (Specifically memory corruption and memory leak errors) • Modify the X_Array class to be a Template ( so that it can hold any data type) • Add a sort function to the X_Array class • Add a find function to the X_Array class • Write a test program to test the various functions of the class. As before - to test/grade this homework we will compile and link your class with a test driver written by the instructor. Be sure to continue the naming conventions from Homework 02 Signatures of the new functions The sort function (meaning should be obvious ): void sort(); The find function takes a const reference to a type T and returns the index of where it is in the X_Array. Return-1 if not found. Do a binary search to efficiently find the item. int find ( const 1 ) const; For the sort function, you may use the same sort function you used in Homeworko1 Submitting your answer You will have to create two files. (x_Array.h and x_Array.ipp) Zip them up into a single file and submit that zip file. Comments We will be grading on comments for this assignment. Be sure to put comment blocks in front of all non- trivial function is the body of the code. Be sure to put comment blocks at the top of each file. Testing your code. I suggest you build a test program that will create various types of X_Array. IE one to hold int, one to hold string etc. Test by loading up various values, sort the values, and compare the expected with actual output both by examining every element, and by doing a find() for various elements.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply