Answered step by step
Verified Expert Solution
Question
1 Approved Answer
question 1 Exercise: matrix calculator In this question you are required to write a C program that performs basic arithmetic operations on square matrices. The
question
Exercise: matrix calculator
In this question you are required to write a C program that performs basic arithmetic operations on square matrices. The program should allow the user to enter up to a pair of matrices an operation to perform addition, subtraction, multiplication, or and, not, transpose. Then display the result accordingly. The numbers in the matrix can be whole, rational and even complex
Examples of input output
Explanation of the syntax : Kotex
: represents a matrix in a compact form and includes the following elements:
matrix size:
a The first number indicates the number of rows in the matrix.
b The second number indicates the number of columns in the matrix.
: separates the size of the matrix from its values.
the values in the matrix:
a The values are separated by commas and arranged in consecutive lines.
b In this case, the first row contains the values and and the second row contains the
The values and
Input requirements:
Below is an example of the input and output of the program. The program receives a calculation action from the user and prints the output like this in a loop until the string END is entered. reminiscent of the terminal interface when the END string is received, the program exits.
:
:
ADD
:
:
:
SUB
:
:
:
MUL
:
END
explanation:
In the first input, the user enters two x matrices with the values
: and asks to add ADD the resulting output is a new matrix
: with the values x in size In the second input, the user again enters two x matrices with the values :
and asks to perform a subtraction SUB The resulting output is a new matrix with the result of the subtraction
In the third input, the user enters two x matrices with the values and and requests to perform a multiplication. MUL The resulting output is a new matrix with the result of the multiplication
At the end, the user presses the string "END" to terminate the program.
Notes on format and assumptions
A proper port can be placed! And that there are no spaces in the input anywhere only a new line at the end of a line In the case of a binary operation, but the matrices contain values that differ from ERR must be printed. But to continue with the program. Beyond that, it can be assumed that the input is correct
Nothing can be assumed about the size of the matrix except that it is square. The maximum string length in a line captured from the user is up to characters.
It can be assumed that complex, whole and rational numbers are not mixed
In rational numbers, only one digit should be displayed after the period
Coefficients of complex numbers are only integers. You can use the exercise in the complex library
file names.
Exqlc
Question :
In this question we will expand the question to a calculation using two programs
The input and output format will be the same as that of question but this time there will be two programs, one will read the input in the format of question and write it to the shared memory. The shared memory size is and a second program the client will read the data and calculate the operations and print them to the screen.
Requirements:
The program should create shared memory to store the matrices. The shared memory can be implemented using the functions shmdtshmet', 'shmat or any other way The server process should create the matrices in the shared memory read from the user.
in the format you determine for yourself The server process should write the data to the shared memory in a synchronized manner and in any method
you choose use semaphores or mutex locks for synchronization. The program needs to handle several matrices in the shared memory. and variable size. It can be assumed
which are squares.
The server will exit and delete the shared memory when the user presses END, until then it will remain in an infinite loop that calls the user.
Hints:
Use structures to represent the matrices and their metadata, including the degree
and the coefficients. In class we saw a data structure of countries did something similar
Use semaphores or mutex locks to synchronize memory access.
Can also be used in other ways. But remember processes are not threads
Use appropriate synchronization mechanisms to avoid raceconditions
file names.
Exqac
Exqbc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started