Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions