logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

The overall goal of this assignment is to implement a C++ application that makes use of classes

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Assignment: Matrix -

Intro to Classes ####Overview

The overall goal of this assignment is to implement a C++ application that makes use of classes and object-oriented technology to create a user-defined `Matrix` type. The functional goal is to create a `Matrix` class that supports certain common operations. In the process you will understand how to create user-defined types using C++ classes, initialize objects using an overloaded constructor, apply the principles of encapsulation and abstraction, and refresh (or learn) the basic linear algebra operations on matrices. A matrix is a rectangular array of numbers arranged in a rows and columns fashion. The number of rows and columns define the dimensions of a matrix. For instance, a matrix that has two rows and three columns is a *two by three* matrix.

The picture below illustrates some sample matrices. ![graphic](https://github.com/xaviermerino/ECE2551-SoftHardDesign/blob/master/Homework-2/matrices.png?raw=true) In the end, you are tasked with creating a class that will perform certain matrices operations. In the future assignments you will be building extra functionality to this class as you explore other object-oriented principles. For a brief linear algebra review you can check: * **Video Lecture:** [Introduction to matrices](https://youtu.be/GguVxHgTv0s) (18 min) * **Video Lecture:** [Computing Determinants of n-dimensional Matrices](https://youtu.be/nbHdSaQu8BI) (10 min) For more information about the math behind matrices and their operations you can [check this](https://www.khanacademy.org/math/precalculus/precalc-matrices). For more information on classes and objects you can follow this [tutorial](https://github.com/xaviermerino/ECE2551-SoftHardDesign/blob/master/Homework-2/tutorial-classes-objects.pdf?raw=true). #### Functional Requirements The following requirements are an overview of what is expected of you in this assignment.

More details on how to implement the solution can be found in the Technical Requirements section. * Each row in the matrix is represented by a `std::vector` of type `double`. The size of the vector will be determined by the required dimensions. * The matrix itself is represented by a vector of row vectors. The matrix is a `std::vector` of type `vector`. * Create a variable `rowSize` of type `int` that keeps tract of the number of rows in the matrix.

* Create a variable `colSize` of type `int` that keeps tract of the number of columns in the matrix. * Create a function `dotProduct` that returns the result of this operation when applied to the two supplied vectors. * Create a function `add` that can add a matrix to another. The function should perform this addition on the calling object. * Create a function `subtract` that can subtract a matrix to another. The function should perform the subtraction on the calling object. * Create a function `multiply` that can multiply a matrix by a scalar. The function should perform this multiplication on the calling object.

* Create another function `multiply` that **overloads** the previous function of this name. This new `multiply` function can multiply a matrix by another. The result should be stored on the the calling object. * Create a function `transpose` that performs a matrix transpose on the calling object. * Create a function `zero` that replaces all of the elements in a matrix with zeros. This function should perform this operation on the calling object. * Create a function `show` that prints all of the contents of the calling matrix. * Create a **recursive** function `getDeterminant` that returns the determinant of the calling matrix. * Remember to identify your recursive and base cases. * The **base case** for this function *could* be: * The algorithm encountered a matrix with dimensions 2x2.

* The **recursive case** for this function *could* be: * Any matrix with a greater dimension than 2x2. * Create a function `getAt` that returns the element stored in the specified position of the calling matrix. The position will be specified by a row and column number. * Create a function `getRowSize` that returns the amount of rows in the calling matrix. * Create a function `getColSize` that returns the amount of columns in the calling matrix. * Create a function `isSquare` that returns `true` if the calling matrix is a square matrix or `false` if it is not. * Create a function `hasSameDimensionsAs` that returns `true` if the calling matrix has the same dimensions as the matrix passed as an argument. It returns `false` otherwise. * Create a function `getMinor` that returns the minor of the calling matrix based on the specified row and column. For more information on `std::vector` you can check [here](http://www.cplusplus.com/reference/vector/vector/). #### Getting Started

1. **[Download](https://github.com/xaviermerino/ECE2551-SoftHardDesign/blob/master/Homework-2/starterHwk2.zip?raw=true)** the starter file set. It will contain the following files: * `catch.hpp` * `Matrix.hpp` * `Matrix.cpp` * `main.cpp` 2. The provided `main.cpp` file is the test file. You are free to test your own program using your own `main.cpp` file but bear in mind that you will be tested against the provided one. 3. The provided `Matrix.hpp` file is the header file for the `Matrix.cpp` file. It provides the specification of the class. Your main task is to write the C++ implementation code for each of the Matrix class functions in the `Matrix.cpp` file. 4. Use your favorite IDE or editor to modify your files. At first, **the program won't compile**. Follow the steps 5 - 7 below to get it to compile. 5. In `Matrix.hpp`, create an `enum` and create a type alias for it, the type should be `Status`. It should hold the following values: * NoError * DivideByZeroError * DimensionError 6. In `Matrix.cpp`, write an empty implementation for each of the functions in the `Matrix.hpp` file. 7. The **program will now compile**. If you try running the program it will tell you that it has **failed all the tests**. Your goal is to make the program pass all the tests by completing the implementation of the methods given to you. You can implement helper functions if needed. See the following section for more information. #### Technical Requirements This section will serve as a guideline of what is necessary for the program to pass all the tests.

We perform unit testing using the **Catch** framework. Catch is a **header-only** framework which means you just need to drop the header file containing the framework into your project. This is the reason behind the `catch.hpp` file. You can also see that some code is provided in the `main.cpp` file. This code tests your `Matrix` class that you placed in the `Matrix.hpp` and `Matrix.cpp` files. If your code passes all the tests it is ready for submission and will, most likely **(cheating is heavily penalized)**, receive full credit. The only thing that you need to do is to modify the `Matrix.hpp` and `Matrix.cpp` files to get the provided functions working. Don't change the function signature as the testing program relies on this to grade your submission. When you first run your program (and no modifications to the functions have been made) you will see something like this: ``` test cases: 24 | 24 failed assertions: 24 | 24 failed ``` Let's start explaining what each of the functions defined in the `Matrix.hpp` file must do. Function implementations for **both** classes **must** be placed in the `Matrix.cpp` file. **The following functions belong to the `Matrix` class:** * **Matrix()**:

Default constructor for the `Matrix` class. It must initialize `rowSize` and `colSize` to zero. * **Matrix(const std::vector\\>& data)**: Parametrized constructor for the `Matrix` class. It takes a vector of row vectors (that store data of type double), resizes the `matrix` data member accordingly and copies the information in `data` to `matrix`. ```c++ enum { RowOne, RowTwo }; std::vector> data; const int numberRows = 2; data.resize(numberRows); data[RowOne].push_back(9); data[RowOne].push_back(7); data[RowTwo].push_back(0); data[RowTwo].push_back(2); Matrix sample(data); ``` The sample code above will create the `Matrix` object below.

![add](https://github.com/xaviermerino/ECE2551-SoftHardDesign/blob/master/Homework-2/matrix2x2.png?raw=true)

* **Status add(const Matrix& other)**: Function that takes as an argument a matrix `other` and adds it, element-wise, to the calling object. It returns a value of type `Status` (defined previously). It should return `NoError` if the addition was carried out successfully or `DimensionError` if the matrices' dimensions do not match. ```c++ enum { RowOne, RowTwo, RowThree }; const int numberRows = 3; std::vector> dataOne; dataOne.resize(numberRows); dataOne[RowOne].push_back(8); dataOne[RowOne].push_back(7); dataOne[RowOne].push_back(5); dataOne[RowTwo].push_back(0); dataOne[RowTwo].push_back(2); dataOne[RowTwo].push_back(4); dataOne[RowThree].push_back(6); dataOne[RowThree].push_back(4); dataOne[RowThree].push_back(2); std::vector> dataTwo; dataTwo.resize(numberRows); dataTwo[RowOne].push_back(1); dataTwo[RowOne].push_back(2); dataTwo[RowOne].push_back(3); dataTwo[RowTwo].push_back(4); dataTwo[RowTwo].push_back(5); dataTwo[RowTwo].push_back(4); dataTwo[RowThree].push_back(1); dataTwo[RowThree].push_back(2); dataTwo[RowThree].push_back(3); Matrix one(dataOne); Matrix two(dataTwo); one.add(two); ``` The sample code above will result in the matrix addition as pictured below.

![add](https://github.com/xaviermerino/ECE2551-SoftHardDesign/blob/master/Homework-2/add.png?raw=true)

* **Status subtract(const Matrix& other)**: Function that takes as an argument a matrix `other` and subtracts it, element-wise, from the calling object. It returns a value of type `Status` (defined previously). It should return `NoError` if the subtraction was carried out successfully or `DimensionError` if the matrices' dimensions do not match. ```c++ enum { RowOne, RowTwo, RowThree }; const int numberRows = 3; std::vector> dataOne; dataOne.resize(numberRows); dataOne[RowOne].push_back(8); dataOne[RowOne].push_back(7); dataOne[RowOne].push_back(5); dataOne[RowTwo].push_back(4); dataOne[RowTwo].push_back(5); dataOne[RowTwo].push_back(4); dataOne[RowThree].push_back(6); dataOne[RowThree].push_back(4); dataOne[RowThree].push_back(2); std::vector> dataTwo; dataTwo.resize(numberRows); dataTwo[RowOne].push_back(1); dataTwo[RowOne].push_back(2);

dataTwo[RowOne].push_back(3); dataTwo[RowTwo].push_back(4); dataTwo[RowTwo].push_back(5); dataTwo[RowTwo].push_back(4); dataTwo[RowThree].push_back(1); dataTwo[RowThree].push_back(2); dataTwo[RowThree].push_back(1); Matrix one(dataOne); Matrix two(dataTwo); one.subtract(two); ``` The sample code above will result in the matrix subtraction as pictured below.

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

526 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

681 Answers

Hire Me
expert
AyooluwaEducation

943 Answers

Hire Me
expert
RIZWANAMathematics

706 Answers

Hire Me

Get Free Quote!

317 Experts Online