Es26-le03-handson

  • Uploaded by: Wilmarc
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Es26-le03-handson as PDF for free.

More details

  • Words: 974
  • Pages: 3
ES 26 – Third Long Exam First Semester, AY 2009-2010

Matrix Calculator Create a program that performs the following operations on three matrices (double) A, B and C of row and column sizes less than or equal to 50 on a command-line fashion: 1. Program Operations (50 pts) a) Make/overwrite matrix A, B or C (15 pts) e.g. make matrix C: MAKE C. Ask the user to first input the number or rows and columns. b) Swap matrix A, B or C (15 pts) e.g. swap matrices A and B: SWAP A B c) Display matix A, B or C (15 pts) e.g. show matrix C: DISP C. Display the number of rows and the number of columns followed by the matrix itself. An example would be Matrix A:

Number of rows: 3 Number of columns: 2 0 1 2 3 4 5 5 6 7

d) Exit the program (5 pts): EXIT 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. a) Addition (15 pts) e.g. add A and B then put result to C: ADD A B C b) Scalar multiplication (10 pts) e.g. multiply 78.5 with C then put result to B: SMUL C 78.5 B c) Transpose (15 pts) e.g. transpose A then put result to A: TRANS A A d) Matrix multiplication (10pts) e.g. matrix multiply C and A then put result to B: MMUL C A B 3. Row Operations (25-pt. Bonus) a) Multiplying any row by a non-zero constant (5 pts) e.g. multiply row 0 of matrix A by 19.8: RMUL A 0 19.8. To convert a string to int use atoi(). b) Interchanging any rows (10 pts) e.g. swap matrix A's row 0 and 1: SWAPR A 0 1 c) Adding any two rows together (10 pts) e.g. add rows 1 and 1 of matrix A then put result to row 1: ADDR A 1 1 1 Other specifications: 1) To show that your program is ready for an input/command, display >>. An example would be: >>ADD A B Operation >>TRANS A Operation

C successful! B successful!

2) Issue an error message if an operation does not exist or the user has inputted an invalid command. 3) Commands are case-sensitive. Hence, trans is not a valid command. 4) Matrices are also case-sensitive. Thus, issuing ADD a b c is invalid. Issue an appropriate

5) 6) 7) 8) 9)

error message. Assume that the user will always input correct arguments, except for those mentioned above. Hence, you are ensured that the second argument for SMULC will always be a double. To convert a string to double, use atof(). Other errors are trivial and are expected to be handled properly. You either get the full point for a given command or no point at all. A deduction of 3 points shall be given to each unhandled exceptions and/or user errors specified above. Write your name, section, time and date of exam on the source code like the ff: /** * Wilmarc D. Lopez * ES26 – THWX1 * September 15, 2009 (Wednesday) * 1:00pm-4:00pm */

10) Also print the same information on screen at the start of your program. 11) This is an open everything exam. 12) Anybody caught talking with anyone except me will automatically be given a grade of 5.0. Do not say I didn't warn you. 13) A student is only allowed to leave the classroom once and only if no student is already outside. 14) When you're finished, call my attention. Tips: 1) 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 e.g. ADD A B A. This one's tricky. 2) You can make things easier by creating a three-dimensional array of doubles. Remember that using only one bracket refers to a two-dimensional array. Hence, you are actually creating an array of two-dimensional doubles. 3) Remember that a string in C should always be ended with '\0' for you to use the functions in string.h properly, among others. 4) Use memcpy() to copy a certain part of a string (substring) and just append '\0' to turn it into another string. The first parameter of memcpy() is the address (e.g. &array[3]) where copying begins. 5) You can create a function that tells you what operation to do by passing the command e.g. “ADD”. This is of course just a suggestion and may not fit to your logic. Do what you think is best. 6) Remember that only chars are enclosed in single quotes. So when you're refering to a number, never put any. 7) Never use scanf() for string input. 8) For your sake, please read everything carefully! Sample run: Wilmarc D. Lopez ES26 – THWX1 September 15, 2009 (Wednesday) 1:00pm-4:00pm Matrix Calculator >>DISP A A is not yet initialized! >>MAKE A

Input number of rows: 51 Size is out of bounds! >>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 Operation successful! >>DISP A Matrix A: Number of rows: 3 Number of columns: 2 0 1 2 3 4 5 5 6 7 >>ADD A B B B is not yet initialized! >>add A A A Invalid command! >>ADD a A A Invalid argument! >>SMUL A A A This command will never ever happen! >>EXITC Invalid command! >>EXIT Ciao mother/father! ^_^v

"A C program is like a fast dance on a newly waxed dance floor by people carrying razors" -- Waldi Ravens

More Documents from "Wilmarc"

Mscsgradapp
May 2020 8
09 Es26 Lab - Loops 2
May 2020 14
11 Es26 Lab - Arrays
May 2020 14
08 Es26 Lab - Loops
May 2020 6
13 Es 26 - Strings
May 2020 4