Professional Documents
Culture Documents
College of Engineering
Department of Computer Science
Project Specification
Requirement Specification
I. Requirement # 1: Create a program that performs operations on three matrices (of type int) A, B and C of
row and column sizes less than or equal to 100 on a command-line fashion. The operations are listed below.
Sample run:
>> MAKE A
Enter number of rows: 2
Enter number of columns: 2
A[0][0] = 1
A[0][1] = 2
A[1][0] = 3
A[1][1] = 4
>>
Notes:
i. The >> shows that your program is ready for a command.
ii. There are no confirmations that operations have been successfully executed.
iii. Only display errors.
b. Swap matrix A, B or C (10 pts). Swaps the values and dimensions of two matrices.
Syntax:
SWAP <matrix1> <matrix2>
– swap values and dimensions of <matrix1> and <matrix2>
– <matrix1> need NOT be different from <matrix2>
Sample run:
>> SWAP B C
>>
c. Display matirx A, B or C (10 pts). Displays the number of rows and columns followed by the
matrix elements.
Syntax:
DISP <matrix>
– display <matrix>
Sample run:
>> DISP A
Number of rows: 2
Number of columns: 1
|1|2|
|3|4|
>>
2 Matrix Operations (50 pts). If an operation error occurs like when rows and columns of two matrices
are not fit for an operation, issue an error and do not proceed but do not terminate the program. If a
matrix is not yet initialized but is used in an operation, issue an error and do not proceed with the
operation.
a. Addition (15 pts). Adds two matrices then puts result to a matrix (not necessarily unique from
either of the operands).
Syntax:
ADDM <matrix1> <matrix2> <matrix3>
– add <matrix1> and <matrix2> then put result to <matrix3>
– the three matrices need NOT be different and unique from each other
b. Scalar multiplication (10 pts). Multiplies a scalar (int) to a matrix then puts result to a matrix.
Syntax:
SMUL <scalar> <matrix1> <matrix2>
– multiply <scalar> (int) to <matrix1> then put result to <matrix2>
– the two matrices need NOT be different and unique from each other
c. Transpose (15 pts). Puts the transpose of a matrix to itself or another matrix.
Syntax:
TRAN <matrix1> <matrix2>
– put <matrix1>'s transpose result to <matrix2>
– the two matrices need NOT be different and unique from each other
a. Matrix multiplication (10 pts). Multiplies two matrices then puts result to a matrix.
Syntax:
MMUL <matrix1> <matrix2> <matrix3>
– multiply <matrix1> and <matrix2> then put result to <matrix3>
– the three matrices need NOT be different and unique from each other
Syntax:
ADDR <matrix> <row1> <row2> <row3>
– adds <row1> to row <row2> then put result to <row3> of <matrix>
– <row1>, <row2> and <row3> are of type int
– <row1>, <row2> and <row3> need NOT be different.
Other specifications
1 To show that your program is ready for an input/command, display >>. An example would be:
>>ADDM A B C
Operation successful!
>>TRAN A B
Operation successful!
2 Issue an error message if an operation does not exist or the user has inputted an invalid command. Notify user
of any user mistakes he/she might have committed – wrong input, incomplete input, etc.
3 Commands are case-sensitive. Hence, tran is not a valid command.
4 Matrices are also case-sensitive. Thus, issuing ADDM a b c is invalid. Issue an appropriate error message.
5 Assume that the user will always input correct arguments, except for those mentioned above. For instance, you
are ensured that the second argument for SMULC will always be a double.
6 You either get the full point for a given command or no point at all.
II. Requirement #2: Create a documentation of your program describing the algorithm(s) and functions used.
1. Provide the following information for each function:
a. Function prototype
b. Description
c. Parameter(s)
d. Returns
2. Describe the general flow of your program using flowcharts. Make it as concise as possible.
3. The documentation is worth 20% of the total grade for this project. So take this very seriously.
1. You can choose to restrict the number of possible rows and columns. If the user inputs a size outside the
bounds, you can just issue an error.
2. Please be careful on passing arrays to functions as they are called by reference especially on cases that an
operation's result is placed on one of the operands.
3. You can make things easier for you by creating a three-dimensional array of ints. Remember that using only
one bracket refers to a two-dimensional array. Hence, you are actually creating an array of two-dimensional
ints.
4. Remember that a string in C should always be ended with '\0' for you to use the functions in string.h properly.
5. Remember that only chars are enclosed in single quotes. So when you're referring to a number, never put any.
6. For your sake, please read everything carefully!
7. The program below works just like your MP, only cooler (because I made it =P). Study it and indulge.
#include <stdio.h>
#include <string.h>
while(1)
printf("\n>> ");
scanf("%s", str);
int a, b;
printf("%d", a+b);
int a, b;
printf("%d", a-b);
if (strcmp(str,"EXIT") == 0)
break;
return 0;
}
Sample Run
>>DISP A
A is not yet initialized!
>>MAKE A
Input number of rows: 51
Size is out of bounds! (If you choose to restrict the size up to 50.)
>>MAKE A
Input number of rows: 2
Input number of columns: 2
A[0][0] = 1
A[0][1] = 2
A[1][0] = 3
A[1][1] = 4
>>DISP A
Matrix A:
Number of rows: 3
Number of columns: 2
1 2
3 4
>>ADDM A B B
B is not yet initialized!
>>addm A A A
Invalid command!
>>ADDM a A A
Invalid argument!
>>ADDM A A A
>>SMUL A A A (This command will never ever happen!)
>>EXITC
Invalid command!
>>EXIT
Ciao mother/father!
Prepared by
Wilmarc Lopez
Computer Vision and Machine Intelligence Group
Sem I, AY 2010-2011
“The question of whether computers can think is like the question of whether submarines can swim.”
(Edsger W. Dijkstra)