-
Notifications
You must be signed in to change notification settings - Fork 1
/
infinnum.cpp
executable file
·217 lines (195 loc) · 5.67 KB
/
infinnum.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
/*
Programmers: Chhean Saur, Jason Hepp, & Brian Cardarella
Infinite Number Driver Test
*/
#include <iostream.h>
#include <conio.h>
#include "inflist.h"
//#include "infinnum.h"
void UserInterface(void);
// returns true or false on whether or not the SearchKey was found within Options
bool Find(char SearchKey, char Options[], int OptionSize);
void Operator(LIST &A, LIST &B, LIST &Ans, char Operation); // Operators
bool Compare(LIST &A, LIST &B, char Compare); // Compare
void ComputeFunction(LIST &A, LIST &B, LIST &Ans, char Function); // Functions
// for file stream, Output = true for output to a file, Output = False for input from a file
void FileInput(LIST &A, fstream& FileName, bool Output);
void EquateList(LIST &A, LIST &B);
void main()
{
LIST A = 0, B = 0, Ans;
fstream File;
const int NumOfOperator = 6, NumOfCompare = 4, NumOfFunc = 14, NumOfSet = 10;
char Operators[] = "+-/*%^", Compares[] = "<>=!", Functions[] = "DKSPQTVdkspqtv",
SetEquals[] = "WRCELwrcel", choice;
while(choice != 'X' && choice != 'x')
{
cout << "(+)Addition (<)Compare if Less (D)Sum of Digits" << endl
<< "(-)Subtraction (>)Compare if Greater (K)Sum of Digits to Kth Power" << endl
<< "(/)Divide (=)Compare if Equal (S)One Digit Sum" << endl
<< "(%)Modulous (!)Compare Not Equal (P)One Digit Product" << endl
<< "(*)Multiply (Q)Digital Sum Sequence" << endl
<< "(^)Exponent (T)Number Ten" << endl
<< " (V)Number Eleven" << endl
<< "(A)Input A (O)utput A to File" << endl
<< "(B)Input B (I)nput A from File" << endl
<< "(W)Set A=Answer" << endl
<< "(R)Set B=Answer" << endl
<< "(C)Set B=A" << endl
<< "(E)Set A=B" << endl
<< "(L)Clear Answer" << endl
<< "(X)Exit" << endl << endl
<< "All operations are done in terms of A & B: A Function B. " << endl
<< "A = " << A << endl << "B = " << B << endl << "Answer = " << Ans << endl
<< "Please choose an option: ";
cin >> choice;
// cout << endl;
if(choice == 'A' || choice == 'a')
{
// cout << "Enter a value for A: ";
cin >> A;
}
else if(choice == 'B' || choice == 'b')
{
// cout << endl << "Enter a value for B: ";
cin >> B;
}
else if(Find(choice,Operators,NumOfOperator))
Operator(A,B,Ans,choice);
else if(Find(choice,Compares,NumOfCompare))
{
if(Compare(A,B,choice))
{
cout << "True" << endl;
}
else
{
cout << "False" << endl;
}
cout << "Press any key to continue. ";
getch();
}
else if(Find(choice,Functions,NumOfFunc))
ComputeFunction(A,B,Ans,choice);
else if(choice == 'O' || choice == 'o')
{
FileInput(A,File,true);
}
else if(choice == 'I' || choice == 'i')
{
FileInput(A,File,false);
}
else if(Find(choice,SetEquals,NumOfSet))
{
if(choice == 'W' || choice == 'w') // A = Ans
EquateList(A,Ans);
else if(choice == 'R' || choice == 'r') // B = Ans
EquateList(B,Ans);
else if(choice == 'C' || choice == 'c') // B = A
EquateList(B,A);
else if(choice == 'E' || choice == 'e') // A = B
EquateList(A,B);
else if(choice == 'L' || choice == 'l') // Ans = Empty List
Ans.Purge();
}
else if(choice != 'X' && choice !='x')
cout << "Error. Incorrect option choice." << endl;
cout << "Answer = " << Ans << endl;
cout << "Press any key to continue. " << endl;
getch();
}
}
void EquateList(LIST &A, LIST &B)
{
A=B;
}
void FileInput(LIST &A, fstream& FileName, bool Output)
{
if(Output)
{
cout << "Note that A's value will be outputted." << endl;
FileName << A;
}
else
{
cout << "Note that A will assume the value from the input." << endl;
FileName >> A;
}
}
bool Find(char SearchKey, char Options[], int OptionSize)
{
for(int i=0; i < OptionSize; i++)
if(SearchKey == Options[i])
return true;
return false;
}
void ComputeFunction(LIST &A, LIST &B, LIST &Ans, char Function)
{
int Delim;
char PrintAll = 'N';
if(Function == 'D' || Function == 'd')
Ans = A.Sum();
else if(Function == 'K' || Function == 'k')
Ans = A.SumKPower(B);
else if(Function == 'S' || Function == 's')
Ans = A.OneDigitSum();
else if(Function == 'P' || Function == 'p')
Ans = A.OneDigitProduct();
else if(Function == 'Q' || Function == 'q')
Ans = A.DigitSumSeq(B);
// for Number Ten
else if(Function == 'T' || Function == 't')
{
cout << "Enter the Nth number to stop: ";
cin >> Delim;
cout << "Do you wish to print out all the numbers in the sequence? (Y/N): ";
cin >> PrintAll;
if(PrintAll == 'Y' || PrintAll == 'y')
Ans = NumberTen(A,B,Delim,true);
else
Ans = NumberTen(A,B,Delim,false);
}
else if(Function == 'V' || Function == 'v')
{
cout << "Enter the Nth number to stop: ";
cin >> Delim;
cout << "Do you wish to print out all the numbers in the sequence? (Y/N): ";
cin >> PrintAll;
if(PrintAll == 'Y' || PrintAll == 'y')
Ans = NumberEleven(A,B,Delim,true);
else
Ans = NumberEleven(A,B,Delim,false);
}
}
bool Compare(LIST &A, LIST &B, char Compare)
{
if(Compare == '>')
if(A > B) return true;
else return false;
else if(Compare == '<')
if(A < B) return true;
else return false;
else if(Compare == '=')
if(A == B) return true;
else return false;
else
{
if(A != B) return true;
else return false;
}
}
void Operator(LIST &A, LIST &B, LIST &Ans, char Operation)
{
if(Operation == '+')
Ans = A + B;
else if(Operation == '-')
Ans = A - B;
else if(Operation == '*')
Ans = A * B;
else if(Operation == '/')
Ans = A / B;
else if(Operation == '%')
Ans = A % B;
else
Ans = A ^ B;
}