SlideShare a Scribd company logo
1 of 30
Download to read offline
import java.util.Random;
//ASSIGNMENT #2: MATRIX ARITHMETIC
//Class Matrix. File: Matrix.java
public class Matrix {
public static final int MAX = 20;
//Attributes
private int size;
private int[][] table;
/**
* Default constructor
* Initializes the table with size MAX
*/
public Matrix() {
this.table = new int[MAX][MAX];
}
/**
* Parameterized constructor
* Initializes the table with size s
*/
public Matrix(int s) {
this.size = s;
this.table = new int[this.size][this.size];
}
/**
* Returns the size of the matrix
* @return
*/
public int getSize() {
return this.size;
}
/**
* The the number at position (r, c)
* @param r
* @param c
* @return
*/
public int getElement(int r, int c) {
return this.table[r][c];
}
/**
* Set a number at position (r, c)
* @param r
* @param c
* @param value
*/
public void setElement(int r, int c, int value) {
this.table[r][c] = value;
}
/**
* Initializes the matrix with random numbers
* @param low
* @param up
*/
public void init(int low, int up) {
Random rand = new Random();
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
setElement(r, c, rand.nextInt(up) + low);
}
}
}
/**
* Prints the matrix
*/
public void print() {
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
System.out.printf(" %2s", getElement(r, c));
}
System.out.printf(" ");
}
}
/**
* Adds this matrix with Matrix a
* @param a
* @return
*/
public Matrix add(Matrix a) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
int value = this.getElement(r, c) + a.getElement(r, c);
result.setElement(r, c, value);
}
}
return result;
}
/**
* Subtracts this matrix with Matrix a
* @param a
* @return
*/
public Matrix subtract(Matrix a) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
int value = this.getElement(r, c) - a.getElement(r, c);
result.setElement(r, c, value);
}
}
return result;
}
/**
* Multiplies this matrix with Matrix a
* @param a
* @return
*/
public Matrix multiply(Matrix a) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
int value = 0;
for (int k = 0 ; k < this.size ; k++) {
value += this.getElement(r, k) * a.getElement(k, c);
}
result.setElement(r, c, value);
}
}
return result;
}
/**
* Multiplies this matrix with a constant whatConst
* @param a
* @return
*/
public Matrix multiplyConst(int whatConst) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
result.setElement(r, c, getElement(r, c) * whatConst);
}
}
return result;
}
/**
* Transposes this matrix
* @param a
* @return
*/
public Matrix transpose() {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
result.setElement(r, c, this.getElement(c, r));
}
}
return result;
}
/**
*
* @param a
* @return
*/
public int trace() {
int trace = 0;
for (int d = 0 ; d < this.size ; d++) {
trace += this.getElement(d, d);
}
return trace;
}
/**
* Checks if this Matrix is equal to Matrix a
* @param a
* @return
*/
public boolean equals(Matrix a) {
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
if(this.getElement(r, c) != a.getElement(r, c))
return false;
}
}
return true;
}
/**
* Copies Matrix a to this matrix
* @param a
*/
public void copy(Matrix a) {
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
this.setElement(r, c, a.getElement(r, c));
}
}
}
/**
* Returns a copy of this matrix
* @return
*/
public Matrix getCopy() {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
result.setElement(r, c, this.getElement(r, c));
}
}
return result;
}
}// close class Matrix
import java.util.InputMismatchException;
//ASSIGNMENT #2: MATRIX ARITHMETIC
//Client for class Matrix. File: MatrixClient.java
import java.util.Scanner;
public class MatrixClient {
public static final int MAX = 20;
public static final int LOW = 1;
public static final int UP = 10;
/**
* Clears the keyboard buffer
*
* @param input
*/
public static void clearBuf(Scanner input) {
input.nextLine();
}
/**
* Display the menu
*/
public static void displayMenu() {
System.out.println("Your options are: ");
System.out.println("-----------------");
System.out.println("1) Add 2 matrices");
System.out.println("2) Subtract 2 matrices");
System.out.println("3) Multiply 2 matrices");
System.out.println("4) Multiply matrix by a constant");
System.out.println("5) Transpose matrix");
System.out.println("6) Matrix trace");
System.out.println("7) Make a copy");
System.out.println("8) Test for equality");
System.out.println("0) EXIT");
System.out.print("Please enter your option: ");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice = 0; // operation to be executed from menu
int numCommands = 0; // display counter
int size = 0; // for subarray processing
int value; // multiply matrix by this constant
// Get size of the matrix
while (true) {
System.out.println("Enter the size of the square matrix: ");
try {
size = input.nextInt();
} catch (InputMismatchException ime) {
System.out.println("INPUT ERROR!!! Invalid input. Please enter a positive
integer");
}
if ((1 > size) || (size > MAX))
System.out.println("INPUT ERROR!!! Invalid size. Positive and <= " + MAX);
else
break;
}
// Create matrices
Matrix first = new Matrix(size);
Matrix second = new Matrix(size);
Matrix result = new Matrix(size);
// Generate Matrix
first.init(LOW, UP);
second.init(LOW, UP);
// Start testing
while (true) {
displayMenu();
choice = input.nextInt();
numCommands += 1;
switch (choice) {
case 0: // Exit
// Close scanner
input.close();
System.out.println("Testing completed.");
System.exit(0);
break;
case 1: // Matrix Addition
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
System.out.println("The resulting matrix is:");
result = first.add(second);
result.print();
break;
case 2: // Matrix Subtraction
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
System.out.println("The resulting matrix is:");
result = first.subtract(second);
result.print();
break;
case 3: // Matrix Multiplication
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
System.out.println("The resulting matrix is:");
result = first.multiply(second);
result.print();
break;
case 4: // Matrix Multiplication by a constant
System.out.print("Enter the multiplication constant: ");
value = input.nextInt();
System.out.println("The original matrix is:");
first.print();
System.out.println("The resulting matrix is:");
result = first.multiplyConst(value);
result.print();
break;
case 5: // Transpose a matrix
System.out.println("The original matrix is:");
first.print();
System.out.println("The resulting matrix is:");
result = first.transpose();
result.print();
break;
case 6: // Trace of a matrix
System.out.println("The original matrix is:");
first.print();
System.out.println("The trace for this matrix is: " + first.trace());
break;
case 7: // Make a copy
System.out.println("The original matrix is:");
first.print();
System.out.println("The copy of this matrix is:");
result = first.getCopy();
result.print();
System.out.println("Testing for equality. Should be equal!!");
if(first.equals(result))
System.out.println("The matrices are equal!!");
else
System.out.println("The matrices are NOT equal!!");
break;
case 8: // Test for equality
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
if(first.equals(second))
System.out.println("The matrices are equal!!");
else
System.out.println("The matrices are NOT equal!!");
break;
default:
System.out.println("Inavlid choice. Please try again!!!");
}
System.out.println("Command number " + numCommands + " completed.");
// Clear keyboard buffer
clearBuf(input);
System.out.println();
}
}
}
SAMPLE OUTPUT:
Enter the size of the square matrix:
2
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 1
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The resulting matrix is:
14 6
10 7
Command number 1 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 2
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The resulting matrix is:
2 -4
6 -5
Command number 2 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 3
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The resulting matrix is:
50 46
50 46
Command number 3 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 4
Enter the multiplication constant: 10
The original matrix is:
8 1
8 1
The resulting matrix is:
80 10
80 10
Command number 4 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 5
The original matrix is:
8 1
8 1
The resulting matrix is:
8 8
1 1
Command number 5 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 6
The original matrix is:
8 1
8 1
The trace for this matrix is: 9
Command number 6 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 7
The original matrix is:
8 1
8 1
The copy of this matrix is:
8 1
8 1
Testing for equality. Should be equal!!
The matrices are equal!!
Command number 7 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 8
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The matrices are NOT equal!!
Command number 8 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 0
Testing completed.
Solution
import java.util.Random;
//ASSIGNMENT #2: MATRIX ARITHMETIC
//Class Matrix. File: Matrix.java
public class Matrix {
public static final int MAX = 20;
//Attributes
private int size;
private int[][] table;
/**
* Default constructor
* Initializes the table with size MAX
*/
public Matrix() {
this.table = new int[MAX][MAX];
}
/**
* Parameterized constructor
* Initializes the table with size s
*/
public Matrix(int s) {
this.size = s;
this.table = new int[this.size][this.size];
}
/**
* Returns the size of the matrix
* @return
*/
public int getSize() {
return this.size;
}
/**
* The the number at position (r, c)
* @param r
* @param c
* @return
*/
public int getElement(int r, int c) {
return this.table[r][c];
}
/**
* Set a number at position (r, c)
* @param r
* @param c
* @param value
*/
public void setElement(int r, int c, int value) {
this.table[r][c] = value;
}
/**
* Initializes the matrix with random numbers
* @param low
* @param up
*/
public void init(int low, int up) {
Random rand = new Random();
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
setElement(r, c, rand.nextInt(up) + low);
}
}
}
/**
* Prints the matrix
*/
public void print() {
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
System.out.printf(" %2s", getElement(r, c));
}
System.out.printf(" ");
}
}
/**
* Adds this matrix with Matrix a
* @param a
* @return
*/
public Matrix add(Matrix a) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
int value = this.getElement(r, c) + a.getElement(r, c);
result.setElement(r, c, value);
}
}
return result;
}
/**
* Subtracts this matrix with Matrix a
* @param a
* @return
*/
public Matrix subtract(Matrix a) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
int value = this.getElement(r, c) - a.getElement(r, c);
result.setElement(r, c, value);
}
}
return result;
}
/**
* Multiplies this matrix with Matrix a
* @param a
* @return
*/
public Matrix multiply(Matrix a) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
int value = 0;
for (int k = 0 ; k < this.size ; k++) {
value += this.getElement(r, k) * a.getElement(k, c);
}
result.setElement(r, c, value);
}
}
return result;
}
/**
* Multiplies this matrix with a constant whatConst
* @param a
* @return
*/
public Matrix multiplyConst(int whatConst) {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
result.setElement(r, c, getElement(r, c) * whatConst);
}
}
return result;
}
/**
* Transposes this matrix
* @param a
* @return
*/
public Matrix transpose() {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
result.setElement(r, c, this.getElement(c, r));
}
}
return result;
}
/**
*
* @param a
* @return
*/
public int trace() {
int trace = 0;
for (int d = 0 ; d < this.size ; d++) {
trace += this.getElement(d, d);
}
return trace;
}
/**
* Checks if this Matrix is equal to Matrix a
* @param a
* @return
*/
public boolean equals(Matrix a) {
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
if(this.getElement(r, c) != a.getElement(r, c))
return false;
}
}
return true;
}
/**
* Copies Matrix a to this matrix
* @param a
*/
public void copy(Matrix a) {
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
this.setElement(r, c, a.getElement(r, c));
}
}
}
/**
* Returns a copy of this matrix
* @return
*/
public Matrix getCopy() {
Matrix result = new Matrix(this.size);
for (int r = 0 ; r < this.size ; r++) {
for (int c = 0 ; c < this.size ; c++) {
result.setElement(r, c, this.getElement(r, c));
}
}
return result;
}
}// close class Matrix
import java.util.InputMismatchException;
//ASSIGNMENT #2: MATRIX ARITHMETIC
//Client for class Matrix. File: MatrixClient.java
import java.util.Scanner;
public class MatrixClient {
public static final int MAX = 20;
public static final int LOW = 1;
public static final int UP = 10;
/**
* Clears the keyboard buffer
*
* @param input
*/
public static void clearBuf(Scanner input) {
input.nextLine();
}
/**
* Display the menu
*/
public static void displayMenu() {
System.out.println("Your options are: ");
System.out.println("-----------------");
System.out.println("1) Add 2 matrices");
System.out.println("2) Subtract 2 matrices");
System.out.println("3) Multiply 2 matrices");
System.out.println("4) Multiply matrix by a constant");
System.out.println("5) Transpose matrix");
System.out.println("6) Matrix trace");
System.out.println("7) Make a copy");
System.out.println("8) Test for equality");
System.out.println("0) EXIT");
System.out.print("Please enter your option: ");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice = 0; // operation to be executed from menu
int numCommands = 0; // display counter
int size = 0; // for subarray processing
int value; // multiply matrix by this constant
// Get size of the matrix
while (true) {
System.out.println("Enter the size of the square matrix: ");
try {
size = input.nextInt();
} catch (InputMismatchException ime) {
System.out.println("INPUT ERROR!!! Invalid input. Please enter a positive
integer");
}
if ((1 > size) || (size > MAX))
System.out.println("INPUT ERROR!!! Invalid size. Positive and <= " + MAX);
else
break;
}
// Create matrices
Matrix first = new Matrix(size);
Matrix second = new Matrix(size);
Matrix result = new Matrix(size);
// Generate Matrix
first.init(LOW, UP);
second.init(LOW, UP);
// Start testing
while (true) {
displayMenu();
choice = input.nextInt();
numCommands += 1;
switch (choice) {
case 0: // Exit
// Close scanner
input.close();
System.out.println("Testing completed.");
System.exit(0);
break;
case 1: // Matrix Addition
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
System.out.println("The resulting matrix is:");
result = first.add(second);
result.print();
break;
case 2: // Matrix Subtraction
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
System.out.println("The resulting matrix is:");
result = first.subtract(second);
result.print();
break;
case 3: // Matrix Multiplication
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
System.out.println("The resulting matrix is:");
result = first.multiply(second);
result.print();
break;
case 4: // Matrix Multiplication by a constant
System.out.print("Enter the multiplication constant: ");
value = input.nextInt();
System.out.println("The original matrix is:");
first.print();
System.out.println("The resulting matrix is:");
result = first.multiplyConst(value);
result.print();
break;
case 5: // Transpose a matrix
System.out.println("The original matrix is:");
first.print();
System.out.println("The resulting matrix is:");
result = first.transpose();
result.print();
break;
case 6: // Trace of a matrix
System.out.println("The original matrix is:");
first.print();
System.out.println("The trace for this matrix is: " + first.trace());
break;
case 7: // Make a copy
System.out.println("The original matrix is:");
first.print();
System.out.println("The copy of this matrix is:");
result = first.getCopy();
result.print();
System.out.println("Testing for equality. Should be equal!!");
if(first.equals(result))
System.out.println("The matrices are equal!!");
else
System.out.println("The matrices are NOT equal!!");
break;
case 8: // Test for equality
System.out.println("First matrix is:");
first.print();
System.out.println("Second matrix is:");
second.print();
if(first.equals(second))
System.out.println("The matrices are equal!!");
else
System.out.println("The matrices are NOT equal!!");
break;
default:
System.out.println("Inavlid choice. Please try again!!!");
}
System.out.println("Command number " + numCommands + " completed.");
// Clear keyboard buffer
clearBuf(input);
System.out.println();
}
}
}
SAMPLE OUTPUT:
Enter the size of the square matrix:
2
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 1
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The resulting matrix is:
14 6
10 7
Command number 1 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 2
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The resulting matrix is:
2 -4
6 -5
Command number 2 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 3
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The resulting matrix is:
50 46
50 46
Command number 3 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 4
Enter the multiplication constant: 10
The original matrix is:
8 1
8 1
The resulting matrix is:
80 10
80 10
Command number 4 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 5
The original matrix is:
8 1
8 1
The resulting matrix is:
8 8
1 1
Command number 5 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 6
The original matrix is:
8 1
8 1
The trace for this matrix is: 9
Command number 6 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 7
The original matrix is:
8 1
8 1
The copy of this matrix is:
8 1
8 1
Testing for equality. Should be equal!!
The matrices are equal!!
Command number 7 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 8
First matrix is:
8 1
8 1
Second matrix is:
6 5
2 6
The matrices are NOT equal!!
Command number 8 completed.
Your options are:
-----------------
1) Add 2 matrices
2) Subtract 2 matrices
3) Multiply 2 matrices
4) Multiply matrix by a constant
5) Transpose matrix
6) Matrix trace
7) Make a copy
8) Test for equality
0) EXIT
Please enter your option: 0
Testing completed.

