Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a class called NumberList. This class is designed to store and manipulate a list data structure. This class will store a list of real

Implement a class called NumberList. This class is designed to store and manipulate a list data structure. This class will store a list of real numbers of type double. The list will have a maximum capacity of
1
0
0
numbers. Test your code as you implement it
.
I would first code some constructors and the print method.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
input.txt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
6
1
2
3
4
5
6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
NumberList.cpp
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#include "NumberList.h
"
#include
using namespace std;
/
/
default constructor, initializes all values of the list to
0
/
/
and sets length to
1
0
NumberList::NumberList
(
)
{
/
/
initialize all values in the numbers array to
0
int i;
for
(
i
=
0
; i
<
MAX
_
CAPACITY; i
+
+
)
numbers
[
i
]
=
0
;
length
=
1
0
;
}
/
/
outputs the numbers in the NumberList horizontally each separated by a comma
/
/
to the standard output screen
void NumberList::print
(
)
{
int i;
for
(
i
=
0
; i
<
length
-
1
; i
+
+
)
cout
<
<
numbers
[
i
]
<
<
"
,
"
;
cout
<
<
numbers
[
i
]
<
<
endl;
}
/
/
constructor that takes an array of size l as input and assigns the first
/
/
l values of the NumberList to the corresponding l values of the input array
NumberList::NumberList
(
int l
,
const double a
[
]
)
{
if
(
l
<
=
MAX
_
CAPACITY
)
{
length
=
l;
for
(
int i
=
0
; i
<
length; i
+
+
)
numbers
[
i
]
=
a
[
i
]
;
}
else
cout
<
<
"NumberList cannot be created because the size is greater than MAX
_
CAPACITY
"
;
}
/
/
stores a value at the end of the NumberList, returns true if successful,
/
/
otherwise returns false
(
THE NUMBERLIST IS FILLED TO CAPACITY
)
bool NumberList::push
(
double value
)
{
if
(
length
>
MAX
_
CAPACITY
)
return false;
numbers
[
length
]
=
value;
length
+
+
;
return true;
}
/
*
NumberList::NumberList
(
int l
,
double n
)
{
}
NumberList::NumberList
(
const NumberList & nl
)
{
}
int NumberList::getLength
(
)
{
}
double NumberList::sum
(
)
{
}
double NumberList::ave
(
)
{
}
double NumberList::max
(
)
{
}
double NumberList::min
(
)
{
}
bool NumberList::isIn
(
double n
)
{
}
bool NumberList::pop
(
)
{
}
void NumberList::read
(
istream & inStream
)
{
if
(
&inStream
=
=
&cin
)
{
}
else
{
/
/
file structure: first line contains the number of numbers in the list
/
/
remaining lines contain the numbers each separated by a whitespace
}
}
bool NumberList::insert
(
double number, int position
)
{
}
/
/
SELECTION SORT algorithm
void NumberList::sort
(
char type
)
{
}
bool NumberList::operator
=
=
(
const NumberList& rhs
)
{
}
NumberList& NumberList::operator
=
(
const NumberList& rhs
)
{
/
/
avoid self
-
assignment, only do assignment if RHS is a different object from this
if
(
this
!
=
&rhs
)
{
}
return
*
this;
}
NumberList& NumberList::operator
+
=
(
const double& number
)
{
if
(
length
=
=
1
0
0
)
cout
<
<
"Unable to perform
+
=
,
list is filled to capacity
"
;
else
{
}
return
*
this;
}
NumberList& NumberList::operator
+
=
(
const NumberList& rhs
)
{
if
(
length
=
=
1
0
0
)
cout
<
<
"Unable to perform
+
=
,
list is filled to capacity
"
;
else if
(
length
+
rhs
.
length
>
1
0
0
)
cout
<
<
"Unable to perform
+
=
,
list would be over capacity
"
;
else
{
}
return
*
this;
}
Please complete in C++not Java
Input numbers are 1,2,3,4,5,6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions