MATH178Discrete Mathematics Lab2 Due on Wednesday March 29th by 9:00 am Write a
ID: 3806480 • Letter: M
Question
MATH178Discrete Mathematics Lab2 Due on Wednesday March 29th by 9:00 am Write a program that performs zero-one matrix operations, including the join, the meet, and the Boolean product. Your matrices should be of type bool and use bitwise AND (&) and bitwise OR (I). (Note: C++ has compound assignment operator l and & Use your program to solve Exercises 26, 27, 28, and 29 from section 2.6 of the textbook. Upload the .cpp file along with your captured output or output to a file as a .zip fileExplanation / Answer
Q1 is solved for you
#include <iostream>
#include <iomanip>
using namespace std;
void MatrixOperation(int x[2][2]);
void MatrixPrinter(int x[2][2]);
void Meet(int A[2][2], int B[2][2]);
void Join(int A[2][2], int B[2][2]);
void ExclusiveOr(int A[2][2], int B[2][2]);
int main()
{
int Matrix_A[2][2] = {{0}};
int Matrix_B[2][2] = {{0}};
MatrixOperation(Matrix_A);
MatrixOperation(Matrix_B);
Meet(Matrix_A, Matrix_B);
return 0;
}
void Meet(int A[2][2], int B[2][2])
{
int C[2][2] = {{0}};
for (int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
C[i][j] = A[i][j] && B[i][j];
}
cout << "A ^ B" << endl;
MatrixPrinter(C);
}
void Join(int A[2][2], int B[2][2])
{
int C[2][2] = {{0}};
for (int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
C[i][j] = A[i][j] || B[i][j];
}
cout << "A v B" << endl;
MatrixPrinter(C);
}
void ExclusiveOr(int A[2][2], int B[2][2])
{
int C[2][2] = {{0}};
for (int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
C[i][j] = A[i][j] ^ B[i][j];
}
cout << "A ^ B" << endl;
MatrixPrinter(C);
}
void MatrixOperation(int x[2][2])
{
int C[2][2] = {{0}};
int NumPairs;
int k;
int j;
cout <<"Enter the number of ordered pairs? ";
cin >> NumPairs;
cout << endl;
for(int i = 0; i < NumPairs; i++)
{
cout << "Enter first element of ordered pair " << i + 1 << ": ";
cin >> k;
cout << "Enter second element of ordered pair " << i + 1 << ": ";
cin >> j;
cout << endl;
C[k-1][j-1] = 1;
}
MatrixPrinter(C);
}
void MatrixPrinter(int x[2][2])
{
cout << " 1 2 " << endl;
cout << "1" << setw(2) << x[0][0] << setw(2) << x[0][1] << endl;
cout << "2" << setw(2) << x[1][0] << setw(2) << x[1][1] << endl;
cout << endl;
}
Rest of the problems should be almost of the similar type. Please do it youself and let us know in case of any problems.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.