More Related Content

Similar to import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf

Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)Arun Umrao
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfaniyathikitchen
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdfg++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdfarakalamkah11
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfANJALIENTERPRISES1
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfmanjan6
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfanurag1231
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdffeelinggifts
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfarchgeetsenterprises
 
Import java
Import javaImport java
Import javaheni2121
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfnageswara1958
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 

Similar to import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf (20)

Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdf
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdfg++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
 
2 d matrices
2 d matrices2 d matrices
2 d matrices
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdf
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdf
 
Import java
Import javaImport java
Import java
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdf
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 

More from aquacareser

1) MODERN TIMES is a very well prepared movie that describes the mis.pdf
1) MODERN TIMES is a very well prepared movie that describes the mis.pdf1) MODERN TIMES is a very well prepared movie that describes the mis.pdf
1) MODERN TIMES is a very well prepared movie that describes the mis.pdfaquacareser
 
1. Identify five differences between DNA replication and gene transc.pdf
1. Identify five differences between DNA replication and gene transc.pdf1. Identify five differences between DNA replication and gene transc.pdf
1. Identify five differences between DNA replication and gene transc.pdfaquacareser
 
1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf
1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf
1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdfaquacareser
 
this is my code to count the frequency of words in a text file#.pdf
 this is my code to count the frequency of words in a text file#.pdf this is my code to count the frequency of words in a text file#.pdf
