You are on page 1of 5

University of the Philippines Diliman

College of Engineering
Department of Computer Science

CS 11: Machine Project 1


ES 26 Project: Matrix Calculator
The objective of this coursework is to let you use the programming concepts you have learned from this course and
to be able to apply it by creating a Matrix Calculator program written in C.

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.

1 Program Operations (30 pts)


a. Make/overwrite matrix A, B or C (10 pts). Asks the user for the dimensions then asks for the
individual elements.
Syntax:
MAKE <matrix>
– create or overwrite <matrix>

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

3 Row Operations (20 pts)


a. Multiplying a row by a constant (10 pts).
Syntax:
RMUL <matrix> <row> <scalar>
– multiply <scalar> to row <row> of <matrix>
– <scalar> and <row> are of type int.

b. Swapping two rows (10 pts)


Syntax:
SWAR <matrix> <row1> <row2>
– swaps <row1> of <matrix> to row <row2>of <matrix>
– <row1> and <row2> are of type int
– <row1> and <row2> need NOT be different.

c. Adding two rows together (10 pts).

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.

Tips and tricks

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>

#define MAX_CHAR 100


int main() {

char str[MAX_CHAR] = {'\0'};

while(1)

printf("\n>> ");

scanf("%s", str);

if( strcmp(str,"ADD") == 0 ) //str is equal to "MAKE"

int a, b;

scanf("%d %d", &a, &b);

printf("%d", a+b);

if( strcmp(str,"SUBT") == 0 ) //str is equal to "SUBT"

int a, b;

scanf("%d %d", &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!

MP Requirement Details (FOLLOW RULES STRICTY!)

1. There are two MAIN deliverables for this project:


a. C source codes (zipped)– 80%
b. Documentation (in PDF) – 20%
2. Send the above deliverables as e-mail attachments to wilmarclopez@gmail.com with the following format as
subject on or before 11:59 pm of August 23, 2010:
a. for THVW: [CS11thvw1011-MP01] Lastname, Firstname
b. for THRU: [CS11thru1011-MP01] Lastname, Firstname
3. This project shall be done individually. Committing plagiarism or assisting another in committing plagiarism
shall be dealt with accordingly.
4. MOSS (Measure Of Software Similarity) from UC Berkeley (http://www.cs.berkeley.edu/~aiken/moss.html)
will be used on the codes to check if anyone cheated – anyone who will be caught cheating will be given a
grade of 5.0 for the entire course.
5. There will be a project demo and will be scheduled later.
6. The coursework cannot be completed at the last minute. Spread the work over the time provided. There will
be no late submissions. Failure to submit on time will incur the student(s) a grade of 0 for this project.
7. Do not assume anything. If there are questions about the specification, ask your instructor. This is very
important! Please NEVER HESITATE to approach me 

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)

You might also like