answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Liula [17]
2 years ago
3

A dynamic integer matrix is a two dimensional array of integers. It can also be described as a pointer to a pointer or an array

of pointers. In this program you will write several small utility functions to test mastery of this concept. The function signatures and descriptions are given below. You may assume that the matrix will be a square matrix meaning that the number of rows equals the number of columns in the matrix.
Implement these functions:
i n t∗∗makeMatrix ( i n t n ) ;
v o i d p r i n t M a t r i x ( i n t∗∗A, i n t n ) ;
b o o l sumEqual ( i n t∗∗A, i n t∗∗B , i n t n ) ;
b o o l i s E q u a l ( i n t∗∗A, i n t∗∗B , i n t n ) ;
i n t d i a g o n a l ( i n t∗∗A, i n t n ) ;
i n t∗∗sumMatrix ( i n t∗∗A, i n t∗∗B , i n t n ) ;
i n t∗∗p r o d u c t ( i n t∗∗A, i n t∗∗B , i n t n ) ;
i n t∗∗s u b t r a c t M a t r i x ( i n t∗∗A, i n t∗∗B , i n t n ) ;
NEXT TWO ARE EXTRA CREDIT AND NOT REQUIRED
d o u b l e∗∗i n v e r s e M a t r i x ( i n t∗∗A, i n t n ) ;
d o u b l e∗∗m a t r i x D i v i s i o n ( i n t∗∗A, i n t∗∗B , i n t n ) ;
Please read the description of these functions carefully.
The makeMatrix function dynamically allocates memory for an integer matrix of size n. It prompts the user to enter values for each position of the matrix from left to right row by row, then returns the created matrix.The printMatrix function displays the matrix from its argument row by row legibly enough so that a grader can see the numbers corresponding to each position of the matrix.The sumEqual function takes two matrices of equal size and an integer indicating the size of the matrices. It computes the sum of all elements in each matrix and see if the sum of each matrix is equal to one another. The function returns true if the sums are equal or returns false if the sums are not equal to one another. You may want to use the enumerated type named "bool" that has only two values: true and false. It is defined in the stdbool.h header file. Function takes two matrices and an integer indicating the size of both matrices.
The isEqual function checks each matrix element by element and see if each element of matrix A is equal to its corresponding element in matrix B. It returns true if the two matrices are element-wise qual or false if even one element is not equal to its corresponding element in the other matrix. You may want to use the enumerated type named "bool" that has only two values: true and false. It is defined in the stdbool.h header file. Function takes two matrices and an integer indicating the size of both matrices.
The diagonal function calculates the product of the elements along the diagonal of the matrix and returns that number. Function takes a single matrix and an integer indicating the size of the matrix. It returns the product.
The sumMatrix function computes the sum of the two matrices. Note that the matrix sum is done element by element in the two matrices. Function takes two matrices and and an integer indicating the size of both matrices. It returns reference to a new dynamic matrix that contains the element by element sum for the corresponding positions.
The product function computes the matrix product by multiplying two matrices.It takes two matrices and an integer indicating the size of both matrices. It returns reference to a new dynamic matrix that is the result of matrix multiplication.
The subtractMatrix function computes the difference of two matrices. The function take two matrices and an integer indicating the size of both matrices. It returns reference to a new dynamic matrix containing the element-wise subtraction.
Your main function should operate similar to the array problem in the last homework assignment. Meaning it will first prompt the user for a size value to be used for both matrices then allow data for them to be entered (by using the makeMatrix function).

Computers and Technology
1 answer:
MrMuchimi2 years ago
3 0

Answer:

#include<iostream>

using namespace std;

int** makeMatrix(int n)

{

int** newM = new int*[n];

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

{

newM[i] = new int[n];

for(int j = 0;j < n; j++)

{

cin >> newM[i][j];

}

}

return newM;

}

void printMatrix(int** A, int n)

{

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

{

for(int j = 0;j < n; j++)

{

cout << A[i][j] << " ";

}

cout << endl;

}

}

bool sumEqual(int** A,int** B, int n)

{

int sum1 = 0, sum2 = 0;

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

{

for(int j = 0; j < n; j++)

{

sum1 += A[i][j];

sum2 += B[i][j];

}

}

return sum1 == sum2;

}

bool isEqual(int** A, int** B, int n)

{

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

{

for(int j = 0; j < n; j++)

{

if(A[i][j] != B[i][j])

{

return false;

}

}

}

return true;

}

int diagonal(int** A, int n)

{

int product = 1;

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

{

product *= A[i][i];

}

return product;

}

int** sumMatrix(int** A, int** B, int n)

{

int** C = new int*[n];

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

{

C[i] = new int[n];

for(int j = 0; j < n; j++)

{

C[i][j] = A[i][j] + B[i][j];

}

}

return C;

}

int** product(int** A, int**B, int n)

{

int** C = new int*[n];

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

{

C[i] = new int[n];

for(int j = 0; j < n; j++)

{

C[i][j] = 0;

for(int k = 0; k < n; k++)

{

C[i][j] += A[i][k] * B[k][j];

}

}

}

return C;

}

int** subtractMatrix(int** A, int** B, int n)

