CS 112 Project 4: Matrix Operations

Objectives:

  1. Build more Matrix operations.
  2. Practice building templates.
  3. Practice using the debugger (if necessary).

Introduction

This week's project is a team project to add more functionality to the Matrix class we built in this week's lab. To illustrate, suppose that m1, m2, and m3 are Matrix objects containing the following values:

   m1 == {1, 2, 3,
          4, 5, 6}
   m2 == {2, 3, 4,
          5, 6, 7}
   m3 == {0, 0, 
          0, 0,
          0, 0}
  1. Inequality. The expression:
       m1 != m2
    should return true. The expression:
       m1 != m1
    should return false.
  2. Stream Input. The expression:
  3.   m.readFrom(cin);
    should read m.getRows() * m.getColumns() values from cin. In other words, this method should assume that the Matrix to which this message has been sent has already been constructed with the correct size. The test-method for this operation uses the file MatrixTest1.txt, so be sure to import it into your project.
  4. Stream Output. The expression:
      m.writeTo(cout);
    should write the values of m to cout, neatly organized in rows and columns, with columns separated by tabs.

  5. File Input. The expression:
      m.readFrom(fileName);
    should fill m with values stored in fileName. You may assume that the first line of fileName has two integers that specify the number of rows and columns of the data in the file.
  6. File Output. The expression:
       m.writeTo(fileName);
    should write all of the values in m to the file named by fileName, neatly organized into rows and columns, with columns separated by tabs. The first line of fileName should consist of the number of rows and columns in m.

  7. Matrix Addition. The expression:
       m3 = m1 + m2;
    should set
    m3 == {3, 5, 7,
           9, 11, 13}
    For Matrix addition to be defined, the two matrices being summed must have the same number of rows, and the same number of columns, but the number of rows need not equal the number of columns.
  8. Matrix Subtraction. The expression:
       m3 = m2 - m1;
    should set
    m3 == {1, 1, 1,
           1, 1, 1}
    For Matrix subtraction to be defined, the two matrices being summed must have the same number of rows, and the same number of columns, but the number of rows need not equal the number of columns.
  9. Tranpose. The expression:
    m3 = m1.getTranpose();
    should set
    m3 == {1, 4,
           2, 5, 
           3, 6}
    More generally, the m.getTranpose() operation should return a Matrix whose columns are m's rows, and whose rows are m's columns.

As indicated on the grade sheet, different members of your team are responsible for different operations. See me for the teams for this project.

As usual, the opening documentation in each file should indicate who wrote which methods.

To make life easier for you, MatrixTester contains a test-method for each of these operations. Use these test-methods and test driven development to build your operations. If you get your program to compile, but it fails a test and you cannot figure out what is wrong, use the debugger! If necessary, draw a memory diagram and trace through the execution of the problematic function one statement at a time, until you identify the logic error.

Template. When you have "finished" your Matrix class, convert it to a Matrix<Item> template and modify the tests in MatrixTester to test your new template.

Application. When you have "finished" your Matrix<Item> template, write a program that:

  1. Displays a menu of Matrix operations (addition, subtraction, and transpose);
  2. Allows the user to choose one of those operations;
  3. Allows the user to enter the name of a file containing Matrix data, and builds a Matrix object using that data;
  4. If the operation requires a second Matrix, allows the user to enter the name of a file containing the data for that Matrix and builds a second Matrix object using that data; and
  5. Displays on the screen the Matrix that results from applying the operation to the data.

Submit:


CS > 112 > Projects > 04


This page maintained by Joel Adams.