Question
Task 1: Recall the class we used in the previous lab to allocate memory dynamically. Modify the header file and the source file given below
Task 1: Recall the class we used in the previous lab to allocate memory dynamically. Modify the header file and the source file given below so that they now work as template class (the array elements in the dynamically allocated memory can be any type as the user defines). dynarr.h #ifndef DYNARR_H_INCLUDED #define DYNARR_H_INCLUDED class dynArr { private: int *data; int size; public: dynArr(int); ~dynArr(); void setValue(int, int); int getValue(int); }; #endif // DYNARR_H_INCLUDED
dynarr.cpp #include "dynarr.h" #include
Task 2: Recall the complex number class we discussed in our lectures. Modify the class and overload the * (multiplication) and the != (not equal) operators for the class given below. complex.h #ifndef COMPLEX_H_INCLUDED #define COMPLEX_H_INCLUDED class Complex { public: Complex(); Complex(double, double); Complex operator+(Complex); void Print(); private: double Real, Imaginary; }; #endif // COMPLEX_H_INCLUDED
complex.cpp #include "complex.h" #include
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