1. Write a C++ program to input from the command line two positive integers p and q between 1 and 10 inclusive. Generate two fixed matrices A and B with elements of type int. You can choose your own rule to fill in the matrix elements as long as no element of A or B is zero. A should be a p by q matrix and B should be a q by p matrix. Calculate the matrix product AB. Print out all three matrices A, B, AB to standard output. You need to design a class and include the dimension sizes (number of rows and columns) as member variables and make the storage for matrix elements dynamically allocated. Use pthread to create two threads to calculate the product so that each thread performs part of the task. Include a makefile to compile your program. Explain in a document your rules to fill in the matrix elements and whether your program has any race conditions. If yes, what did you do to prevent those race conditions.

2. Write a bash script to call your C++ program in problem 1 with three pairs of different matrix dimensions.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#ifndef MATRIX_H
#define MATRIX_H

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <pthread.h>

using namespace std;

class matrix {
    matrix(int p = 1, int q = 1);
    matrix(const matrix& orig);
    virtual ~matrix();
    friend ostream &operator<<(ostream &stream, const matrix & o);
    matrix operator*(const matrix & o);
// void *runner(void * param);
    int row; //number of row
    int col; // number of col
    int ** m;
$60.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Linux Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats