8 bool FloatToString(char * string, float * value)
11 *value = (float)strtod(string, &end);
18 PrintLn("Chose an operation to perform: +, -, *, /, m (module/length). q to quit.");
25 case '+': case '-': case '*': case '/': case 'm': case 'q':
29 PrintLn("Invalid Operation");
40 while(!FloatToString(input, &scalar))
42 PrintLn("Print enter a valid numeric value");
53 while(!vector.OnGetDataFromString(input))
55 PrintLn("Print enter a valid 2D vector value");
61 class Lab5VectorApp : Application
67 Vector vector1, vector2;
69 char operation = GetOperation();
70 if(operation == 'q') break;
72 PrintLn("Enter the first operand:");
73 vector1 = GetVector();
77 PrintLn("Enter the second operand:");
78 if(operation == '+' || operation == '-')
79 vector2 = GetVector();
83 if(operation == '/' && scalar == 0)
84 PrintLn("Cannot divide by 0");
89 case '+': PrintLn(vector1, " + ", vector2, " = ", Vector { vector1.x + vector2.x, vector1.y + vector2.y }); break;
90 case '-': PrintLn(vector1, " - ", vector2, " = ", Vector { vector1.x - vector2.x, vector1.y - vector2.y }); break;
91 case '*': PrintLn(vector1, " * ", scalar, " = ", Vector { vector1.x * scalar, vector1.y * scalar }); break;
92 case '/': PrintLn(vector1, " / ", scalar, " = ", Vector { vector1.x / scalar, vector1.y / scalar }); break;
93 case 'm': PrintLn("|",vector1,"| = ", sqrt(vector1.x * vector1.x + vector2.y * vector2.y)); break;