Question
// DO NOT CHANGE THIS FILE /********************** * File: check13a.cpp *********************/ #include using namespace std; #include numberList.h /**************************************************************** * Function: main * Purpose: Test the
// DO NOT CHANGE THIS FILE
/**********************
* File: check13a.cpp
*********************/
#include
using namespace std;
#include "numberList.h"
/****************************************************************
* Function: main
* Purpose: Test the NumberList class.
****************************************************************/
int main()
{
// YOU SHOULD NOT CHANGE ANYTHING IN THIS FUNCTION
cout
NumberList list(5);
cout
list.displayList();
cout
list.setNumber(2, 10);
list.displayList();
for (int i = 0; i
{
cout
NumberList tempList(i);
tempList.displayList();
}
cout
return 0;
}
#include "numberList.h"
#include
using namespace std;
/******************************************************
numberList.cpp file
* Function: getNumber
* Description: Returns the number at the given index.
******************************************************/
int NumberList::getNumber(int index) const
{
int number = -1;
if (index >= 0 && index
{
number = array[index];
}
return number;
}
/******************************************************
* Function: setNumber
* Description: Sets the value to the array at the given index.
******************************************************/
void NumberList::setNumber(int index, int value)
{
if (index >= 0 && index
{
array[index] = value;
}
}
/******************************************************
* Function: displayList
* Description: displays the list
******************************************************/
void NumberList::displayList() const
{
for (int i = 0; i
{
cout
}
cout
}
/*******************
* NumberList class
numberList.h
*******************/
#ifndef NUMBER_LIST_H
#define NUMBER_LIST_H
#include
class NumberList
{
private:
int size;
int *array;
public:
NumberList()
{
size = 0;
array = NULL;
}
// TODO: Add your constructor and destructor
int getNumber(int index) const;
void setNumber(int index, int value);
void displayList() const;
};
#endif
**********************************
MakeFile
**********************************
a.out : numberList.o check13a.o
g++ numberList.o check13a.o
numberList.o : numberList.h numberList.cpp
g++ -c numberList.cpp
check13a.o : numberList.h check13a.cpp
g++ -c check13a.cpp
clean :
rm *.o *.out
Instructions You are provided with a main function, and the start of the NumberList class. This class will st of integers, and then provides a getNumber function to return the value at any index in this array, and a setNumber to set one. Your task is to fill in a non-default constructor and a destructor for the class. ore a dynamically allocated array NumberList -array: int* -size: int +NumberList(size) +NumberList() +getNumber(index) : int +setNumber(index, value): void +displayList): void 1. Copy the provided code: mkdir check13a cd check13a cp /home/cs165new/check13a/* . 2. Implement a non-default constructor that accepts an integer for the size of the number list. It should: 1. Dynamically allocate an array of that size 2. Save the size in the member variable named, "size". 3. Fill in a default value of 0 for each spot in the array 3. Implement a destructor that frees up the memory of the array. It should 1. Delete the dynamically allocated array 2. Set the array pointer to be NULL. 3. Output a message that says, "Freeing memory". Note that we normally wouldn't output a message like this in a destructor, but this informs the testbed that you are using your destructor. 4. A main function is provided for you that will create and use some NumberList objects. You should not change this function. All vou need to do is add the constructor and destructor mentioned above
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