Answered step by step
Verified Expert Solution
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
numbers Test your code as you implement it
I would first code some constructors and the print method.
input.txt
NumberList.cpp
#include "NumberList.h
#include
using namespace std;
default constructor, initializes all values of the list to
and sets length to
NumberList::NumberList
initialize all values in the numbers array to
int i;
for
i
; i
MAX
CAPACITY; i
numbers
i
;
length
;
outputs the numbers in the NumberList horizontally each separated by a comma
to the standard output screen
void NumberList::print
int i;
for
i
; i
length
; 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
; 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
cout
Unable to perform
list is filled to capacity
;
else
return
this;
NumberList& NumberList::operator
const NumberList& rhs
if
length
cout
Unable to perform
list is filled to capacity
;
else if
length
rhs
length
cout
Unable to perform
list would be over capacity
;
else
return
this;
Please complete in Cnot Java
Input numbers are
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started