Question: Can you please help me with this ? it's for C++ *****The requiered files are below!!****** Array.h #ifndef ARRAY_H_ #define ARRAY_H_ // Your TEMPLATED Array

Can you please help me with this ? it's for C++ *****The requiered files are below!!******Can you please help me with this ? it's for C++ *****The

Array.h

#ifndef ARRAY_H_ #define ARRAY_H_

// Your TEMPLATED Array class declaration goes here:

// Your TEMPLATED Array class implementations for methods (1) and (2) (parametrized ctor and assignment operator) go here:

#endif //ARRAY_H_

Lab9.cpp

#include

#include "Array.h"

using namespace std;

int main() { // Create an Array object that works with Type by invoking the parametrized ctor of the templated class // At this time the compiler: // a) first generates the required class declaration and method implementation out of the provided template in Array.h // creates a class Array where T is int // b) after it has generated this code, it actually invokes the requested method (the parametrized ctor)

Array intArray_0(10, -10); //10 elements, all with value -10

// Create another Array object that works with Type. The compiler has already generated the class Array so it just invokes the ctor method

Array intArray_1(20, 1000); //20 elements, all with value 1000

// Call the assignment opreator of the Array class templated for Type. // The compiler understands that the left-hand side argument (intArray_0) is of Array type, and the right-hand side argument (intArray_1) is also of Array type. // Therefore it knows to call the assignment operator of the Array class which it generated before. intArray_0 = intArray_1;

// Now, create an Array object that works with Type by invoking the parametrized ctor of the templated class // The compiler will now generate another SEPARATE class Array and its required methods and act in the same way as described above Array doubleArray_0(10, -0.1); //10 elements, all with value -0.1

Array doubleArray_1(20, 0.001); //20 elements, all with value 0.001

doubleArray_0 = doubleArray_1;

return 0; }

Makefile

TARGET = lab9 LIBS = -lm #Math Library, just a placeholder HEADERS = Array.h SRCS = lab9.cpp OBJECTS := $(patsubst %.cpp,%.o,$(SRCS)) CXX = g++ CXX_FLAGS = -Wall -std=c++11 #C++11 just for reference, not necessary

.PHONY: default all clean

all: depend $(TARGET)

#Rules to recompile template headers when they change depend: .depend .depend: $(HEADERS) rm -f ./.depend $(CXX) $(CXX_FLAGS) -MM $^ > ./.depend; include .depend

%.o: %.cpp $(HEADERS) $(CXX) $(CXX_FLAGS) -c $

$(TARGET): $(OBJECTS) $(CXX) $(CXX_FLAGS) $(OBJECTS) $(LIBS) -o $@

clean: -rm -f *.o -rm -f ./.depend -rm -f $(TARGET)

You are given the declaration of a dynamic memory FloatArray class that only works with float value types. For simplicity the class declaration only contains a parametrized ctor and an assignment operator: class FloatArrayf public: FloatArray (size_t size, const float & val); FloatArray & operator- (const FloatArray & rhs)i 1/ (2) private: float * m_buffer; sizet m size; The parametrized ctor (1) dynamically allocates an array of size number of floats (m buffer is used to "remember" that address) and assigns to all the value of val. The assignment operator (2) deallocates any previously allocated memory, and then allocates enough new memory to copy over the contents of the FloatArray rhs. Then it copies all elements You have to template this class and its methods such that it works with any possible type T: . Give the templated class declaration. 2. Give the implementation of the templated class parametrized ctor (1). 3. Give the implementation of the templated class assignment operator (2)

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!