-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complexotron__SEP.cpp
1123 lines (966 loc) · 27.6 KB
/
Complexotron__SEP.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Complexotron.cpp
// Author: Siraj Qazi
// Complexotron v4.2
// Dated: May 29th, 2018
// Class Complexotron's implementation file
#include <iostream> // Standard C++ I/O
#include <iomanip> // Stream Manipulations
#include <string> // Standard C++ <string> class header
#include <fstream> // For file I/O
#include <cctype> // Character testing function prototypes
#include <cmath> // Mathematical Functions
#include <conio.h> // For _getch() Function
#include <Windows.h> // Sleep() Command
#include "Complexotron.h"
using namespace std;
int tempcommandNumber = 0;
int stringCount = 0;
// int editLocation = 0;
Complexotron::Complexotron() // Class Complexotron Constructor
{
// Ask user to set console window font size 36 at startup
cout << "\n Please set this Console Window's Font Size"
<< "\n\n to 36 For the best experience with this Application.\n"
<< "\n Click Window icon(top-left) > Properties > Font > 36 > OK"
<< "\n\n <PRESS ANY KEY WHEN YOU'RE DONE>";
_getch();
// Initializing Memory Arrays:
integerMemory = new int[100];
stringMemory = new string[100];
instructionMemory = new int[100];
decMemory = new double[100];
for (int i = 0; i<100; i++)
{
integerMemory[i] = 0;
instructionMemory[i] = 0;
decMemory[i] = 0.0;
stringMemory[i] = " ";
}
// Initializing Complexotron's Registers:
congregator = 0;
dcongregator = 0.0;
instructionMeasure = 0;
commandID = 0;
location = 0;
commandRgstr = 0;
ifstream passwd("adminPd.txt"); // Read admin password from file
if (!passwd)
adminPasswd = "@complexotron1"; // Set default password
else
passwd >> adminPasswd;
passwd.close();
}
void Complexotron::enterComplexotron() // Startup
{
system("color 0a");
system("cls");
cout << "\n #############################################################################\n\n"
<< " Hydra :: Complexotron\n"
<< " Version 4.2\n"
<< " #############################################################################\n"
<< "\n Logged in: @" << userID << "\n"
<< "\n Welcome to The Complexotron! A Computer that runs programs written in\n"
<< " it's own machine language, a.k.a the Complexotron Machine Language(CML).\n"
<< " \n\n Press "
<< "\n 1 to Enter new program."
<< "\n 2 to Load a source file. "
<< "\n 3 to see documentation on The Complexotron. "
<< "\n 4 to change Administrator password. "
<< "\n 5 to Exit. ";
char choicey = _getch();
switch (choicey)
{
case '1':
enterCML();
break;
case '2':
loadFromFile();
break;
case '3':
documentation();
break;
case '4':
changePasswd();
break;
case '5':
exit(0);
default:
cout << "\n Press 1-4 only.\n <PRESS ANY KEY> ";
_getch();
enterComplexotron();
}
}
void Complexotron::enterCML() // CML Code entry window
{
int commandNumber = 0; // array index
int userInput = 0;
system("cls");
cout << "\n #############################################################################\n\n"
<< " THE COMPLEXOTRON :: CML\n"
<<" Version 4.2\n\n"
<< " #############################################################################\n\n";
cout << " Enter Complexotron Machine Language (CML) Code here:\n"
<< "\n Enter one instruction per line number, and enter sentinel value -1 to\n"
<< " stop entering further instructions.\n Press foward slash(/) to refer to the documentation for CML.\n\n";
cout << noshowpos;
entry:
while (commandNumber < 100)
{
if (commandNumber < 10)
{
cout << " 0";
cout << commandNumber << " > ";
}
else
cout << " "<< commandNumber << " > ";
//cin >> userInput;
char userInputchar[4], c;
int i = 0;
do // Input mechanism: _getch() function rather than std::cin
{
c = _getch(); // so that a keypress is captured, Pressing enter isn't required.
if (c == '-')
{
cout << "-";
c = _getch();
if (c == '1')
{
cout << 1;
userInput = -1;
break;
}
else
continue;
}
else if (c == '/')
documentation();
else if (c == 8) // ASCII For BackSpace key is 8
{
cout << "\b";
i--;
}
if (!isdigit(c))
continue; // Character Exception Handling
cout << c;
userInputchar[i++] = c;
} while (i != 4); // Allow entry of only 4 characters
// afteruserInput:
if (userInput != -1)
{
userInput = atoi(userInputchar); // cout << "\n userInput = " << userInput;
int testVal = userInput / 100; // cout << "\n testVal = " << testVal;
int complexoCommands[30] = { 0,10,11,12,13,20,21,22,23,30,31,21,33,34,35,36,37,38,40,41,42,43,50,51,52,53,54,70,71,99 };
for (int i = 0; i < 30; ++i)
{
// cout << "\n loop running: testVal= " << testVal << " command[" << i << "] = " << complexoCommands[i]<<"\n";
if (testVal == complexoCommands[i])
break;
else if (i == 29 && testVal != complexoCommands[i])
{
cout << " ~ Unrecognized Command. Please enter again.\n\n";
goto entry;
}
}
instructionMemory[commandNumber] = userInput; /*
Save entered instruction
into the instructionMemory[] array
*/
/*--------------------------------
if (editLocation == 0)
{
cout << "\n editLocation = 0";
instructionMemory[commandNumber] = userInput;
}
else
{
cout << "\n editLocation = "<<editLocation;
instructionMemory[editLocation] = userInput;
_getch();
}
//-------------------------------------- */
}
displayCommand(userInput);
cout << endl;
/* while ((userInput < -1 && userInput != -1) || userInput > 9999) // Invalid value check loop
{
cout << "User userInput invalid. Please try again." << endl;
if (commandNumber < 10) {
cout << " 0";
}
cout << commandNumber << " > ";
cin >> userInput;
}
*/
// instructionMemory[commandNumber] = userInput;
if (userInput / 100 == 99)
{
if (instructionMemory[commandNumber] % 100 < 10)
cout << " 0";
cout << instructionMemory[commandNumber] % 100 << " > ";
cin >> instructionMemory[userInput % 100];
//-----------------------------------------
/* editLocation = userInput % 100;
cout << "\n editLocation = " << editLocation<<"\n";
_getch();
//-----------------------------------------
//----------------------------------------- */
/*
int i = 0;
do
{
c = _getch();
if (c == '-')
{
cout << "-";
c = _getch();
if (c == '1')
{
cout << 1;
userInput = -1;
break;
}
else
continue;
}
else if (c == '/')
documentation();
else if (c == 8)
{
cout << "\b";
i--;
}
if (!isdigit(c))
continue; // Character Exception Handling
cout << c;
userInputchar[i++] = c;
} while (i != 4);
goto afteruserInput;
//------------------------------------------ */
}
commandNumber++;
tempcommandNumber = commandNumber;
if (userInput == -1)
{
if (instructionMemory[0] == 0)
instructionMemory[0] = 4300;
for (int i = 0; i < commandNumber; i++)
{
if (instructionMemory[i] / 100 == 70)
{
stringInput();
break; /* So that the duplication
of for loops doesnt occur,
i.e. once this for loop and then
again the for loop inside
stringInput()*/
}
}
break; /* Break out of the main userInput while loop
(while commandNumber < 100)
To stop entering further instructions */
}
}
// Successfully loaded.
loadedSuccessfully();
}
void Complexotron::execute() {
while (instructionMeasure < 100)
{
commandRgstr = instructionMemory[instructionMeasure];
if ((instructionMemory[instructionMeasure++] / 100 )!= 70)
CML();
}
}
void Complexotron::CML() // Complexotron's Core Processing Function
{
commandID = commandRgstr / 100;
location = commandRgstr % 100;
switch (commandID) // MASTER SWITCH : CPU OF COMPLEXOTRON
{
case READ:
cin >> integerMemory[location];
break;
case WRITE:
cout << "\n "<< integerMemory[location] << endl;
break;
case READ_DECIMAL:
cin >> decMemory[location];
break;
case WRITE_DECIMAL:
cout << "\n " << decMemory[location] << endl;
break;
case LOAD:
congregator = integerMemory[location];
break;
case STORE:
integerMemory[location] = congregator;
break;
case LOAD_DECIMAL:
dcongregator = decMemory[location];
break;
case STORE_DECIMAL:
decMemory[location] = dcongregator;
break;
case ADD:
congregator += integerMemory[location];
break;
case SUBTRACT:
congregator -= integerMemory[location];
break;
case MULTIPLY:
congregator *= integerMemory[location];
break;
case DIVIDE:
if (integerMemory[location] == 0)
showError("divide0");
else
congregator /= integerMemory[location];
break;
case POWER:
{
int power = congregator;
for (int i = 1; i < integerMemory[location]; ++i)
congregator *= power;
}
break;
case ADD_DECIMAL:
dcongregator += decMemory[location];
break;
case SUBTRACT_DECIMAL:
dcongregator -= decMemory[location];
break;
case MULTIPLY_DECIMAL:
dcongregator *= decMemory[location];
break;
case DIVIDE_DECIMAL:
if (decMemory[location] == 0.0)
showError("divide0");
else
dcongregator /= decMemory[location];
break;
case POWER_DECIMAL:
{
double power = dcongregator;
for (int i = 1; i < decMemory[location] ; ++i)
dcongregator *= power;
}
break;
case LOG:
dcongregator = log(decMemory[location]);
break;
case SIN:
dcongregator = sin(decMemory[location]);
break;
case COS:
dcongregator = cos(decMemory[location]);
break;
case TAN:
dcongregator = tan(decMemory[location]);
break;
case GOTO:
instructionMeasure = location;
break;
case GOTO_IF_NEG:
if (congregator < 0)
instructionMeasure = location;
break;
case GOTO_IF_ZERO:
if (congregator == 0)
instructionMeasure = location;
break;
case GOTO_IF_NEG_DECIMAL:
if (dcongregator < 0)
instructionMeasure = location;
break;
case GOTO_IF_ZERO_DECIMAL:
if (dcongregator == 0)
instructionMeasure = location;
break;
/* This part is never executed, cz of the if condition
in the while loop of execute()
case READ_STRING:
cout << "\n Enter string in case READ STRING";
getline(cin, stringMemory[location]);
break;
*/
case WRITE_STRING:
cout << "\n "<<stringMemory[location]<<endl;
break;
case STOP:
cout << "------- Complexotron execution Completed -------" << endl;
_getch();
printStats();
instructionMeasure = 100;
break;
case EDIT:
break;
default:
cout << "Invalid userInput";
cout << "\n InstructionMemory[location]:: " << instructionMemory[location]<<"\n";
}
}
void Complexotron::printStats()
{
system("cls");
system("color 0b");
cout << "\n #############################################################################\n\n"
<< " THE COMPLEXOTRON :: Memory Stats\n\n"
<< " #############################################################################\n\n";
cout << "\n COMPLEXOTRON MEMORY REGISTERS:" << endl;
cout << "\n congregator: " << showpos << setw(5) << setfill('0') << congregator << endl;
cout << "\n instructionMeasure: " << showpos << setw(2) << setfill('0') << instructionMeasure << endl;
cout << "\n commandRgstr: " << showpos << setw(5) << setfill('0') << commandRgstr << endl;
cout << "\n commandID: " << showpos << setw(2) << setfill('0') << commandID << endl;
cout << "\n location: " << showpos << setw(2) << setfill('0') << location << endl;
cout << "\n UserID: " << userID << endl;
cout << "" << endl;
cout << "\n\n";
// Instruction Memory
cout << "\n INSTRUCTION MEMORY:" << endl;
cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
cout << "00 ";
for (int i = 0; i < 10; i++) {
cout << showpos << setw(5) << setfill('0') << instructionMemory[i] << " ";
}
cout << endl;
for (int j = 10; j < 100; j+= 10)
{
cout << noshowpos << j << " ";
for (int i = 0; i < 10; ++i) {
cout << showpos << setw(5) << setfill('0') << instructionMemory[j + i] << " ";
}
cout << endl;
}
// Integer Memory
cout << "\n INTEGER MEMORY:" << endl;
cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
cout << "00 ";
for (int i = 0; i < 10; i++) {
cout << showpos << setw(6) << setfill('0') << integerMemory[i] << " ";
}
cout << endl;
for (int j = 10; j < 100; j+= 10)
{
cout << noshowpos << j << " ";
for (int i = 0; i < 10; i++) {
cout << showpos << setw(6) << setfill('0') << integerMemory[j + i] << " ";
}
cout << endl;
}
cout << "\n DECIMAL MEMORY:" << endl;
cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
cout << "00 ";
for (int i = 0; i < 10; ++i) {
cout << showpos << setw(6) << setfill('0') << decMemory[i] << " ";
}
cout << endl;
for (int j = 10; j < 100; j += 10)
{
cout << noshowpos << j << " ";
for (int i = 0; i < 10; ++i) {
cout << showpos << setw(6) << setfill('0') << decMemory[j + i] << " ";
}
cout << endl;
}
// String Memory
cout << noshowpos << "\n STRING MEMORY:\n" << endl;
for (int i = 0; i < stringCount; ++i)
{
if (i < 10)
{
cout << " 0";
cout << i;
}
else
cout << " " << i;
cout << " " << stringMemory[i]<<"\n";
}
_getch();
enterComplexotron();
}
void Complexotron::showError(string errorType)
{
if (errorType == "dividebyZero") {
cout << "An attempt was made to divide by 0. The program will terminate." << endl;
instructionMeasure = 100;
printStats();
}
else
{
cout << "\n An Exception occured.\n";
instructionMeasure = 100;
printStats();
}
}
void Complexotron::loadFromFile()
{
string fileName;
cout << "\n\n Enter the name of the file(with type extension):\n > ";
cin >> fileName;
ifstream inFile(fileName);
if (!inFile)
{
cout << "\n File couldn't be opened.\n";
_getch();
enterComplexotron();
}
cout << "\n\n Reading instructions from file";
for (int i = 0; i<5; ++i)
{
Sleep(130);
cout << ".";
}
cout << "\n\n";
for (int x = 0; !inFile.eof(); ++x) // Read from the file until EndOfFile(EOF)
{
inFile >> instructionMemory[x];
cout <<"\n "<< instructionMemory[x];
displayCommand(instructionMemory[x]);
tempcommandNumber++;
Sleep(100);
}
stringInput();
loadedSuccessfully();
}
void Complexotron::saveToFile() // Function to output code to a file
{
string fileName;
cout << "\n Enter the file name you want to save this CML Code to:\n > ";
cin >> fileName;
fileName.append(".txt");
ofstream outFile(fileName);
if (!outFile)
{
cout << "\n File couldn't be created.\n";
_getch();
exit(0);
}
cout << "\n\n Saving Program to file";
for (int i = 0; i<5; ++i)
{
Sleep(130);
cout << ".";
}
cout << "\n";
for (int x = 0; x < tempcommandNumber; ++x)
{
outFile << instructionMemory[x]<<"\n";
cout << "\n " << instructionMemory[x];
displayCommand(instructionMemory[x]);
Sleep(100);
}
cout << "\n File saved successfully. \n <PRESS ANY KEY> ";
_getch();
enterComplexotron();
exit(0);
}
void Complexotron::loadedSuccessfully()
{
int loop = 5;
cout << "\n Building program";
while (loop-- >= 0) //Loading Animation
{
Sleep(100);
cout << ".";
}
cout << "\n\n Program loaded successfully.\n";
loaded:
cout << "\n\n Press"
<< "\n 1 To Execute Program."
<< "\n 2 to Save program to a file."
<< endl;
char x = _getch();
switch (x)
{
case '1':
cout << "\n";
system("cls");
cout << "\n ------------------------- OUTPUT CONSOLE --------------------------\n\n";
break;
case '2':
saveToFile();
default:
cout << "\n Press 1-2 ?\n ";
goto loaded;
}
execute();
}
void Complexotron::Start() // Startup function, with login
{
string pass;
string username;
char password[100];
system("cls");
cout << "\n -----------------------------------------------------------------------------"
<< "\n The COMPLEXOTRON :: LOGIN CONSOLE"
<< "\n -----------------------------------------------------------------------------"
<< endl;
cout << "\n\n Enter Login ID: > ";
cin >> userID;
if (userID == "admin")
{
int i = 0;
cout << "\n Enter password: > ";
char c = _getch();
while (c != 13) // Accept input until Enter(ASCII 13) is pressed.
{
if (c == 8) // Allow Backspace for erasing characters
{
if (i == 0);
else
{
password[--i] = '\0';
cout << "\b \b";
}
}
else
{
password[i++] = c;
cout << "*";
}
c = _getch();
}
password[i] = '\0'; // Terminate the string in memory
if (password == adminPasswd)
{
loading();
exit(0);
}
else
{
cout << "\n\n The password is INCORRECT.\n" << endl;
_getch();
Start();
}
}
username = userID;
username.append(".txt");
ifstream saveData(username); // Open the file corresponding to userID
if (!saveData)
{
cout << "\n Authentication Error: No such account exists in the "
<< " Complexotron DataBase." << endl;
_getch();
Start();
}
else
{
int i = 0;
cout << "\n Enter password: > ";
char c = _getch();
while (c != 13) // Accept input until Enter(ASCII 13) is pressed.
{
if (c == 8) // Allow Backspace for erasing characters
{
if (i == 0);
else
{
password[--i] = '\0';
cout << "\b \b";
}
}
else
{
password[i++] = c;
cout << "*";
}
c = _getch();
}
password[i] = '\0'; // Terminate the string in memory
saveData >> pass; // Read password from file
if (password == pass)
{
loading();
exit(0);
}
else
{
cout << "\n\n The password is INCORRECT.\n" << endl;
_getch();
Start();
}
}
}
void Complexotron::loading()
{
system("color 0b");
system("cls");
cout << "\n\n Logging you in ";
for (int i = 0; i < 5; ++i) // Rotating '/' animation
{
Sleep(105);
cout << "\b\\" << flush;
Sleep(105);
cout << "\b|" << flush;
Sleep(105);
cout << "\b/" << flush;
Sleep(105);
cout << "\b--" << flush;
}
system("cls");
system("color 0e");
cout << "\n\n Fetching data ";
for (int i = 0; i < 5; ++i)
{
Sleep(105);
cout << "\b\\" << flush;
Sleep(105);
cout << "\b|" << flush;
Sleep(105);
cout << "\b/" << flush;
Sleep(105);
cout << "\b--" << flush;
}
enterComplexotron();
}
void Complexotron::documentation()
{
system("color 0e");
system("cls");
cout << "\n #############################################################################\n\n"
<< " THE COMPLEXOTRON :: User Guide\n\n"
<< " #############################################################################\n\n";
cout << "\n Welcome to the User Guide for The Complexotron!"
<< "\n\n On this page you will find all the details on how to operate this "
<< "\n Hybrid Machine Language Simulation (HMLS)."
<< "\n\n Below is a list of ML Codes of all the available commands\n in The Complexotron:"
<< "\n" << endl;
cout << "\tCML COMMAND\tINSTRUCTION CODE & DESCRIPTION\n"
<< " -------------------------------------------------------------\n";
cout << "\n \tREAD\t\t| 10\tRead a number from the keyboard."
"\n \tWRITE\t\t| 11\tWrite a number onto the screen."
"\n \tLOAD\t\t| 20\tLoad a number to the CONGREGATOR."
"\n \tSTORE\t\t| 21\tStore the CONGREGATOR RESULT into memory."
"\n \tADD\t\t| 30\tAdd a number to the CONGREGATOR."
"\n \tSUBTRACT\t| 31\tSubtract a number from the CONGREGATOR."
"\n \tDIVIDE\t\t| 32\tDivide the CONGREGATOR by a number."
"\n \tMULTIPLY\t| 33\tMultiply the CONGREGATOR by a number."
"\n \tPOWER\t\t| 34\tRaise to power the CONGREGATOR."
"\n \tLOG\t\t| 35\tCalculate log() of CONGREGATOR."
"\n \tSIN\t\t| 36\tCalculate sin() of CONGREGATOR."
"\n \tCOS\t\t| 37\tCalculate cos() of CONGREGATOR."
"\n \tTAN\t\t| 38\tCalculate tan() of CONGREGATOR."
"\n \tGOTO\t\t| 40\tGOTO a specified LINE NUMBER."
"\n \tGOTO_IF_NEG\t| 41\tGoto a line if CONGREGATOR is negative."
"\n \tGOTO_IF_ZERO\t| 42\tGoto a line if CONGREGATOR is zero."
"\n \tSTOP\t\t| 43\tEnd of program."
"\n \tREAD_STRING\t| 70\tRead a string from the user."
"\n \tWRITE_STRING\t| 71\tWrite a string tto the screen."
"\n \tEDIT\t\t| 99\tEdit a line."
;
cout << "\n\n -------- DECIMAL MANIPULATIONS ----------\n";
cout<< "\n \tREAD_DECIMAL\t| 12\tRead a decimal number from the keyboard."
"\n \tWRITE_DECIMAL\t| 13\tWrite a decimal number on the screen."
"\n \tLOAD_DECIMAL\t| 22\tLoad a decimal number into the dcongregator."
"\n \tSTORE_DECIMAL\t| 23\tStore the dcongregator into a memory location."
"\n \tADD_DECIMAL\t| 50\tAdd a decimal number to the dcongregator."
"\n \tSUBTRACT_DECIMAL| 51\tSubtract a decimal number from dcongregator."
"\n \tDIVIDE_DECIMAL\t| 52\tDivide the dcongregator by a decimal number."
"\n \tMULTIPLY_DECIMAL| 53\tMultiply a decimal number to the dcongregator."
"\n \tPOWER_DECIMAL\t| 54\tRaise the dcongregator to a power."
<< endl;
cout << "\n\n < PRESS ANY KEY TO LAUNCH COMPLEXOTRON AGAIN > ";
_getch();
enterComplexotron();
}
void Complexotron::stringInput()
{
cout << "\n\n ----------- Preprocessing dependencies ----------------\n";
for (int i = 0; i < tempcommandNumber; i++)
{
if (instructionMemory[i] / 100 == 70)
{
stringCount++;
cout << "\n Enter string["<< instructionMemory[i] % 100<<"]: ";
cin.ignore();
getline(cin, stringMemory[instructionMemory[i] % 100]);
}
}
}
void Complexotron::displayCommand(int instruction)
{
if (instruction == -1)
cout << "\t\tBEGIN CODE EXECUTION ";
else
{
int commandID = instruction / 100;
int location = instruction % 100;
switch (commandID)
{
case READ:
cout << "\t\tREAD into integerMemory[" << location << "]";
break;
case WRITE:
cout << "\t\tWRITE integerMemory[" << location << "] to std::out";
break;
case READ_DECIMAL:
cout << "\t\tREAD into decimalMemory[" << location << "]";
break;
case WRITE_DECIMAL:
cout << "\t\tWRITE decimalMemory[" << location << "] to std::out";
break;
case LOAD:
cout << "\t\tLOAD " << "integerMemory[" << location << "] into CONGREGATOR";
break;
case STORE:
cout << "\t\tSTORE CONGREGATOR to integerMemory[" << location << "]";
break;
case LOAD_DECIMAL:
cout << "\t\tLOAD " << "decMemory[" << location << "] into decimalCONGREGATOR";
break;
case STORE_DECIMAL:
cout << "\t\tSTORE decimalCONGREGATOR to decMemory[" << location << "]";
break;
case ADD:
cout << "\t\tADD " << "integerMemory[" << location << "] TO CONGREGATOR";
break;
case SUBTRACT:
cout << "\t\tSUBTRACT " << "integerMemory[" << location << "] FROM CONGREGATOR";
break;
case MULTIPLY:
cout << "\t\tMULTIPLY CONGREGATOR BY integerMemory[" << location << "]";
break;
case DIVIDE:
cout << "\t\tDIVIDE CONGREGATOR BY integerMemory[" << location << "]";
break;
case POWER:
cout << "\t\tEXPONENTIATE CONGREGATOR TO integerMemory[" << location<<"]";
break;
case ADD_DECIMAL:
cout << "\t\tADD decMemory[" << location << "] TO decimalCONGREGATOR";
break;
case SUBTRACT_DECIMAL:
cout << "\t\tSUBTRACT decMemory[" << location << "] FROM decimalCONGREGATOR";
break;
case MULTIPLY_DECIMAL:
cout << "\t\tMULTIPLY decimalCONGREGATOR BY decMemory[" << location << "]";
break;
case DIVIDE_DECIMAL:
cout << "\t\tDIVIDE decimalCONGREGATOR BY " << "decMemory[" << location << "]";
break;
case POWER_DECIMAL:
cout << "\t\tEXPONENTIATE decimalCONGREGATOR TO decMemory[" << location<<"]";
break;
case LOG:
cout << "\t\tSTORE LOG OF integerMemory[" << location << "] TO CONGREGATOR";
break;
case SIN:
cout << "\t\tSTORE SIN OF integerMemory[" << location << "] TO CONGREGATOR";
break;
case COS:
cout << "\t\tSTORE COS OF integerMemory[" << location << "] TO CONGREGATOR";
break;
case TAN:
cout << "\t\tSTORE TAN OF integerMemory[" << location << "] TO CONGREGATOR";
break;
case GOTO:
cout << "\t\tGOTO LINE " << location;