{

int** C = new int*[n];

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

{

C[i] = new int[n];

for(int j = 0; j < n; j++)

{

C[i][j] = A[i][j] - B[i][j];

}

}

return C;

}

int main()

{

cout << "Enter the size of the matrices : ";

int n;

cin >> n;

int** m1 = makeMatrix(n);

int** m2 = makeMatrix(n);

cout << endl << "Print the first matrix : "<< endl;

printMatrix(m1,n);

cout << "Print the second matrix : " << endl;

printMatrix(m2,n);

cout << "Is sum equal : " << sumEqual(m1,m2,n) << endl;

cout << "Are these two matrices equal : " << isEqual(m1,m2,n) << endl;

cout << "Product of diagonal elements of first matrix is : " << diagonal(m1,n) << endl;

cout << "Sum of two matrices is : " << endl;

int** sum = sumMatrix(m1,m2,n);

printMatrix(sum,n);

cout << "Product of two matrices is : " << endl;

int** pro = product(m1,m2,n);

printMatrix(pro,n);

cout << "Difference of two matrices is: " << endl;

int** difference = subtractMatrix(m1,m2,n);

printMatrix(difference, n);

return 0;

}

Explanation:

All the required functions have been implemented. See the output snippet which is added for better understanding.

You might be interested in
One form of competition-based pricing is going-rate pricing, inwhich a firm bases its price largely on competitors' prices, with
Kobotan [32]

Answer:

Out of the four options , the option that is most suitable  is

option b. Cost, demand

<u>cost</u> or to <u>demand</u>

Explanation:

Going rate pricing is a form of competition based pricing. This pricing is commonly used for homogeneous products i.e., products with very minute distinction or variation among producers.

This type of pricing is based on setting price on the basis of the prevailing market trends in pricing of goods or services, so, the prices are largely based on the competition in the market rather than considering its own cost and demand.

8 0
2 years ago
In a ____________________ attack, the attacker sends a large number of connection or information requests to disrupt a target fr
Blababa [14]

DDoS - Distributed Denial of Service

<u>Explanation:</u>

  • In DDoS attack, the attack comes from various system to a particular one by making some internet traffic.
  • This attack is initiated from various compromised devices, sometimes distributed globally through a botnet. It is different from other attacks  such as (DoS) Denial of Service attacks, in which it utilizes an unique Internet-connected device ( single network connection) to stream a target with the malicious traffic.
  • So in DDoS, multiple systems are involved in the attack and hence we can conclude that as the answer.
8 0
2 years ago
a. STOP: What is a technology habit you practice today that you now realize will not help you to be successful? Explain why it’s
Zina [86]
A technology habit that I practice today that I realize will not help me to be successful is playing games on my phone. It’s important to stop doing this because instead of playing a game I could be doing more helpful things, like reading a book.
3 0
2 years ago
Read 2 more answers
A user complains that her computer is performing slowly. She tells you the problem started about a week ago when new database so
k0ka [10]

Answer:

Option (B) is the correct of this question.

Explanation:

The performance of a monitor and process counters to observe the performance is the tool or method which determines the new software is hogging the computer resources. So this way the user don't have any problem with computer.

  • You can view log files in Windows Performance Monitor to see a visual representation of the performance counter data.
  • Performance counters are bits of code that log, count, and measure software events that allow a high-level view of user trends.
  • To customize the tracking of AD FS output using the Quality Monitor.
  • Type Output Monitor on Start screen, then click ENTER.
  • Expand Data Collector Sets in the console tree, right-click on User Specified, point to New, then select Data Collector Collection.

Other options are incorrect according to the given scenario.

4 0
2 years ago
[20 points] 3.3 Code Practice: Question 2
igor_vitrenko [27]

Answer:

See explanation

Explanation:

The attachment show that you've attempted the question already.

I'll assist in making corrections to your source code.

First, edit line 5 to

if(r<= 255 and g<=255 and b <=255):

Then edit line 8 to:

if(r>= 255):

Then edit line 11 to:

if(g>= 255):

Lastly, edit line 14 to:

if(b>= 255):

<em>Other part of the attachment is correct</em>

3 0
2 years ago
Other questions:
  • In three to five sentences, describe whether or not files should be deleted from your computer.
    13·2 answers
  • Suppose you define a java class as follows: public class test { } in order to compile this program, the source code should be st
    14·1 answer
  • PowerPoint is a visual aid for many speakers. Discuss some points to remember when adding text to a PowerPoint presentation. How
    13·1 answer
  • Leena needs to manually update the TOC and would prefer not to change the styles in the document.
    9·2 answers
  • 3.5 Code Practice
    11·2 answers
  • A class of Students was previously defined with the following properties: a string name, an integer age, a Boolean variable indi
    14·1 answer
  • Jennifer has written a short story for children. What should be her last step before she submits the story for publication?
    11·1 answer
  • We have an internal webserver, used only for testing purposes, at IP address 5.6.7.8 on our internal corporate network. The pack
    15·1 answer
  • You should see an error. Let's examine why this error occured by looking at the values in the "Total Pay" column. Use the type f
    14·1 answer
  • Write a method named removeDuplicates that accepts a string parameter and returns a new string with all consecutive occurrences
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!