Question

In: Computer Science

Create a C++ project in visual studio. You can use the C++ project that I uploaded...

Create a C++ project in visual studio.

You can use the C++ project that I uploaded to complete this project.

1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which is equal to M[i][j].

Explain the time complexity of this function inside of the code as a comment.

2. Write a function that will accept two integer matrices C and D by reference parameters. The function will compute the transpose of C and store it in D. For your information, the transpose of matrix C is D, where D[j][i] = C[i][j].

Explain the time complexity of this function inside of the function code as a comment.

3. Write a function that will accept one integer matrix E and one column vector F by reference parameters, and one integer I as a value parameter. The function will return an integer v, which is the i-th coefficient of row vector denoted by E*F (multiplication of E and F). For example, if V = E*F, the function will return v, which is equal to V[i].

Explain the time complexity of this function inside of the function code as a comment.

Solutions

Expert Solution

//Question1:-
//rename arr1->A and arr2->B
//time complexity for the loop is n^3 as wee use 3 loops in it
#include <iostream>
int print(int arr1[3][3],int arr2[3][3],int i,int j) 
{ 
    int matrix[i][i];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            int sum=0;
            for(int k=0;k<3;k++){
                sum=sum+(arr1[i][k]*arr2[k][j]);
            }
            matrix[i][j]=sum;
        }
    }
    for (int x = 0; x< 3; x++){ 
      for (int y = 0; y < 3; y++){ 
            std::cout<<matrix[x][y]<<"\t";
      }
  std::cout<<"\n";
    }
    return matrix[i][j];
} 
  
int main() 
{
    int i=1,j=2;
    int arr1[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    int arr2[3][3] = {{3,4,5,},{7,5,4},{5,8,2}};
    int m=print(arr1,arr2,i,j);
    if(m!=0)
        std::cout<<m<<"\t"<<"Element found";
    else
        std::cout<<"\t"<<"Element not found";
    return 0; 
} 
//Question2:-
//time complexity for the loop is n^2 as wee use 2 loops in it

#include <iostream>
void print(int C[3][3],int D[3][3]) 
{ 
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            D[i][j]=C[j][i];
        }
    }
} 
  
int main() 
{
    int C[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    int D[3][3];
    std::cout<<"Before Transpose"<<"\n";
    for (int x = 0; x< 3; x++){ 
      for (int y = 0; y < 3; y++){ 
            std::cout<<C[x][y]<<"\t";
      }
    std::cout<<"\n";
    }
    print(C,D);
    std::cout<<"After Transpose"<<"\n";
    for (int x = 0; x< 3; x++){ 
      for (int y = 0; y < 3; y++){ 
            std::cout<<D[x][y]<<"\t";
      }
    std::cout<<"\n";
    }
} 

I hope you like the solution if you do so then press that thumbs up button to support.


Related Solutions

Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for name, one for hours worked,and the last for hourly rate. The arrays will receive the information from inputs from the screen.For example, you will ask the following three questions: a) Employee name: b) Hours worked: c) Hourly rate: After you have received all ten records and have inserted them into the array, you will then calculate the hourly rate times the hours worked to...
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in...
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in Assignment 04.1 to C++ code inside the main() function. Your program should prompt for a single 9-digit routing number without spaces between digits as follows: Enter a 9-digit routing number without any spaces: The program should output one of: Routing number is valid Routing number is invalid A C++ loop and integer array could be used to extract the routing number's 9 digits. However...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes. THANKS
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT