Question

Using C++ Write a function that given two dynamical arrays (A and B) of doubles of...

Using C++

Write a function that given two dynamical arrays (A and B) of doubles of a given size N, will return a N by N dynamical array C such that C[i][j]=A[i]*B[j]. e.g. A={1,2,3}, B={10,20,30}, will result in C={{10,20,30},{20,40,60}, {30, 60, 90}}

double** outerProd(double *A, double *B, int size);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ code

#include<iostream>
using namespace std;
//function prototype
double** outerProd(double *A, double *B, int size);
//main function
int main()
{
   int size = 3;
   double *A = new double[size] { 1, 2, 3 };
   double *B = new double[size]{ 10,20,30 };
   //call the function
  
   double **c = outerProd(A, B, size);

   //print the array
   cout << "{"<<endl;
   for (int i = 0; i < size; i++)
   {
       cout << "{";
       for (int j = 0; j < size; j++)
       {
           cout << c[i][j] << ",";
       }
       cout << "}" << endl;
   }
   cout << "}" << endl;
   //to hold the output screen
   system("pause");
   return 0;
}

//function definition
double** outerProd(double *A, double *B, int size)
{
   double **c ;
   c = new double*[size];
   for (int i = 0; i < size; i++)
   {
       c[i] = new double[size];
       for (int j = 0; j < size; j++)
       {
           c[i][j] = A[i]*B[j];
       }
   }
   return c;
}

//output

//If you need any help regarding this solution ............ please leave a comment .......... thanks

Add a comment
Know the answer?
Add Answer to:
Using C++ Write a function that given two dynamical arrays (A and B) of doubles of...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • In C++ Write a function that accepts two int arrays of the same size. The first...

    In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...

  • c++ help Write a program that: Creates two finite arrays of size 10 These arrays will...

    c++ help Write a program that: Creates two finite arrays of size 10 These arrays will serve as a storing mechanism for student grades in Classes A and B Uses a loop to populate the arrays with randomly generated numbers from 0 to 100.These numbers will represent student grades. Compute average grade of each class. Finally, output the two arrays and the message with two averages and best class. ("Class A average is: 65.43; class B average is: 68.90. Class...

  • Write a C function bool arrayEqual that compares two 2D arrays. It accepts the following arguments...

    Write a C function bool arrayEqual that compares two 2D arrays. It accepts the following arguments int a[ROW][COL], int b[ROW][COL], m, n (m and n are the size of the rows and columns correspondingly). It returns true if all the corresponding elements are equal in a and b, otherwise false. Write the main function. Initialize two arrays (e.g. 3*4 dimension).

  • In C Write a couple of functions to process arrays. Note that from the description of...

    In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an int array and size, and...

  • In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different...

    In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different types of known parameter lists which are either void DisplayMax(string idI, double value[], int size) or void DisplayMax(int idn, short value几int size). The first and second parameters are parallel arrays. (Parallel Arrays are two arrays whose data is related by a common index. For example: with the string array and double array, index 5 of the string array would have some name, and index...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • USING C++: Write a function that given a 2D dynamic array of integers, will return the...

    USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...

  • C++ Please     Contact list - functions & parallel arrays/CStrings No Vectors can be used since we...

    C++ Please     Contact list - functions & parallel arrays/CStrings No Vectors can be used since we haven't learned them yet !! A contact list is a place where you can store a specific information with other associated information such as a phone number, email address, birthday, etc. Write a program that will read 5 data pairs into two parallel arrays. Data pairs consist of a name (as a CString) and a GPA (double). That list is followed by a name,...

  • use java and write in text a. Rewrite the following code segment using if statements. Assume...

    use java and write in text a. Rewrite the following code segment using if statements. Assume that grade has been declared as of type char. char grade= 'B';; switch (grade) { case 'A': System.out.println("Excellent"); break case 'B': System.out.println("Good"); default: System.out.println("you can do better”); } - b. write Java code that inputs an integer and prints each of its digit followed by ** e.gif the integer is 1234 then it should print 1**2**3**4 e.g. if the integer is 85 then it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT