Question

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 operations (addition, subtraction, multiplication) as Many mathematica


The following are more detailed descriptions of the required functions The grid0 function is the constructor. The constructor

The matrix type class, based on grid class, should provide the matrix operations. Inheritance from grid is public. matrixType

The following are more detailed descriptions of the required functions Function matrixintType(int,int,string) is the construc

The matrix Type operator%( int) randomize the matrix array values using the Fisher- Yates shuffle. See algorithm below. The i

Design and implement two C++ classes to provide matrix operations (addition, subtraction, multiplication) as Many mathematical functions and simple games use a two-dimensional grid that can be Source: www.xkcd.com implemented with a two-dimensional array Create a grid class to provide a basic grid functionality grid - rows: int -cols: int -**intGrid: int MAX ROW 5000: static constexpr int MAX COL 5000: static constexpr int +grid(int-0, int-0) +grid() +setCell(int, int, int): void +getCell(int, int) const: int +printGrid() const: void +setSize(int, int): void +getRows () const: int +getCols() const: int
The following are more detailed descriptions of the required functions The grid0 function is the constructor. The constructor should set the rows and cols class variables and dynamically create the two-dimensional array based on the provided input (row, cols). The arguments are the number of rows and columns in the grid. The constructor should ensure that the provided grid size is within the defined parameters (0 MAX_ROW, 0-MAX COL) inclusive. If not, an error message should be displayed and no board created and the class variables initialized appropriately. The constructor should dynamically create the board and initialize all cells to 0. Note, since a 1 by 1 grid is a scaler, a 1 by 1 grid is an error. The "grid() function is the destructor that should delete the dynamically allocated array. The setCell(int, int, int) should set the given cell, row and column, to the provided value. The arguments are the row, column, and new value (in that order). If an invalid location is provided, the function should display an error message. The getCell(int, int) should return the given content of the given row and column. The arguments are the row, column (in that order). If an invalid location is provided, the function should display an error message. The printGrid) function should print the contents of the grid including a leading and trailing '". Refer to the example output for a formatting example. The setSize(int, int) function should set the size matrix to the passed size (rows, columns). The function should ensure that the provided grid size is within the defined parameters (MAX_ROW and MAX_COL) inclusive. Note, while the constructor should allow a (0,0) matrix, the set size should not allow both rows and columns to be 0. If the size is incorrect, an error message should be displayed and the class variables not altered e size is correct, and a matrix already exists, it must be dynamically deleted before the new sized matrix is dynamically created. After the new matrix is created, the function should set the rows and cols class variables and initialize all cells to 0. Note, since a 1 by 1 grid is a scaler, a 1 by 1 grid is an error. The getRows0 and getCols) functions should return the applicable class variables.
The matrix type class, based on grid class, should provide the matrix operations. Inheritance from grid is public. matrixType -title: string matrixType(int-0, int-0, string-"") +matrixType(const matrixType &) ~matrixType() +getTitle() const: string +setTitle(string): void +operator*(const int) matrixType +operator (const matrixType&): const matrixType& +operator+ const matrixType& ): matrixType +operator-( const matrixType& ): matrixType +operator++):matrixType +operator-- : matrixType +operator--( int ): matrixType +operator+ +( int): matrixType +operator*-( int ): matrixType +operator int ): matrixType +operator%( int ): matrixType +operator( int ): matrixType +operatorl(int): matrixType friend istream& operator>> istream&, matrixType&); friend ostream& operator
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question: Implement C++ Code to do multiple matrix operation (like us addition, subtraction, multiplication)

Answer:

(a) Implement two C++ class to do addition of two multi-dimensional Matrix

-- Need to introduce a 'source file' cpp file to do these operations.

Below is the sample simple C++ cpp code

create file 'add_two_matrix.cpp' and write the below code

$vim add_two_matrix.cpp

/*-- START OF CODE --*/

#include<iostream.h> //include needed header files

//declare 2nd matrix class

class matrix_2;

//define 1st matrix class

class matrix_1

