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!!******
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
Array
// Create another Array object that works with
Array
// Call the assignment opreator of the Array class templated for
// Now, create an Array object that works with
Array
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
Get step-by-step solutions from verified subject matter experts
