multiplies two matrices (M1 × M2) of
integers using pointers and dynamic arrays (you are not allowed to use the vector class). At the command
line, require four integer arguments: (1) M1 rows, (2) M1 columns, (3) M2 rows, (4) M2 columns.
read in the matrices one cell at a time.
I just want a little help on how to code matrices. Here is what im beinging with:
You are supposed to got the array dimensions as command line arguments. You current code ignores the arguments and reads values from std::cin.
Why do you show usage on line 4? You don't know at that point whether the user has given required arguments.
In your current code the lines 6-16 do read dimensions from the user. What does the lines 17-21 achieve?
argv is array of character string
Yes. Each string is one command line argument. The array has argc strings. The first string is the name of the program. The other strings you should convert to integers and store to the variables that you have declared on line 3.
Note on line 20. The most portable range of return values is probably 0--127. The language standard requires int, but some operating systems expect smaller range.
bool s2i( const char *, int & ); // string to int
IF (5==argc && s2i(argv[1], m1r) && s2i(argv[2], m1c) &&
s2i(argv[3], m2r) && s2i(argv[4], m2c))
IF (0<m1r && 0<m1c && m1c==m2r && 0<m2c)
do all the real work
ELSE
error: invalid dimensions
ELSE
error: usage