{

//define member variables

//define two dimensional matrix with size of 10*10

int a[10][10];

//define m.n as the range - until which matrix to be loaded

int m,n;

//define member functions

public:

//define member function to get values from user

void getValuesForMatrix1();

//define memeber function to load selected values from user

void putValuesIntoMatrix1();

//friend function to do matrix add,matrix substract,matrix multiply

friend void add_matrix(matrix_1,matrix_2);

friend void substract_matrix(matrix_1,matrix_2);

friend void multiply_matrix(matrix_1,matrix_2);  

};

void matrix_1::getValuesForMatrix1()

{

int i,j;

cout<<"Matrix 1 :\n"

cout<<"Enter Rows and Columns: ";

cin>>m>>n;

cout<<"Enter the Matrix_1 Elements :\n";

for(i=0:i<m;i++)

for(j=0;j<n;j++)

cin>>a[i][j];

}

void matrix_1::putValuesIntoMatrix1()

{

int i,j;

cout<<"Matrix 1 :\n"

for(i=0:i<m;i++)

{

for(j=0;j<n;j++)

{

cout<<a[i][j]<<" ";

}

cout<<endl;

}

//define 2nd matrix class

class matrix_2

{

//define member variables

//define two dimensional matrix with size of 10*10

int b[10][10];

//define m.n as the range - until which matrix to be loaded

int m,n;

//define member functions

public:

//define member function to get values from user

void getValuesForMatrix2();

//define memeber function to load selected values from user

void putValuesIntoMatrix2();

//friend function to do matrix add,matrix substract,matrix multiply

friend void add_matrix(matrix_1,matrix_2);

friend void substract_matrix(matrix_1,matrix_2);

friend void multiply_matrix(matrix_1,matrix_2);  

};

void matrix_2::getValuesForMatrix2()

{

int i,j;

cout<<"Matrix 2 :\n"

cout<<"Enter Rows and Columns: ";

cin>>m>>n;

cout<<"Enter the Matrix_1 Elements :\n";

for(i=0:i<m;i++)

for(j=0;j<n;j++)

cin>>b[i][j];

}

void matrix_2::putValuesIntoMatrix2()

{

int i,j;

cout<<"Matrix 2 :\n"

for(i=0:i<m;i++)

{

for(j=0;j<n;j++)

{

cout<<b[i][j]<<" ";

}

cout<<endl;

}

void add_matrix(matrix_1 m1,matrix_2 m2)

{

int i,j;

if((m1.m == m2.m) && (m1.n == m2.n))

{

cout<<"SUM OF TWO MATRIX"<<endl;

for(i=0;i<m1.m;i++)

{

for(j=0;j<m1.n;j++)

{

cout<<m1.a[i][j] + m2.b[i][j]<<" ";

}

cout<<endl;

}

}

else

{

cout<<"Matrix Rows and Column Dimensions are wrong Cant do Sum of two matrixes"<<endl;

}

}

void substract_matrix(matrix_1 m1,matrix_2 m2)

{

int i,j;

if((m1.m == m2.m) && (m1.n == m2.n))

{

cout<<"SUBSTRACT OF TWO MATRIX"<<endl;

for(i=0;i<m1.m;i++)

{

for(j=0;j<m1.n;j++)

{

cout<<m1.a[i][j] - m2.b[i][j]<<" ";

}

cout<<endl;

}

}

else

{

cout<<"Matrix Rows and Column Dimensions are wrong Cant do Substract of two matrixes"<<endl;

}

}

void mulltiply_matrix(matrix_1 m1,matrix_2 m2)

{

int i,j;

if((m1.m == m2.m) && (m1.n == m2.n))

{

cout<<"MULTIPLY OF TWO MATRIX"<<endl;

for(i=0;i<m1.m;i++)

{

for(j=0;j<m1.n;j++)

{

cout<<m1.a[i][j] * m2.b[i][j]<<" ";

}

cout<<endl;

}

}

else

{

cout<<"Matrix Rows and Column Dimensions are wrong Cant do Multiply of two matrixes"<<endl;

}

}

//Implement main function to call all the implemented fucntions

int main()

{

//declare matrix_1 matrix_2 objects

matrix_1 obj1;

matrix_2 obj2;

//call all functions for matrix objects

obj1.getValuesForMatrix1();

obj1.putValuesIntoMatrix1();

obj2.getValuesForMatrix2();

obj2.putValuesIntoMatrix2();

//do matrix operations

add_matrix(obj1,obj2);

substract_matrix(obj1,obj2);

multiply_matrix(obj1,obj2);

}

/*-- END OF CODE --*/

-- run the code in g++/gcc compiler operating systems

-- Execute the code with different matrix vaues and check the output for all matrix operations.

Add a comment
Know the answer?
Add Answer to:
I only need the "functions" NOT the header file nor the main implementation file JUST the impleme...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help modifying this program. How would I make sure that the methods is being...

    I need help modifying this program. How would I make sure that the methods is being called and checked in my main method? Here is what the program needs to run as: GDVEGTA GVCEKST The LCS has length 4 The LCS is GVET This is the error that I'm getting: The LCS has length 4 // I got this right The LCS is   //the backtrace is not being called for some reason c++ code: the cpp class: /** * calculate...

  • Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp,...

    Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp, and a test file to test the functionality of the class. Hint: read all the explanations in the header with attention. MyArray.h : #ifndef MYARRAY_H #define MYARRAY_H #include <iostream> using namespace std; class MyArray { friend ostream& operator<<( ostream & output, const MyArray & rhs); // to output the values of the array friend istream& operator>>( istream & input, MyArray & rhs); // to...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • Please help me out with this assignment. Please read the requirements carefully. And in the main...

    Please help me out with this assignment. Please read the requirements carefully. And in the main function please cout the matrix done by different operations! Thanks a lot! For this homework exercise you will be exploring the implementation of matrix multiplication using C++ There are third party libraries that provide matrix multiplication, but for this homework you will be implementing your own class object and overloading some C+ operators to achieve matrix multiplication. 1. 10pts] Create a custom class called...

  • C++ there is an issue with my if/else statements, I have tried several different ways to...

    C++ there is an issue with my if/else statements, I have tried several different ways to make it match the instructions but each time i get different errors. Need help geting this to match the instructions peoperly. *******************instructions***************************** Function: nextGeneration This function has no parameters. This function returns an int. The purpose of this function is to modify the grid to represent the next generation. Here's how you are supposed to do that for this assignment: Set each element of...

  • Using java : In this exercise, you need to implement a class that encapsulate a Grid. A grid is a useful concept in crea...

    Using java : In this exercise, you need to implement a class that encapsulate a Grid. A grid is a useful concept in creating board-game applications. Later we will use this class to create a board game. A grid is a two-dimensional matrix (see example below) with the same number of rows and columns. You can create a grid of size 8, for example, it’s an 8x8 grid. There are 64 cells in this grid. A cell in the grid...

  • C++ must use header files and implementation files as separate files. I’ll need a header file,...

    C++ must use header files and implementation files as separate files. I’ll need a header file, implementation file and the main program file at a minimum. Compress these files into one compressed file. Make sure you have adequate documentation. We like to manipulate some matrix operations. Design and implement a class named matrixMagic that can store a matrix of any size. 1. Overload the addition, subtraction, and multiplication operations. 2. Overload the extraction (>>) and insertion (<<) operators to read...

  • #ifndef __MATRIX__ #define __MATRIX__ #include "complex.h" namespace gtmath { class matrix { public: matrix(int , int...

    #ifndef __MATRIX__ #define __MATRIX__ #include "complex.h" namespace gtmath { class matrix { public: matrix(int , int );    //TODO: Add implementation here    //TODO: Implement parenthesis operator complex& operator()(int, int) { return m_vals[rows][cols]; } friend std::ostream& operator<<(std::ostream& os, gtmath::matrix& m);    int get_num_cols(); int get_num_rows();          private: complex** m_vals; int rows; int cols; }; } #include "matrix.h" #include <limits> namespace gtmath { //constructor & inlitilize dynamic array matrix::matrix(int rows, int cols) { this->cols = cols; this->rows = rows;...

  • In this assignment, you are asked to: 1. create a Matrix class that stores and operate...

    In this assignment, you are asked to: 1. create a Matrix class that stores and operate on a dynamic two-dimensional array. The class has the following structure: Private member variables: - int ** mat; - int rows; - int cols; Public member functions: +Default constructor: sets both rows and cols to 3 and creates 3x3 matrix dynamically +Parameterized constructor: sets the rows and cols to the values passed to the constructor and create a matrix with the given dimensions. +Destructor:...

  • STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...

    STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT