Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal Joey7F's Journal: Programming Assignment 1

Source:

#include
using namespace std;
#include
#define MAX_DIMENSION 10
#define MAX_ENTRY_LENGTH 5 //this is for field width purposes

struct dimensions
{ //matrix dimensions sans the data
        int matrix1r, matrix1c, matrix2r, matrix2c;
};

struct valid
{ //the add, subtract, etc. are either true or false, true meaning they can be performed // and false if they can't
        bool add, subtract, smult, mmult, trans;
};
void returnbig(dimensions dim, int *matrix1[MAX_DIMENSION][MAX_DIMENSION], int *matrix2[MAX_DIMENSION][MAX_DIMENSION]);
void add(dimensions dim, int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);
void subtract(dimensions dim, int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);
void mmult(dimensions dim,int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);

void smult(dimensions dim,int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);

void trans(dimensions dim, int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);

void getelements(dimensions dim, int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);
void output(dimensions dim,int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION]);
dimensions getdata();
int menu(valid validations);
valid validation (dimensions data);
void main()
{
        int matrix1[MAX_DIMENSION][MAX_DIMENSION] = {0};
        int matrix2[MAX_DIMENSION][MAX_DIMENSION] = {0};

        dimensions dim;
        dim = getdata();
        getelements(dim, matrix1, matrix2);
        valid validations = validation(dim); //menu(validations);
        switch(menu(validations))
        {
                case 1: add(dim, matrix1, matrix2); break;
                case 2: subtract(dim, matrix1, matrix2); break;
                case 3: mmult(dim, matrix1, matrix2); break;
                case 4: smult(dim, matrix1, matrix2); break;
                case 5: trans(dim, matrix1, matrix2); break;
                default: cout MAX_DIMENSION || dim.matrix1c > MAX_DIMENSION || dim.matrix2r > MAX_DIMENSION || dim.matrix2c> MAX_DIMENSION)
        {
                cout > dim.matrix1r;
                cin >> dim.matrix1c;
                cin >> dim.matrix2r;
                cin >> dim.matrix2c;
        }

        return dim;
}

void getelements(dimensions dim, int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION])
{
        int x;
        char answer;
        for (int j=0; j > x;
                        matrix1[j][i] = x;
                }
        }

        for (int j=0; j > x;
                        matrix2[j][i] = x;
                }
        }

        output(dim,matrix1, matrix2);
        cout > answer; //If there were errors in the display, we re-call this element function
        if (answer=='Y' || answer=='y')
                getelements(dim, matrix1, matrix2);

        return;
}

void output(dimensions dim, int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION])
{
        cout > i;

        return (i+count);
}

void add(dimensions dim,int matrix1[MAX_DIMENSION][MAX_DIMENSION], int matrix2[MAX_DIMENSION][MAX_DIMENSION])
{
        cout > scalar;

        for (int j = 0; j dim.matrix1r)
        {
                int swap[MAX_DIMENSION][MAX_DIMENSION]; // when we return to main.
                swap=*matrix1;
                *matrix1=*matrix2;
                *matrix2=swap;
        }
        */
        return;
} /*Input Matrix information in the format( R1 C1 R2 C2 ) 3 2 2 3
Enter the Data for row 1
2 3
Enter the Data for row 2
3 4
Enter the Data for row 3
4 5
Enter the Data for row 1
2 3 4
Enter the Data for row 2
3 4 5
Matrix 1
        2 3
        3 4
        4 5
Matrix 2
        2 3 4
        3 4 5
Are there any errors? (y/n) n
The following operations are valid:

Menu
1. Matrix Multiplication
2. Scalar Multiplication
3. Matrix Transposition

Please select one: 1
Matrix Multiplication...
| 13 18 23|
| 18 25 32|
| 23 32 41|

**********OUTPUT***********************/ /***********OUTPUT 2****************
Input Matrix information in the format( R1 C1 R2 C2 ) 3 3 3 3
Enter the Data for row 1
1 2 3
Enter the Data for row 2
4 5 6
Enter the Data for row 3
7 8 9
Enter the Data for row 1
9 8 7
Enter the Data for row 2
6 5 4
Enter the Data for row 3
3 2 1
Matrix 1
        1 2 3
        4 5 6
        7 8 9
Matrix 2
        9 8 7
        6 5 4
        3 2 1
Are there any errors? (y/n) n
The following operations are valid:

Menu
1. Add
2. Subtract
3. Matrix Multiplication
4. Scalar Multiplication
5. Matrix Transposition

Please select one: 1
Adding Matrix One and Matrix Two...
| 10 10 10|
| 10 10 10|
| 10 10 10|
*/

--Joey

This discussion has been archived. No new comments can be posted.

Programming Assignment

Comments Filter:

I've noticed several design suggestions in your code.

Working...