Question: C++ #include IntArray.h #include #include int main() { // create an array of 10 ints (invoke the constructor) ds::IntArray nums(10); // randomly add 10 ints

C++

#include "IntArray.h" #include #include

int main() { // create an array of 10 ints (invoke the constructor) ds::IntArray nums(10);

// randomly add 10 ints to the array srand(time(0)); // setting the seed for rand() for (int i = 0; i < 10; i++) { nums[i] = rand() % 10 + 1; // generating random numbers by rand() }

// print the array std::cout << "Original:\t"; for (int i = 0; i < nums.length; i++) { std::cout << nums[i] << " "; } std::cout << std::endl;

// test the reverse function nums.reverse(); std::cout << "Reverse:\t"; for (int i = 0; i < nums.length; i++) { std::cout << nums[i] << " "; } std::cout << std::endl;

// now the destructor is invoked

return 0; }

IntArray.h

CXX := g++ CXXFLAGS := -O0 -g -Wall -std=c++11 -Werror=return-type

main.out: IntArray.cpp main.cpp $(CXX) $(CXXFLAGS) $^ -o $@

test: main.out valgrind --leak-check=full ./main.out

clean: rm -f *.out

IntArray.cpp

#include "IntArray.h"

namespace ds {

/** * Construct a new IntArray object * * @param len length of the IntArray */ IntArray::IntArray(int len) { // TODO: initialize data members }

/** * Destroy the IntArray object */ IntArray::~IntArray() { // TODO: delete the internal array }

/** * Reverse the IntArray */ void IntArray::reverse() { // TODO: reverse `storedArray` }

} // namespace ds

makefile

CXX := g++ CXXFLAGS := -O0 -g -Wall -std=c++11 -Werror=return-type

main.out: IntArray.cpp main.cpp $(CXX) $(CXXFLAGS) $^ -o $@

test: main.out valgrind --leak-check=full ./main.out

clean: rm -f *.out

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!