this is my code to count the frequency of words in a text file#.pdfaquacareser
 
The ice allows the refluxed materials to crystall.pdf
                     The ice allows the refluxed materials to crystall.pdf                     The ice allows the refluxed materials to crystall.pdf
The ice allows the refluxed materials to crystall.pdfaquacareser
 
1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf
1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf
1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdfaquacareser
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquacareser
 
Web sever environmentA Web server is a program that uses HTTP (Hy.pdf
Web sever environmentA Web server is a program that uses HTTP (Hy.pdfWeb sever environmentA Web server is a program that uses HTTP (Hy.pdf
Web sever environmentA Web server is a program that uses HTTP (Hy.pdfaquacareser
 
We ca use HashSet data structure to remove duplicats from an array i.pdf
We ca use HashSet data structure to remove duplicats from an array i.pdfWe ca use HashSet data structure to remove duplicats from an array i.pdf
We ca use HashSet data structure to remove duplicats from an array i.pdfaquacareser
 
this eample is of t-test for comparing two meanshere mean1 = m.pdf
this eample is of t-test for comparing two meanshere mean1 = m.pdfthis eample is of t-test for comparing two meanshere mean1 = m.pdf
this eample is of t-test for comparing two meanshere mean1 = m.pdfaquacareser
 
The middle ear bones in mammals are derived from bones in the dentar.pdf
The middle ear bones in mammals are derived from bones in the dentar.pdfThe middle ear bones in mammals are derived from bones in the dentar.pdf
The middle ear bones in mammals are derived from bones in the dentar.pdfaquacareser
 
There is an old saying “Do not put all eggs in one basket”WhyBe.pdf
There is an old saying “Do not put all eggs in one basket”WhyBe.pdfThere is an old saying “Do not put all eggs in one basket”WhyBe.pdf
There is an old saying “Do not put all eggs in one basket”WhyBe.pdfaquacareser
 
The ER Model is focussed to be a description of real-world entities..pdf
The ER Model is focussed to be a description of real-world entities..pdfThe ER Model is focussed to be a description of real-world entities..pdf
The ER Model is focussed to be a description of real-world entities..pdfaquacareser
 
Please find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdf
Please find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdfPlease find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdf
Please find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdfaquacareser
 
Question 1 answer is A Global trade allows wealthy countries to use .pdf
Question 1 answer is A Global trade allows wealthy countries to use .pdfQuestion 1 answer is A Global trade allows wealthy countries to use .pdf
Question 1 answer is A Global trade allows wealthy countries to use .pdfaquacareser
 
Precipitation hardening, or age hardening, provides one of the most .pdf
Precipitation hardening, or age hardening, provides one of the most .pdfPrecipitation hardening, or age hardening, provides one of the most .pdf
Precipitation hardening, or age hardening, provides one of the most .pdfaquacareser
 
Protists are beneficial to the ecosystem in generating oxygen as the.pdf
Protists are beneficial to the ecosystem in generating oxygen as the.pdfProtists are beneficial to the ecosystem in generating oxygen as the.pdf
Protists are beneficial to the ecosystem in generating oxygen as the.pdfaquacareser
 
Now a normal O2 molecule has 12 electrons in the valence shell so, O.pdf
Now a normal O2 molecule has 12 electrons in the valence shell so, O.pdfNow a normal O2 molecule has 12 electrons in the valence shell so, O.pdf
Now a normal O2 molecule has 12 electrons in the valence shell so, O.pdfaquacareser
 
P1.javaimport java.util.Scanner;keyboard inputting package pub.pdf
P1.javaimport java.util.Scanner;keyboard inputting package pub.pdfP1.javaimport java.util.Scanner;keyboard inputting package pub.pdf
P1.javaimport java.util.Scanner;keyboard inputting package pub.pdfaquacareser
 
operating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfoperating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfaquacareser
 

More from aquacareser (20)

1) MODERN TIMES is a very well prepared movie that describes the mis.pdf
1) MODERN TIMES is a very well prepared movie that describes the mis.pdf1) MODERN TIMES is a very well prepared movie that describes the mis.pdf
1) MODERN TIMES is a very well prepared movie that describes the mis.pdf
 
