Answered step by step
Verified Expert Solution
Link Copied!

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 1
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 (2,2:1,2,3,4) Kotex
(2,2:1,2,3,4) represents a matrix in a compact form and includes the following elements:
-(2,2) matrix size:
a. The first number (2) indicates the number of rows in the matrix.
b. The second number (2) indicates the number of columns in the matrix.
- : separates the size of the matrix from its values.
-1,2,3,4 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 1 and 2, and the second row contains the
The values 3 and 4.
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.
(2,2:1,2,3,4)
(2,2:5,6,7,8)
ADD
(2,2:6,8,10,12)
(2,2:9,8,7,6)
(2,2:1,2,3,4)
SUB
(2,2:8,6,4,2)
(2,2:1,2,3,4)
(2,2:5,6,7,8)
MUL
(2,2:19,22,43,50)
END
explanation:
In the first input, the user enters two 2x2 matrices with the values (2,21,2,3,4)
-(2,2:5,6,7,8), and asks to add (ADD) the resulting output is a new matrix
(2,2:6,8,10,12)2 with the values x2 in size In the second input, the user again enters two 2x2 matrices with the values (2,2:9,8,7,6)-
(2,21,2,3,4), 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 2x2 matrices with the values (2,21,2,3,4 and 1-(2,25,6,7,8), 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 110. 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 128 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.
Ex3ql.c .1
Question 2:
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 1, but this time there will be two programs, one will read the input (in the format of question (1) and write it to the shared memory. The shared memory size is --2048 and a second program (the client) will read the data and calculate the operations and print them to the screen.
Requirements:
1. 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 2. 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
3 you choose - use semaphores or mutex locks for synchronization. 4. The program needs to handle several matrices in the shared memory. and variable size. It can be assumed
which are squares.
5. 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:
1. 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))
2. Use semaphores or mutex locks to synchronize memory access.
Can also be used in other ways. But remember - processes are not threads
3. Use appropriate synchronization mechanisms to avoid race-conditions
file names.
Ex3q2a.c .1
Ex3q2b.c .2

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions