-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalculatorInterface.cpp
86 lines (73 loc) · 2.35 KB
/
CalculatorInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "CalculatorInterface.h"
CalculatorInterface::CalculatorInterface() {
instructions = Instruction();
}
void CalculatorInterface::start() {
// Method to start the interactive terminal for application commands
std::cout << "Welcome to Programmable Calculator" << std::endl;
int i = 1;
while(i == 1) {
displayMessage();
std::getline(std::cin, input);
switch(input[0]) {
case 'i' : {
std::cout << "i pressed" << std::endl;
command_i();
}
break;
case 'd' : std::cout << "d pressed" << std::endl;
command_d();
break;
case 'r' : {
std::cout << "r pressed" << std::endl;
command_r();
}
break;
case 'c' : std::cout << "c pressed" << std::endl;
command_c();
break;
case 'p' : {
std::cout << "p pressed" << std::endl;
command_p();
}
break;
case 'q' : {
std::cout << "Thank you" << std::endl;
std::cout << "Created by Vasanth Pandiarajan - UIN 672498535" << std::endl;
i = 0;
}
break;
default:
std::cout << "Invalid Input" << std::endl;
}
}
}
void CalculatorInterface::displayMessage() {
std::cout << "Enter 'i <filename>' to specify the input file with the instructions" << std::endl;
std::cout << "Enter d to debug - Should have selected i and specified files earlier" << std::endl;
std::cout << "Enter r to run the instructions" << std::endl;
std::cout << "Enter c to run additional 100 instructions" << std::endl;
std::cout << "Enter p print the values" << std::endl;
std::cout << "Enter q to quit" << std::endl;
}
void CalculatorInterface::command_i() {
std::string filename = input.substr(2);
instructions.readInstructionsFromFile(filename);
std::vector<std::string> vector1 = instructions._instruction_set();
for(int i = 0 ; i < vector1.size(); i++) {
std::cout << vector1[i] << std::endl;
}
}
void CalculatorInterface::command_r() {
instructions.execute_all();
}
void CalculatorInterface::command_d() {
instructions.debug();
}
void CalculatorInterface::command_p() {
instructions.print_instructions();
instructions.display_registers();
}
void CalculatorInterface::command_c() {
instructions.continue_execution();
}