1. Identify five differences between DNA replication and gene transc.pdf
1. Identify five differences between DNA replication and gene transc.pdf1. Identify five differences between DNA replication and gene transc.pdf
1. Identify five differences between DNA replication and gene transc.pdf
 
1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf
1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf
1.1Yearcash flowpresent value of cash inflow = cash flow(1+r).pdf
 
this is my code to count the frequency of words in a text file#.pdf
 this is my code to count the frequency of words in a text file#.pdf this is my code to count the frequency of words in a text file#.pdf
this is my code to count the frequency of words in a text file#.pdf
 
The ice allows the refluxed materials to crystall.pdf
                     The ice allows the refluxed materials to crystall.pdf                     The ice allows the refluxed materials to crystall.pdf
The ice allows the refluxed materials to crystall.pdf
 
1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf
1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf
1. b2. c (bed bug)3. d (caterpillars)4. c (lyme disease)5. e.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
Web sever environmentA Web server is a program that uses HTTP (Hy.pdf
Web sever environmentA Web server is a program that uses HTTP (Hy.pdfWeb sever environmentA Web server is a program that uses HTTP (Hy.pdf
Web sever environmentA Web server is a program that uses HTTP (Hy.pdf
 
We ca use HashSet data structure to remove duplicats from an array i.pdf
We ca use HashSet data structure to remove duplicats from an array i.pdfWe ca use HashSet data structure to remove duplicats from an array i.pdf
We ca use HashSet data structure to remove duplicats from an array i.pdf
 
this eample is of t-test for comparing two meanshere mean1 = m.pdf
this eample is of t-test for comparing two meanshere mean1 = m.pdfthis eample is of t-test for comparing two meanshere mean1 = m.pdf
this eample is of t-test for comparing two meanshere mean1 = m.pdf
 
The middle ear bones in mammals are derived from bones in the dentar.pdf
The middle ear bones in mammals are derived from bones in the dentar.pdfThe middle ear bones in mammals are derived from bones in the dentar.pdf
The middle ear bones in mammals are derived from bones in the dentar.pdf
 
There is an old saying “Do not put all eggs in one basket”WhyBe.pdf
There is an old saying “Do not put all eggs in one basket”WhyBe.pdfThere is an old saying “Do not put all eggs in one basket”WhyBe.pdf
There is an old saying “Do not put all eggs in one basket”WhyBe.pdf
 
The ER Model is focussed to be a description of real-world entities..pdf
The ER Model is focussed to be a description of real-world entities..pdfThe ER Model is focussed to be a description of real-world entities..pdf
The ER Model is focussed to be a description of real-world entities..pdf
 
Please find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdf
Please find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdfPlease find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdf
Please find the answers belowAnswer 16 Option A (IEP). (IEP or i.pdf
 
Question 1 answer is A Global trade allows wealthy countries to use .pdf
Question 1 answer is A Global trade allows wealthy countries to use .pdfQuestion 1 answer is A Global trade allows wealthy countries to use .pdf
Question 1 answer is A Global trade allows wealthy countries to use .pdf
 
Precipitation hardening, or age hardening, provides one of the most .pdf
Precipitation hardening, or age hardening, provides one of the most .pdfPrecipitation hardening, or age hardening, provides one of the most .pdf
Precipitation hardening, or age hardening, provides one of the most .pdf
 
Protists are beneficial to the ecosystem in generating oxygen as the.pdf
Protists are beneficial to the ecosystem in generating oxygen as the.pdfProtists are beneficial to the ecosystem in generating oxygen as the.pdf
Protists are beneficial to the ecosystem in generating oxygen as the.pdf
 
Now a normal O2 molecule has 12 electrons in the valence shell so, O.pdf
Now a normal O2 molecule has 12 electrons in the valence shell so, O.pdfNow a normal O2 molecule has 12 electrons in the valence shell so, O.pdf
Now a normal O2 molecule has 12 electrons in the valence shell so, O.pdf
 
P1.javaimport java.util.Scanner;keyboard inputting package pub.pdf
P1.javaimport java.util.Scanner;keyboard inputting package pub.pdfP1.javaimport java.util.Scanner;keyboard inputting package pub.pdf
P1.javaimport java.util.Scanner;keyboard inputting package pub.pdf
 
operating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfoperating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf

  • 1. import java.util.Random; //ASSIGNMENT #2: MATRIX ARITHMETIC //Class Matrix. File: Matrix.java public class Matrix { public static final int MAX = 20; //Attributes private int size; private int[][] table; /** * Default constructor * Initializes the table with size MAX */ public Matrix() { this.table = new int[MAX][MAX]; } /** * Parameterized constructor * Initializes the table with size s */ public Matrix(int s) { this.size = s; this.table = new int[this.size][this.size]; } /** * Returns the size of the matrix * @return */ public int getSize() { return this.size; } /** * The the number at position (r, c) * @param r * @param c
  • 2. * @return */ public int getElement(int r, int c) { return this.table[r][c]; } /** * Set a number at position (r, c) * @param r * @param c * @param value */ public void setElement(int r, int c, int value) { this.table[r][c] = value; } /** * Initializes the matrix with random numbers * @param low * @param up */ public void init(int low, int up) { Random rand = new Random(); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { setElement(r, c, rand.nextInt(up) + low); } } } /** * Prints the matrix */ public void print() { for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { System.out.printf(" %2s", getElement(r, c)); }
  • 3. System.out.printf(" "); } } /** * Adds this matrix with Matrix a * @param a * @return */ public Matrix add(Matrix a) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { int value = this.getElement(r, c) + a.getElement(r, c); result.setElement(r, c, value); } } return result; } /** * Subtracts this matrix with Matrix a * @param a * @return */ public Matrix subtract(Matrix a) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { int value = this.getElement(r, c) - a.getElement(r, c); result.setElement(r, c, value); } } return result; } /**
  • 4. * Multiplies this matrix with Matrix a * @param a * @return */ public Matrix multiply(Matrix a) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { int value = 0; for (int k = 0 ; k < this.size ; k++) { value += this.getElement(r, k) * a.getElement(k, c); } result.setElement(r, c, value); } } return result; } /** * Multiplies this matrix with a constant whatConst * @param a * @return */ public Matrix multiplyConst(int whatConst) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { result.setElement(r, c, getElement(r, c) * whatConst); } } return result; } /** * Transposes this matrix * @param a * @return */
  • 5. public Matrix transpose() { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { result.setElement(r, c, this.getElement(c, r)); } } return result; } /** * * @param a * @return */ public int trace() { int trace = 0; for (int d = 0 ; d < this.size ; d++) { trace += this.getElement(d, d); } return trace; } /** * Checks if this Matrix is equal to Matrix a * @param a * @return */ public boolean equals(Matrix a) { for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { if(this.getElement(r, c) != a.getElement(r, c)) return false; } } return true; } /**
  • 6. * Copies Matrix a to this matrix * @param a */ public void copy(Matrix a) { for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { this.setElement(r, c, a.getElement(r, c)); } } } /** * Returns a copy of this matrix * @return */ public Matrix getCopy() { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { result.setElement(r, c, this.getElement(r, c)); } } return result; } }// close class Matrix import java.util.InputMismatchException; //ASSIGNMENT #2: MATRIX ARITHMETIC //Client for class Matrix. File: MatrixClient.java import java.util.Scanner; public class MatrixClient { public static final int MAX = 20; public static final int LOW = 1; public static final int UP = 10; /** * Clears the keyboard buffer * * @param input
  • 7. */ public static void clearBuf(Scanner input) { input.nextLine(); } /** * Display the menu */ public static void displayMenu() { System.out.println("Your options are: "); System.out.println("-----------------"); System.out.println("1) Add 2 matrices"); System.out.println("2) Subtract 2 matrices"); System.out.println("3) Multiply 2 matrices"); System.out.println("4) Multiply matrix by a constant"); System.out.println("5) Transpose matrix"); System.out.println("6) Matrix trace"); System.out.println("7) Make a copy"); System.out.println("8) Test for equality"); System.out.println("0) EXIT"); System.out.print("Please enter your option: "); } public static void main(String[] args) { Scanner input = new Scanner(System.in); int choice = 0; // operation to be executed from menu int numCommands = 0; // display counter int size = 0; // for subarray processing int value; // multiply matrix by this constant // Get size of the matrix while (true) { System.out.println("Enter the size of the square matrix: "); try { size = input.nextInt(); } catch (InputMismatchException ime) { System.out.println("INPUT ERROR!!! Invalid input. Please enter a positive integer"); }
  • 8. if ((1 > size) || (size > MAX)) System.out.println("INPUT ERROR!!! Invalid size. Positive and <= " + MAX); else break; } // Create matrices Matrix first = new Matrix(size); Matrix second = new Matrix(size); Matrix result = new Matrix(size); // Generate Matrix first.init(LOW, UP); second.init(LOW, UP); // Start testing while (true) { displayMenu(); choice = input.nextInt(); numCommands += 1; switch (choice) { case 0: // Exit // Close scanner input.close(); System.out.println("Testing completed."); System.exit(0); break; case 1: // Matrix Addition System.out.println("First matrix is:"); first.print(); System.out.println("Second matrix is:"); second.print(); System.out.println("The resulting matrix is:"); result = first.add(second); result.print(); break; case 2: // Matrix Subtraction System.out.println("First matrix is:");
  • 9. first.print(); System.out.println("Second matrix is:"); second.print(); System.out.println("The resulting matrix is:"); result = first.subtract(second); result.print(); break; case 3: // Matrix Multiplication System.out.println("First matrix is:"); first.print(); System.out.println("Second matrix is:"); second.print(); System.out.println("The resulting matrix is:"); result = first.multiply(second); result.print(); break; case 4: // Matrix Multiplication by a constant System.out.print("Enter the multiplication constant: "); value = input.nextInt(); System.out.println("The original matrix is:"); first.print(); System.out.println("The resulting matrix is:"); result = first.multiplyConst(value); result.print(); break; case 5: // Transpose a matrix System.out.println("The original matrix is:"); first.print(); System.out.println("The resulting matrix is:"); result = first.transpose(); result.print(); break; case 6: // Trace of a matrix System.out.println("The original matrix is:"); first.print(); System.out.println("The trace for this matrix is: " + first.trace());
  • 10. break; case 7: // Make a copy System.out.println("The original matrix is:"); first.print(); System.out.println("The copy of this matrix is:"); result = first.getCopy(); result.print(); System.out.println("Testing for equality. Should be equal!!"); if(first.equals(result)) System.out.println("The matrices are equal!!"); else System.out.println("The matrices are NOT equal!!"); break; case 8: // Test for equality System.out.println("First matrix is:"); first.print(); System.out.println("Second matrix is:"); second.print(); if(first.equals(second)) System.out.println("The matrices are equal!!"); else System.out.println("The matrices are NOT equal!!"); break; default: System.out.println("Inavlid choice. Please try again!!!"); } System.out.println("Command number " + numCommands + " completed."); // Clear keyboard buffer clearBuf(input); System.out.println(); } } } SAMPLE OUTPUT:
  • 11. Enter the size of the square matrix: 2 Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 1 First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The resulting matrix is: 14 6 10 7 Command number 1 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 2
  • 12. First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The resulting matrix is: 2 -4 6 -5 Command number 2 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 3 First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The resulting matrix is: 50 46 50 46 Command number 3 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices
  • 13. 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 4 Enter the multiplication constant: 10 The original matrix is: 8 1 8 1 The resulting matrix is: 80 10 80 10 Command number 4 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 5 The original matrix is: 8 1 8 1 The resulting matrix is: 8 8 1 1 Command number 5 completed. Your options are:
  • 14. ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 6 The original matrix is: 8 1 8 1 The trace for this matrix is: 9 Command number 6 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 7 The original matrix is: 8 1 8 1 The copy of this matrix is: 8 1 8 1 Testing for equality. Should be equal!! The matrices are equal!!
  • 15. Command number 7 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 8 First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The matrices are NOT equal!! Command number 8 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 0 Testing completed. Solution
  • 16. import java.util.Random; //ASSIGNMENT #2: MATRIX ARITHMETIC //Class Matrix. File: Matrix.java public class Matrix { public static final int MAX = 20; //Attributes private int size; private int[][] table; /** * Default constructor * Initializes the table with size MAX */ public Matrix() { this.table = new int[MAX][MAX]; } /** * Parameterized constructor * Initializes the table with size s */ public Matrix(int s) { this.size = s; this.table = new int[this.size][this.size]; } /** * Returns the size of the matrix * @return */ public int getSize() { return this.size; } /** * The the number at position (r, c) * @param r * @param c
  • 17. * @return */ public int getElement(int r, int c) { return this.table[r][c]; } /** * Set a number at position (r, c) * @param r * @param c * @param value */ public void setElement(int r, int c, int value) { this.table[r][c] = value; } /** * Initializes the matrix with random numbers * @param low * @param up */ public void init(int low, int up) { Random rand = new Random(); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { setElement(r, c, rand.nextInt(up) + low); } } } /** * Prints the matrix */ public void print() { for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { System.out.printf(" %2s", getElement(r, c)); }
  • 18. System.out.printf(" "); } } /** * Adds this matrix with Matrix a * @param a * @return */ public Matrix add(Matrix a) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { int value = this.getElement(r, c) + a.getElement(r, c); result.setElement(r, c, value); } } return result; } /** * Subtracts this matrix with Matrix a * @param a * @return */ public Matrix subtract(Matrix a) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { int value = this.getElement(r, c) - a.getElement(r, c); result.setElement(r, c, value); } } return result; } /**
  • 19. * Multiplies this matrix with Matrix a * @param a * @return */ public Matrix multiply(Matrix a) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { int value = 0; for (int k = 0 ; k < this.size ; k++) { value += this.getElement(r, k) * a.getElement(k, c); } result.setElement(r, c, value); } } return result; } /** * Multiplies this matrix with a constant whatConst * @param a * @return */ public Matrix multiplyConst(int whatConst) { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { result.setElement(r, c, getElement(r, c) * whatConst); } } return result; } /** * Transposes this matrix * @param a * @return */
  • 20. public Matrix transpose() { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { result.setElement(r, c, this.getElement(c, r)); } } return result; } /** * * @param a * @return */ public int trace() { int trace = 0; for (int d = 0 ; d < this.size ; d++) { trace += this.getElement(d, d); } return trace; } /** * Checks if this Matrix is equal to Matrix a * @param a * @return */ public boolean equals(Matrix a) { for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { if(this.getElement(r, c) != a.getElement(r, c)) return false; } } return true; } /**
  • 21. * Copies Matrix a to this matrix * @param a */ public void copy(Matrix a) { for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { this.setElement(r, c, a.getElement(r, c)); } } } /** * Returns a copy of this matrix * @return */ public Matrix getCopy() { Matrix result = new Matrix(this.size); for (int r = 0 ; r < this.size ; r++) { for (int c = 0 ; c < this.size ; c++) { result.setElement(r, c, this.getElement(r, c)); } } return result; } }// close class Matrix import java.util.InputMismatchException; //ASSIGNMENT #2: MATRIX ARITHMETIC //Client for class Matrix. File: MatrixClient.java import java.util.Scanner; public class MatrixClient { public static final int MAX = 20; public static final int LOW = 1; public static final int UP = 10; /** * Clears the keyboard buffer * * @param input
  • 22. */ public static void clearBuf(Scanner input) { input.nextLine(); } /** * Display the menu */ public static void displayMenu() { System.out.println("Your options are: "); System.out.println("-----------------"); System.out.println("1) Add 2 matrices"); System.out.println("2) Subtract 2 matrices"); System.out.println("3) Multiply 2 matrices"); System.out.println("4) Multiply matrix by a constant"); System.out.println("5) Transpose matrix"); System.out.println("6) Matrix trace"); System.out.println("7) Make a copy"); System.out.println("8) Test for equality"); System.out.println("0) EXIT"); System.out.print("Please enter your option: "); } public static void main(String[] args) { Scanner input = new Scanner(System.in); int choice = 0; // operation to be executed from menu int numCommands = 0; // display counter int size = 0; // for subarray processing int value; // multiply matrix by this constant // Get size of the matrix while (true) { System.out.println("Enter the size of the square matrix: "); try { size = input.nextInt(); } catch (InputMismatchException ime) { System.out.println("INPUT ERROR!!! Invalid input. Please enter a positive integer"); }
  • 23. if ((1 > size) || (size > MAX)) System.out.println("INPUT ERROR!!! Invalid size. Positive and <= " + MAX); else break; } // Create matrices Matrix first = new Matrix(size); Matrix second = new Matrix(size); Matrix result = new Matrix(size); // Generate Matrix first.init(LOW, UP); second.init(LOW, UP); // Start testing while (true) { displayMenu(); choice = input.nextInt(); numCommands += 1; switch (choice) { case 0: // Exit // Close scanner input.close(); System.out.println("Testing completed."); System.exit(0); break; case 1: // Matrix Addition System.out.println("First matrix is:"); first.print(); System.out.println("Second matrix is:"); second.print(); System.out.println("The resulting matrix is:"); result = first.add(second); result.print(); break; case 2: // Matrix Subtraction System.out.println("First matrix is:");
  • 24. first.print(); System.out.println("Second matrix is:"); second.print(); System.out.println("The resulting matrix is:"); result = first.subtract(second); result.print(); break; case 3: // Matrix Multiplication System.out.println("First matrix is:"); first.print(); System.out.println("Second matrix is:"); second.print(); System.out.println("The resulting matrix is:"); result = first.multiply(second); result.print(); break; case 4: // Matrix Multiplication by a constant System.out.print("Enter the multiplication constant: "); value = input.nextInt(); System.out.println("The original matrix is:"); first.print(); System.out.println("The resulting matrix is:"); result = first.multiplyConst(value); result.print(); break; case 5: // Transpose a matrix System.out.println("The original matrix is:"); first.print(); System.out.println("The resulting matrix is:"); result = first.transpose(); result.print(); break; case 6: // Trace of a matrix System.out.println("The original matrix is:"); first.print(); System.out.println("The trace for this matrix is: " + first.trace());
  • 25. break; case 7: // Make a copy System.out.println("The original matrix is:"); first.print(); System.out.println("The copy of this matrix is:"); result = first.getCopy(); result.print(); System.out.println("Testing for equality. Should be equal!!"); if(first.equals(result)) System.out.println("The matrices are equal!!"); else System.out.println("The matrices are NOT equal!!"); break; case 8: // Test for equality System.out.println("First matrix is:"); first.print(); System.out.println("Second matrix is:"); second.print(); if(first.equals(second)) System.out.println("The matrices are equal!!"); else System.out.println("The matrices are NOT equal!!"); break; default: System.out.println("Inavlid choice. Please try again!!!"); } System.out.println("Command number " + numCommands + " completed."); // Clear keyboard buffer clearBuf(input); System.out.println(); } } } SAMPLE OUTPUT:
  • 26. Enter the size of the square matrix: 2 Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 1 First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The resulting matrix is: 14 6 10 7 Command number 1 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 2
  • 27. First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The resulting matrix is: 2 -4 6 -5 Command number 2 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 3 First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The resulting matrix is: 50 46 50 46 Command number 3 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices
  • 28. 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 4 Enter the multiplication constant: 10 The original matrix is: 8 1 8 1 The resulting matrix is: 80 10 80 10 Command number 4 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 5 The original matrix is: 8 1 8 1 The resulting matrix is: 8 8 1 1 Command number 5 completed. Your options are:
  • 29. ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 6 The original matrix is: 8 1 8 1 The trace for this matrix is: 9 Command number 6 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 7 The original matrix is: 8 1 8 1 The copy of this matrix is: 8 1 8 1 Testing for equality. Should be equal!! The matrices are equal!!
  • 30. Command number 7 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 8 First matrix is: 8 1 8 1 Second matrix is: 6 5 2 6 The matrices are NOT equal!! Command number 8 completed. Your options are: ----------------- 1) Add 2 matrices 2) Subtract 2 matrices 3) Multiply 2 matrices 4) Multiply matrix by a constant 5) Transpose matrix 6) Matrix trace 7) Make a copy 8) Test for equality 0) EXIT Please enter your option: 0 Testing completed.