Question

Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a...

Write a function makeDoubles  in c++, that takes an integer parameter called size and:
  • allocates a new array of that many double's
  • initializes all elements to be 0
  • returns this array

Homework Answers

Answer #1
#include <iostream>

using namespace std;

double *makeDoubles(int size);

int main() {
    int size;
    cout << "Enter size: ";
    cin >> size;
    double *arr = makeDoubles(size);
    for (int i = 0; i < size; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl;
    delete[] arr;
    return 0;
}

double *makeDoubles(int size) {
    double *arr = new double[size];
    for (int i = 0; i < size; ++i) {
        arr[i] = 0;
    }
    return arr;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C Programming: Write a function that takes in an array of integers and an integer containing...
C Programming: Write a function that takes in an array of integers and an integer containing the count of elements, then have it returns the sum of all the even values inside the array.
(C++) Write a function called triple that takes an array of integers as a parameter as...
(C++) Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)
C programing Write a function that takes in an integer as input and returns an integer...
C programing Write a function that takes in an integer as input and returns an integer array of zeros.
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT