Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) 8 pts. In the table below write code to create and allocate the memory for tw

ID: 3903774 • Letter: 1

Question

1) 8 pts. In the table below write code to create and allocate the memory for two arrays of 6 doubles. One array should be a static variable. One array should be a dynamic variable. You should use the following definition: const int SIZE = 6; Static Dynamic 2) 4 pts. In C++ what type of function is preferred to a macro? 3) 8 pts. The method cout.flags sets multiple output format flags at one time. (Similar to cout.setf sets one flag at a time.) For example ou might call it like below. What purpose does the sign serve? cout.flags Cios.base: :right I ios.base::hex | os base::showbase);

Explanation / Answer

1. Dynamic Declaration

#include <iostream>

using namespace std;
const int SIZE = 6;
int main()
{
  
double *array = new double[SIZE];

delete [] array;

return 0;
}

Static Decalaration

#include <iostream>

using namespace std;
const int SIZE = 6;
int main()
{
  
double *array[SIZE];

return 0;

}

2.

Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called. ?Generally, you should use macros to replace small, repeatable code sections, and you should use functions for larger coding tasks that might require several lines of code.

3.

Bitwise OR ( | ) is used to turn on multiple bits at the same time. In the given question it is used to combine the flags.