-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBasicApp.cs
254 lines (215 loc) · 8.73 KB
/
BasicApp.cs
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
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
namespace JetOS
{
/// <summary>
///
/// </summary>
class BasicApp
{
/// <summary>
///
/// </summary>
public void Plus()
{
Console.WriteLine("Plus App");
Console.Write("A=");
float a, b, c;
string a_input = Console.ReadLine();
Console.Write("B=");
string b_input = Console.ReadLine();
a = float.Parse(a_input);
b = float.Parse(b_input);
c = a + b;
Console.WriteLine("Output: {0}", c.ToString());
}
public void Multiply()
{
Console.WriteLine("Multiply App");
Console.Write("A=");
float a, b, c;
string a_input = Console.ReadLine();
Console.Write("B=");
string b_input = Console.ReadLine();
a = float.Parse(a_input);
b = float.Parse(b_input);
c = a * b;
Console.WriteLine("Output: {0}", c.ToString());
}
public void Minus()
{
Console.WriteLine("Minus App");
Console.Write("A=");
float a, b, c;
string a_input = Console.ReadLine();
Console.Write("B=");
string b_input = Console.ReadLine();
a = float.Parse(a_input);
b = float.Parse(b_input);
c = a - b;
Console.WriteLine("Output: {0}", c.ToString());
}
public void Divide()
{
Console.WriteLine("Divide App");
Console.Write("A=");
float a, b, c;
string a_input = Console.ReadLine();
Console.Write("B=");
string b_input = Console.ReadLine();
a = float.Parse(a_input);
b = float.Parse(b_input);
c = a / b;
Console.WriteLine("Output: {0}", c.ToString());
}
public void RandomApp()
{
Random ran = new Random();
Console.WriteLine("Output: {0}", ran.ToString());
}
string DecimalConvertTo(string mode, int value)
{
// Since COSMOS needed plugs for native functions, Convert.ToString(Int, Int32) is unusable
string result = "";
switch (mode)
{
case "binary":
switch(value)
{
case 0:
result = "0";
break;
case 1:
result = "1";
break;
default:
while (value >= 2)
{
if (value % 2 == 1)
{
result += "1";
value = (value - (value % 2)) / 2;
} else
{
result += "0";
value = value / 2;
}
}
result += "1";
char[] charArray = result.ToCharArray();
Array.Reverse(charArray);
result = new string(charArray);
break;
}
break;
case "octal":
if (value < 8)
{
result = value.ToString();
} else
{
int val = 0;
while (value >= 8)
{
double logbase = Math.Floor(Math.Log(value, 8));
int times = Convert.ToInt32(Math.Floor(value / Math.Pow(8, logbase)));
value = Convert.ToInt32(value - times*Math.Pow(8, logbase));
val += Convert.ToInt32(times*Math.Pow(10, logbase));
}
val += value;
result = val.ToString();
}
break;
case "hexadecimal":
result = "0x" + value.ToString("X");
break;
}
return result;
}
public void DecimalConverter()
{
// try
// {
bool ProcessEnded = false;
Console.WriteLine("Welcome to DECIMAL TO OTHERS CONVERTER for JetOS");
while (ProcessEnded == false)
{
Console.WriteLine("Which type of number do you want to convert into?");
Console.WriteLine("\t0. Binary\n\t1. Octal\n\t2. Hexadecimal\n\n\n\t3. Exit Program");
Console.Write("> ");
string num = Console.ReadLine();
int command;
if (int.TryParse(num, out command) == false)
{
Console.WriteLine("Please type a valid number value! (Must be integer)");
}
else
{
string mode = "";
switch (command)
{
case 0:
mode = "binary";
break;
case 1:
mode = "octal";
break;
case 2:
mode = "hexadecimal";
break;
case 3:
Console.WriteLine("Thank you for using the converter! See you soon!");
ProcessEnded = true;
break;
default:
Console.WriteLine("Cannot find any functions for conversion assigned to that number. Please try again!");
break;
}
if (mode != "")
{
bool convertFinished = false;
while (convertFinished == false)
{
Console.WriteLine("Please type your number (must be not less than 0)");
Console.Write(">> ");
int dec;
string number = Console.ReadLine();
if (int.TryParse(number, out dec) == true)
{
if (dec >= 0)
{
string result = DecimalConvertTo(mode, dec);
Console.WriteLine("Output result: " + result);
}
else
{
Console.WriteLine("CONVERSION FAILED!\nReason: Your input value is a negative integer!");
}
}
else
{
Console.WriteLine("CONVERSION FAILED!\nReason: Invaild input value!");
}
Console.WriteLine("Do you want to convert again into the same number type?");
Console.WriteLine("Type: 'Y' if you want to, or else type any value to finish.");
Console.Write("> ");
string com = Console.ReadLine();
com = com.Replace(" ", String.Empty);
if (com != "Y")
{
convertFinished = true;
}
}
}
}
}
//}
//catch (InvalidCastException e)
//{
// Console.WriteLine(e);
//}
}
}
}