Question: An elderly professor who has only ever programmed in FORTAN 7 7 and C decides to re - implement a function in C + +
An elderly professor who has only ever programmed in FORTAN and C decides to
reimplement a function in C The new program is to be written using modern
C memory management and collections from the Standard Template Library.
The result, along with a short test program, is as follows:
File: dblsum.h
#include
#include
int dblsumstd::uniqueptr&;
File: dblsum.cxx
#include
#include
int dblsumstd::uniqueptr& a
return aa;
#include
int main
auto aptr
std::makeunique
std::array
;
std::cout dblsumaptr std::endl;
return ;
Line numbers are for reference only and are not part of the code
Question continues on the next page...
Page of Continued Overleaf
a Write out the type of dblsum in full in English words, including the type of its
argument.
b Why must the argument to this function be passed as a reference?
c What is the advantage of passing a reference to an array constant rather than
passing an array variable?
d What is the type of a on line
e In lines a constant array object containing two integers is constructed
from a variable array object containing two integers. Is this allowed? If so
explain why.
f FORTRAN passes all function arguments by reference. The professors postgraduate student told him that was the same as passing a pointer in C
Do you agree with the postgraduate student? If not, explain the difference
between passing a pointer and passing a reference.
g The code could be simplified but achieve the same design aims by changing
the type of dblsum. Rewrite the function using a simpler convention, and
show how the test program would have to be modified to accommodate the
change.
h The makeunique function on lines allocates a new array on the heap.
Is the allocated memory freed, and if so when?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
