check if command is dot or cross
This commit is contained in:
parent
4e24b69d89
commit
fd06b99890
50
src/main.nim
50
src/main.nim
|
@ -1,52 +1,52 @@
|
||||||
import strutils, sequtils, os, procedures, strformat
|
import strutils, sequtils, os, procedures, strformat
|
||||||
|
# TODO: while loop to check if inputs are valid
|
||||||
|
|
||||||
var operation: string
|
var operation: string
|
||||||
case paramStr(0):
|
# if command is "dot" or "cross" preform that operation
|
||||||
of "dot":
|
if paramStr(0).endsWith("/dot") or paramStr(0) == "dot":
|
||||||
operation = "dot"
|
operation = "dot"
|
||||||
echo "Parameter is dot"
|
echo "Calculating the dot product:"
|
||||||
of "cross":
|
elif paramStr(0).endsWith("/cross") or paramStr(0) == "cross":
|
||||||
operation = "cross"
|
operation = "cross"
|
||||||
echo "Parameter is cross"
|
echo "Calculating the cross product:"
|
||||||
else:
|
else:
|
||||||
# TODO: ask user to preform dot or cross product
|
echo "Would you like to preform the dot or cross product?"
|
||||||
echo "multrix"
|
operation = readLine(stdin)
|
||||||
|
|
||||||
|
|
||||||
|
# record first matrix
|
||||||
echo "Enter number of rows in the first matrix:"
|
echo "Enter number of rows in the first matrix:"
|
||||||
let r1: int = parseInt(readLine(stdin))
|
let r1: int = parseInt(readLine(stdin))
|
||||||
echo "Enter number of columns in the first matrix:"
|
echo "Enter number of columns in the first matrix:"
|
||||||
let c1: int = parseInt(readLine(stdin))
|
let c1: int = parseInt(readLine(stdin))
|
||||||
var m1 = newSeqWith(r1, newSeq[float](c1))
|
var m1 = newSeqWith(r1, newSeq[float](c1))
|
||||||
|
|
||||||
procedures.fillMatrix(m1, r1, c1)
|
procedures.fillMatrix(m1, r1, c1)
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# record second matrix
|
||||||
echo "Enter number of rows in the second matrix:"
|
echo "Enter number of rows in the second matrix:"
|
||||||
let r2: int = parseInt(readLine(stdin))
|
let r2: int = parseInt(readLine(stdin))
|
||||||
echo "Enter number of columns in the second matrix:"
|
echo "Enter number of columns in the second matrix:"
|
||||||
let c2: int = parseInt(readLine(stdin))
|
let c2: int = parseInt(readLine(stdin))
|
||||||
var m2 = newSeqWith(r2, newSeq[float](c2))
|
var m2 = newSeqWith(r2, newSeq[float](c2))
|
||||||
|
|
||||||
procedures.fillMatrix(m2, r2, c2)
|
procedures.fillMatrix(m2, r2, c2)
|
||||||
|
|
||||||
|
# resultent matrix
|
||||||
# calculate dot product (in procedures)
|
|
||||||
|
|
||||||
var m = newSeqWith(0, newSeq[float](0))
|
var m = newSeqWith(0, newSeq[float](0))
|
||||||
m = dot(m1, m2)
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: calculate cross product (in procedures)
|
|
||||||
|
|
||||||
|
case operation:
|
||||||
|
of "dot":
|
||||||
|
m = dot(m1, m2) # calculate dot product (in procedures)
|
||||||
|
of "cross":
|
||||||
|
echo "*do cross product*" # TODO: calculate cross product (in procedures)
|
||||||
|
else:
|
||||||
|
quit "Invalid matrix operation!", QuitFailure
|
||||||
|
|
||||||
echo "\nFirst matrix is:"
|
echo "\nFirst matrix is:"
|
||||||
procedures.printMatrix(m1)
|
printMatrix(m1)
|
||||||
|
|
||||||
echo "\nSecond matrix is:"
|
echo "\nSecond matrix is:"
|
||||||
procedures.printMatrix(m2)
|
printMatrix(m2)
|
||||||
|
|
||||||
echo "\nResult matrix is:"
|
echo "\nResult matrix is:"
|
||||||
procedures.printMatrix(m)
|
printMatrix(m)
|
Loading…
Reference in a new issue