Question

In: Computer Science

Write a function that will take in an array (of type double), and will return the...

Write a function that will take in an array (of type double), and will return the array with all of the elements doubled. You must use pass-by-reference and addressing and/or pointers to accomplish this task. C++

Solutions

Expert Solution

// C++ program to create a function that will take in an array (of type double), and will return the array with all of the elements doubled

#include <iostream>

using namespace std;

// function that takes input the array and size of the array

// and returns elements of the array doubled

void elementsDoubled(double array[], int size)

{

       // loop to double the elements of the array being doubled

       for(int i=0;i<size;i++)

       {

             array[i] = array[i]*array[i];

       }

}

int main()

{

      

       int size;

       // input the number of elements in the array

       cout<<"Enter the number of elements : ";

       cin>>size;

       double array[size];

       // loop to input the elements of the array

       for(int i=0;i<size;i++)

       {

             cout<<"Enter element-"<<(i+1)<<" : ";

             cin>>array[i];

       }

       elementsDoubled(array,size); // call the function to double the elements of the array

       // display the array elements

       for(int i=0;i<size;i++)

             cout<<array[i]<<" ";

       cout<<endl;

               return 0;

}

//end of program

Output:


Related Solutions

I need to write a function the will take in an array (of type double), and...
I need to write a function the will take in an array (of type double), and will return the array with all of the elements doubled while using pass-by-reference and addressing and/or pointers. This is what i have so far, but im messing up in line 31 where i call the function i believe so im not returning the correct array? please help edit. #include <iostream> #include <iomanip> using namespace std; double *doubleArray ( double arr[], int count, int SIZE);...
Write a function in C# that takes an array of double as the parameter, and return...
Write a function in C# that takes an array of double as the parameter, and return the average
Write a class DataSet that stores a number of values of type double in an array...
Write a class DataSet that stores a number of values of type double in an array list. Provide methods to insert a value to the array list and to compute the sum, average, and maximum value. Please put a note on what you did is for what. So I can understand this question better. Code provided: import java.util.*; public class DataSet {    private ArrayList<Double> data; /** Constructs an empty data set. @param maximumNumberOfValues the maximum this data set can...
Write a method that, given an array of grades stored as double values, computes and return...
Write a method that, given an array of grades stored as double values, computes and return their mean.    Write another method that will return an array of the mean grade obtained by an arbitrary number of student.    This method will take a 2-dimensional array of double values in which each row corresponds to the grade vector    for a different student. You can compute the mean for each row as you did before...    Once you are done,...
Write a function hitRate(A, B) to return the percentage of elements in array A that match...
Write a function hitRate(A, B) to return the percentage of elements in array A that match the elements with the same index in array B. A and B are 1darrays or 2darrays of the same shape. Sample: if X = np.array([1, 3, 5, 8]); Y = np.array([2, 1, 3, 8]), then hitRate(X, Y) returns 0.25. in python program
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list. (please do on racket language)
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list.
Write, specify and prove the function reverse that reverses an array in place. Take care of...
Write, specify and prove the function reverse that reverses an array in place. Take care of the unmodified part of the array at some iteration of the loop. Assume that the swap function is already proved. Note: Prototype is as below. [7 M] [CO2] void swap(int* a, int* b); void reverse(int* array, size_t len){ }
In C++, Write the definition of the function MaximumCount() whose header is int MaximumCount(Array<double>& data) It...
In C++, Write the definition of the function MaximumCount() whose header is int MaximumCount(Array<double>& data) It returns the amount of times the maximum value of data appears in data. If data is empty, it returns 0. For instance, if data = [7, 1, 4, 9, 6, 7, 7, 3, 2, 6, 9, 5, 9], it will return 3 since 9 appears three times
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT