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
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
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