Commit abe3c2dd authored by Laura's avatar Laura

Lazarus - Teamwork4 - Version 4

parent df43c072
......@@ -81,6 +81,18 @@ MiniComputer::executeCommand(int command)
return 1;
}
int
MiniComputer::loadRegister(std::string registerName)
{
std::cout << "Load into " << registerName << "\n"
<< "Input the value to load into register " << registerName << ".\n"
<< registerName << ": ";
int number;
std::cin >> number;
std::cout << registerName << " = " << number << "\n" << std::endl;
return number;
}
int
MiniComputer::executeLoadCommand()
{
......@@ -93,35 +105,19 @@ MiniComputer::executeLoadCommand()
int registerNumber;
std::cin >> registerNumber;
if (0 == registerNumber) {
std::cout << "Load into a\n"
<< "Input the value to load into register a.\n"
<< "a: ";
std::cin >> a_;
std::cout << "a = " << a_ << "\n" << std::endl;
a_ = loadRegister("a");
return 0;
}
if (1 == registerNumber) {
std::cout << "Load into b\n"
<< "Input the value to load into register b.\n"
<< "b: ";
std::cin >> b_;
std::cout << "b = " << b_ << "\n" << std::endl;
b_ = loadRegister("b");
return 0;
}
if (2 == registerNumber) {
std::cout << "Load into c\n"
<< "Input the value to load into register c.\n"
<< "c: ";
std::cin >> c_;
std::cout << "c = " << c_ << "\n" << std::endl;
if (2 == registerNumber) {
c_ = loadRegister("c");
return 0;
}
if (3 == registerNumber) {
std::cout << "Load into d\n"
<< "Input the value to load into register d.\n"
<< "d: ";
std::cin >> d_;
std::cout << "d = " << d_ << "\n" << std::endl;
d_ = loadRegister("d");
return 0;
}
/// error case
......@@ -159,22 +155,18 @@ MiniComputer::executeAddCommand()
return 2;
}
if (0 == registerNumber1) {
std::cout << a_ << std::endl;
inputRegister1 = a_;
registerLetter1 = "a";
}
if (1 == registerNumber1) {
std::cout << b_ << std::endl;
inputRegister1 = b_;
registerLetter1 = "b";
}
if (2 == registerNumber1) {
std::cout << c_ << std::endl;
inputRegister1 = c_;
registerLetter1 = "c";
}
if (3 == registerNumber1) {
std::cout << d_ << std::endl;
inputRegister1 = d_;
registerLetter1 = "d";
}
......@@ -193,22 +185,18 @@ MiniComputer::executeAddCommand()
return 2;
}
if (0 == registerNumber2) {
std::cout << a_ << std::endl;
inputRegister2 = a_;
registerLetter2 = "a";
}
if (1 == registerNumber2) {
std::cout << b_ << std::endl;
inputRegister2 = b_;
registerLetter2 = "b";
}
if (2 == registerNumber2) {
std::cout << c_ << std::endl;
inputRegister2 = c_;
registerLetter2 = "c";
}
if (3 == registerNumber2) {
std::cout << d_ << std::endl;
inputRegister2 = d_;
registerLetter2 = "d";
}
......@@ -246,7 +234,7 @@ MiniComputer::executeAddCommand()
inputRegister3 = inputRegister1 + inputRegister2;
d_ = inputRegister3;
}
std::cout << registerNumber3 << "\n" << registerLetter3 << " = " << registerLetter1 << " + " << registerLetter2 << " = " << inputRegister1 << " + " << inputRegister2 << " = " << inputRegister3 << "\n" << std::endl;
std::cout << registerLetter3 << " = " << registerLetter1 << " + " << registerLetter2 << " = " << inputRegister1 << " + " << inputRegister2 << " = " << inputRegister3 << "\n" << std::endl;
return 0;
}
......@@ -269,19 +257,19 @@ MiniComputer::executePrintCommand()
int registerNumber;
std::cin >> registerNumber;
if (0 == registerNumber) {
std::cout << registerNumber << "\n" << a_ << std::endl;
std::cout << a_ << "\n" << std::endl;
return 0;
}
if (1 == registerNumber) {
std::cout << registerNumber << "\n" << b_ << std::endl;
std::cout << b_ << "\n" << std::endl;
return 0;
}
if (2 == registerNumber) {
std::cout << registerNumber << "\n" << c_ << std::endl;
std::cout << c_ << "\n" << std::endl;
return 0;
}
if (3 == registerNumber) {
std::cout << registerNumber << "\n" << d_ << std::endl;
std::cout << d_ << "\n" << std::endl;
return 0;
}
std::cerr << "Error 2: Register not found!" << std::endl;
......@@ -291,7 +279,7 @@ MiniComputer::executePrintCommand()
std::string line;
std::cout << "> String: ";
std::cin.ignore(commandRegister, '\n');
std::getline (std::cin, line);
std::getline(std::cin, line);
if (line.length() > commandRegister) {
line = line.substr(0, commandRegister);
}
......@@ -300,10 +288,9 @@ MiniComputer::executePrintCommand()
line += " ";
goto start;
}
std::cout << line << "!" << std::endl;
std::cout << line << "\n" << std::endl;
return 0;
}
std::cerr << "Error 2: Register not found!" << std::endl;
return 2;
}
......@@ -12,7 +12,7 @@ private:
int getMainCommand();
int executeCommand(int command);
int executeLoadCommand();
void loadRegister(int register);
int loadRegister(std::string register);
int executeStoreCommand();
int executeAddCommand();
int executePrintCommand();
......@@ -23,4 +23,3 @@ private:
int c_;
int d_;
};
......@@ -8,4 +8,3 @@ main()
MiniComputer mini("Mini");
return mini.run();
}
......@@ -31,4 +31,3 @@ test1: MiniComputer
.PRECIOUS: main.ii main.s
.SECONDARY: main.ii main.s
......@@ -46,10 +46,7 @@ Command Set
2 - c
3 - d
> Register1: 10
> Register2: 5
> Register3: 2
c = a + b = 10 + 5 = 15
> Register1: > Register2: > Register3: c = a + b = 10 + 5 = 15
Command Set
0 – exit
......@@ -68,8 +65,8 @@ N – String Length
2 - c
3 - d
> Register: 2
15
> Register: 15
Command Set
0 – exit
1 – load
......@@ -81,7 +78,8 @@ Command Set
0 – Register
N – String Length
> Print: > String: 5!
> Print: > String: here
Command Set
0 – exit
1 – load
......@@ -89,4 +87,4 @@ Command Set
3 – print
4 – add
> Command:
> Command:
\ No newline at end of file
......@@ -6,7 +6,6 @@
3 0 2
3 1 5 I am here
3 5 I am here
0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment