Complete the C++ code below #include "std_lib_facilities.h" /*1. Define a function which calculates the outer product of two vectors. The function return is a matrix. */ vector> outerProduct(vector& A, vector& B) { //implement here } /*2. Define a function which transposes a matrix. */ vector> transpose(vector>& A) { //implementation } /*3. Define a function which calculates the multiplication of a matrix and it's transpose. */ vector> product(vector>& A) { // implementation } /*4. Define a print out function that will print out a matrix in the following format: Example: a 3 by 4 matrix should have the print out: 1 2 3 4 2 3 4 5 3 4 5 6 */ void printMatrix(vector>& A) { // implementation } int main() { // Define both vector A and vector B vector A = {1 ,2, 3, 4, 5}; vector B = {1, 2, 3}; /*Test outerProduct function, the expected output is: 1 2 3 2 4 6 3 6 9 4 8 12 5 10 15 */ vector> M = outerProduct(A, B); printMatrix(M); /*Test transpose function, the expected output is: 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 */ vector> tM = transpose(M); printMatrix(tM); /*Test product function, the expected output is: 14 28 42 56 70 28 56 84 112 140 42 84 126 168 210 56 112 168 224 280 70 140 210 280 350 */ vector> pM = product(M); printMatrix(pM); keep_window_open(); return 0; }
Complete the C++ code below
#include "std_lib_facilities.h"
/*1. Define a function which calculates the outer product of two
vector<vector<int>> outerProduct(vector<int>& A, vector<int>& B)
{
//implement here
}
/*2. Define a function which transposes a matrix. */
vector<vector<int>> transpose(vector<vector<int>>& A)
{
//implementation
}
/*3. Define a function which calculates the multiplication of a matrix and it's transpose. */
vector<vector<int>> product(vector<vector<int>>& A)
{
// implementation
}
/*4. Define a print out function that will print out a matrix in the following format:
Example: a 3 by 4 matrix should have the print out:
1 2 3 4
2 3 4 5
3 4 5 6
*/
void printMatrix(vector<vector<int>>& A)
{
// implementation
}
int main()
{
// Define both vector A and vector B
vector<int> A = {1 ,2, 3, 4, 5};
vector<int> B = {1, 2, 3};
/*Test outerProduct function, the expected output is:
1 2 3
2 4 6
3 6 9
4 8 12
5 10 15
*/
vector<vector<int>> M = outerProduct(A, B);
printMatrix(M);
/*Test transpose function, the expected output is:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
*/
vector<vector<int>> tM = transpose(M);
printMatrix(tM);
/*Test product function, the expected output is:
14 28 42 56 70
28 56 84 112 140
42 84 126 168 210
56 112 168 224 280
70 140 210 280 350
*/
vector<vector<int>> pM = product(M);
printMatrix(pM);
keep_window_open();
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images