Help!! Tips on Matrix Calculator Program please!

This is a discussion on Help!! Tips on Matrix Calculator Program please! within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I'm enjoying all the great info on this board. Could I ask for some tips on this program ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    37

    Help!! Tips on Matrix Calculator Program please!

    Hi everyone, I'm enjoying all the great info on this board. Could I ask for some tips on this program I have for school? Its for Matrix Math. The program will read 4X4 matrices from the keyboard and perform operations on them. The operations are: +, -, scalar *, matrix *, and transpose. A 'Q' will quit the program.

    It needs to run something like this:

    -----------------------------------------------------------------------------

    How many initial matrices will begiven? 2

    For matrix 1:
    Row 1? 2 4 0 1
    Row 2? 3 0 1 2
    Row 3? 1 0 1 -1
    Row 4? 0 1 2 0

    For matrix 2:
    Row 1? 1 0 0 0
    Row 2? 0 1 0 0
    Row 3? 0 0 1 0
    Row 4? 0 0 0 1

    Operation? +

    First matrix for +? 1
    Second matrix for +? 2

    Result is matrix 3:
    Row 1: 3 4 0 1
    Row 2: 3 1 1 2
    Row 3: 1 0 2 -1
    Row 4: 0 1 2 1

    Operation? *

    Scalar value for *? 2
    Matrix for *? 3

    Result is matrix 4:
    Row 1: 6 8 0 2
    Row 2: 6 2 2 4
    Row 3: 2 0 4 -2
    Row 4: 0 2 4 2

    Operation? T

    Matrix for T? 4

    Result is matrix 5:
    Row 1: 6 6 2 0
    Row 2: 8 2 0 2
    Row 3: 0 2 4 4
    Row 4: 2 4 -2 2

    Operation? X

    First matrix for X? 1
    Second matrix for X? 3

    Result is matrix 6:
    Row 1: 18 13 6 11
    Row 2: 10 14 6 4
    Row 3: 4 3 0 -1
    Row 4: 5 1 5 0

    Operation? Q
    ---------------------------------------------------------------------

    Any help is appreciated!

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Well, your matrices can be represented by 4X4 arrays.. The math part's just a matter of figuring out how to add, multiply, etc. arrays... Whaddya got so far?

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    37
    I think I'm supposed to use a 3D array instead of a bunch of 2ds, is that good?
    Last edited by skanxalot; 03-07-2002 at 04:23 PM.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    I can't think of any reason you'd want to use 3d arrays...

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    37
    What I'm thinking is I might need to use a 3D because the number of matrices is a variable, entered by user. It could be two, it could be twenty.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    37
    bis-ump!!

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    This has been asked mant times before.

    http://www.cprogramming.com/cboard/s...threadid=12464

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    37
    Ok, so how do I make it do this:

    For matrix 1:
    Row 1? 2 4 0 1
    Row 2? 3 0 1 2
    Row 3? 1 0 1 -1
    Row 4? 0 1 2 0

    For matrix 2:
    Row 1? 1 0 0 0
    Row 2? 0 1 0 0
    Row 3? 0 0 1 0
    Row 4? 0 0 0 1

    Where the space makes it go to a new column??
    I don't know how to input a row at a time.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    8

    Hmm....

    I wouldn't use 2d or 3d arrays.

    Make a matrix class then have an array of class objects or use a linked list of classes....

  10. #10
    Registered User
    Join Date
    Mar 2002
    Location
    South Africa
    Posts
    35

    I think Donk has the best idea

    Unless you are using c or pascal or sth, neither of which allows that. In that case, perhaps you should try a dynamic array of 2d arrays.
    I code.
    I think.
    Ergo, I think in code.

  11. #11
    Registered User
    Join Date
    Mar 2002
    Posts
    37
    The thing is, we haven't learned classes yet so I don't think that would be a good idea. I'm pretty sure we're supposed to use a 3D array. So how can I input a row at a time?

  12. #12
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Easily

    cout << "Enter row " << row << "->";
    cin >> var1;
    cin >> var2;
    cin >> var3;
    cin >> var4;

    This will work provided they seperate each element by spaces. Of course you'll probably want to use some loops, and put the 'var's in an array or something, as this isn't expandable.

  13. #13
    Registered User
    Join Date
    Mar 2002
    Posts
    37
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 02:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 07:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21