Language is C++
Basic principles and theory of structured programming in C++ by implementing the class: Matrix
Use these principles and theory to help build and manipulate instances of the class (objects), call member functions
Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp).
The code in the following files:
Summary
Create three files matrix.cpp and matrix.h . You will end up with matrix.h, matrix.cpp and matrixDriver.cpp.
Matrix Class Definition:
Class Account |
|
Private Data Members: static int cnt const int maxRowSize=5 const int maxColSize =5 int row_size int col_size double matrix[maxRowSize][maxColSize] |
Static data member used to count the number of Matrix objects created; The maximum row size of a Matrix object. The maximum column size of a Matrix object. Row size of matrix Column size of matrix The 2-Dimensional array representing the matrix. |
Public Member Functions: Matrix() Matrix(int row, int column) |
Constructors: Default Constructor (no parameters) –Maximum size of Matrix Overloaded Constructor: row and column size of matrix |
Public Member Functions: void setRowSize(int x) void setColumnSize(int x) void addValue(double x) static int getCnt() |
Function sets the row size of the matrix. Function sets the column size of the matrix . Populates Matrix object left to right / top to bottom. Returns the count of Matrix objects created |
Public Member Functions: int getRowSize() int getColumnSize() void displayMatrix() double getValue(int row, int col) |
Function returns the row size Function returns the column size Function displays the matrix on the console Function retrieves a value in matrix at position (row,col) |
Public Member Functions: Matrix add(Matrix &other) Matrix substract(Matrix &other) Matrix product(Matrix &other) Matrix product(double scalar) |
Operation for adding two matrices Operation for subtracting two matrices Operation for multiplying two matrices Operation for multiplying a scalar to a matrix |
Main Program:
Create a program which demonstrates the following:
This is all information given for this homework assignment
The interface is Class and Data Abstraction
#include<iostream.h>
#include<conio.h>
#include<math.h>
class matrix
{
public:
int a[50][50],b[50][50],c[50][50],i,j,m,n,p,q,k;
void summetrix()
{
cout<<"enter the first metrix elements"
for(i=1;i<2;i++)
for(j=1;j<2;j++)
cin>>a[i][j];
cout<<"enter the elements of second metrix";
for(i=1;i<2;i++)
for(j=1;j<2;j++)
cin>>b[i][j];
for(i=1;i<2;i++)
for(j=1;j<2;j++)
c[i][j]=a[i][j]+b[i][j];
for(i=1;i<2;i++)
for(j=1;j<2;j++)
cout<<c[i][j];
}
void sumMetrix(int row,int col)
{
p=row;
q=col;
for(i=1;i<p;i++)
for(j=1;j<q;j++)
cin>>a[i][j];
for(i=1;i<p;i++)
for(j=1;j<q;j++)
cin>>b[i][j];
for(i=1;i<p;i++)
for(j=1;j<q;j++)
c[i][j]=a[i][j]+b[i][j];
for(i=1;i<p;i++)
for(j=1;j<q;j++)
cout<<c[i][j];
}
void main()
{
matrix m;
m.summetrix();
m.sumMetrix(3,2);
m.submetrix();
m.mulmetrix();
getch();
}
void submetrix()
{
cout<<"enter the first metrix elements"
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cin>>a[i][j];
cout<<"enter the elements of second metrix";
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cin>>b[i][j];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
c[i][j]=a[i][j]-b[i][j];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cout<<c[i][j];
}
void mulmetrix()
{
cout<<"enter the first metrix elements"
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cin>>a[i][j];
cout<<"enter the elements of second metrix";
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cin>>b[i][j];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
c[i][j]=0;
for(k=1;k<=2;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cout<<c[i][j];
}
Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...
Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...
//please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks import java.util.*; public class Test { /** Main method */ public static void main(String[] args) { double[][] matrix = getMatrix(); // Display the sum of each column for (int col = 0; col < matrix[0].length; col++) { System.out.println( "Sum " + col + " is " + sumColumn(matrix, col)); } } /** getMatrix initializes an...
C++ CODE: The matrix class consists of two files: matrix.h and matrix.cpp. The class has the following definition: matrix -size:int -mat:int** ---------------- +matrix(file:string) +~matrix() +operator +(add:matrix*):matrix & +operator-(sub:matrix*):matrix & +friend operator<<(out:ostream &, t:const matrix&):ostream & +displayRow(r:int):void The class variables are as follows: • size: the number of rows and columns in a square matrix • mat: the integer matrix that contains the numeric matrix itself. The methods have the following behaviour: 2 • matrix(file:string): The default constructor. It receives the...
1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...
I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...
C++ This exercise will introduce static member variables and static methods in class to you. Class Department contain information about universities departments: name students amount in addition it also stores information about overall amount of departments at the university: departments amount class Department { public: Department(string i_name, int i_num_students); ~Department(); int get_students(); string get_name(); static int get_total(); private: string name; int num_students; static int total_departments; }; Carefully read and modify the template. You have to implement private static variable "total...
Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()" public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...
The code should be written in C++. I included the Class used for this function. Also, please fix the main function if necessary. Description: This function de-allocates all memory allocated to INV. This will be the last function to be called (automatically by the compiler) //before the program is exited. This function also erased all data in the data file. There are other functions that add, process and alter the file; the file printed after those functions will have new...