Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hi ! this is C++ Subject help me to find the subtraction result , if u can add multiplication and addition that would be wonderful,

hi ! this is C++ Subject

help me to find the "subtraction result" , if u can add "multiplication and addition" that would be wonderful, but i want to see only the subtraction part.

also, please use "C++ online compiler". and "RUN" the result using that online compiler. SHOW ME HOW TO DO IT.

#include

using namespace std;

// Function to display the menu of operations

int displayMenu() {

int choice;

cout

cout

cout

cout

cout

cin >> choice;

return choice;

}

// Function to get the size of the matrices from the user

void getMatrixSize(int &rows, int &cols) {

cout

cin >> rows;

cout

cin >> cols;

}

// Function to get a matrix from the user

void getMatrix(int **matrix, int rows, int cols) {

cout

for (int i = 0; i

for (int j = 0; j

cin >> matrix[i][j];

}

}

}

// Function to perform matrix addition

void addMatrices(int **matrix1, int **matrix2, int rows, int cols) {

cout

for (int i = 0; i

for (int j = 0; j

cout

}

cout

}

}

// Function to perform matrix multiplication

void multiplyMatrices(int **matrix1, int **matrix2, int rows1, int cols1, int cols2) {

cout

for (int i = 0; i

for (int j = 0; j

int sum = 0;

for (int k = 0; k

sum += matrix1[i][k] * matrix2[k][j];

}

cout

}

cout

}

}

// Function to perform matrix subtraction

void subtractMatrices(int **matrix1, int **matrix2, int rows, int cols) {

cout

for (int i = 0; i

for (int j = 0; j

cout

}

cout

}

}

int main() {

cout

cout

int choice, rows1, cols1, rows2, cols2;

// Create arrays to store the matrices

int **matrix1, **matrix2;

// Get the size of the first matrix from the user

cout

getMatrixSize(rows1, cols1);

matrix1 = new int*[rows1];

for (int i = 0; i

matrix1[i] = new int[cols1];

}

// Get the elements of the first matrix from the user

cout

getMatrix(matrix1, rows1, cols1);

// Get the size of the second matrix from the user

cout

getMatrixSize(rows2, cols2);

matrix2 = new int*[rows2];

for (int i = 0; i

matrix2[i] = new int[cols2];

}

// Get the elements of the second matrix from the user

cout

getMatrix(matrix2, rows2, cols2);

// Loop until the user chooses to exit

do {

choice = displayMenu();

switch (choice) {

case 1: // Addition

if (rows1 == rows2 && cols1 == cols2) {

addMatrices(matrix1, matrix2, rows1, cols1);

} else {

cout

}

break;

case 2: // Multiplication

if (cols1 == rows2) {

multiplyMatrices(matrix1, matrix2, rows1, cols1, cols2);

} else {

cout

}

break;

case 3: // Subtraction

if (rows1 == rows2 && cols1 == cols2) {

subtractMatrices(matrix1, matrix2, rows1, cols1);

} else {

cout

}

break;

case 0: // Exit

cout

break;

default:

cout

break;

}

} while (choice != 0);

return 0;

}

image text in transcribed

Pseudocode. CASE 1: // Addition PRINT "Welcome to the matrix calculator program!" IF (rows 1== rows 2AND cols 1== cols 2 ) THEN CALL addMatrices(matrix1, matrix 2 , rows1, cols1) PRINT "Developed by ali abdulaah,(bf220001), Suliman (be320107), mphaped (bf200080), and ELSE saaglim, Mohamed (Bf180010)" PRINT "Error: matrices have different dimensions" DECLARE rows 1 , cols1, rows 2 , cols2, choice END IF CASE 2: // Multiplication // Get the size of the first matrix from the user IF ( cols 1== rows 2) THEN PRINT "Enter the size of the first matrix:" CALL multiplyMatrices(matrix1, matrix2, rows1, cols1, cols2) CALL getMatrixSize(rows1, cols1) ELSE PRINT "Error: number of columns of first matrix must be equal to number of rows of second // Get the elements of the first matrix from the user END IF PRINT "Enter the elements of the first matrix:" CASE 3: // Subtraction DECLARE matrix1[rows 1][cols1] IF (rows1 == rows 2AND cols 1== cols 2 ) THEN CALL getMatrix(matrix1, rows1, cols1) CALL subtractMatrices(matrix1, matrix 2 , rows1, cols1) ELSE // Get the size of the second matrix from the user PRINT "Error: matrices have different dimensions" PRINT "Enter the size of the second matrix:" CALL getMatrixSize(rows 2 , cols 2 ) END IF CASE 0: // Exit PRINT "Exiting program..." // Get the elements of the second matrix from the user DEFAULT: PRINT "Enter the elements of the second matrix:" PRINT "Invalid choice. Please select a valid operation." DECLARE matrix 2 [rows 2 ] [cols2] END SWITCH CALL getMatrix(matrix2, rows 2 , cols2) WHILE (choice != 0) // Loop until the user chooses to exit DO CALL displayMenu() STORE result in choice SWITCH choice

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to Figure 3.6, page

Answered: 1 week ago