Design and build a rational number calculator program. This calculator should re
ID: 1847154 • Letter: D
Question
Design and build a rational number calculator program. This calculator should read the mathematical
expression as an user input and add (+), subtract (-), multiply (*) or divide (/) the rational numbers. The
program should do the calculation using c# operator precedence rule; * and / are perform before + and -. It
also search for the maximum common divider to simplify the result.
The following is a sample run of the program
Input the mathematical expression: 1/3 * 2/4 + 5/9
Output: 1/3 * 2/4 + 5/9 = 78/108 = 13/18
or
Input the mathematical expression 1/2 + 1/4 * 5/3
Explanation / Answer
[Visual Basic] Imports System Public Class SplitTest Public Shared Sub Main() Dim words As String = "this is a list of words, with: a bit of punctuation." Dim split As String() = words.Split(New [Char]() {" "c, ","c, "."c, ":"c}) Dim s As String For Each s In split If s.Trim() "" Then Console.WriteLine(s) End If Next s End Sub 'Main End Class 'SplitTest [C#] using System; public class SplitTest { public static void Main() { string words = "this is a list of words, with: a bit of punctuation."; string [] split = words.Split(new Char [] {' ', ',', '.', ':'}); foreach (string s in split) { if (s.Trim() != "") Console.WriteLine(s); } } } [C++] #using using namespace System; using namespace System::Collections; int main() { String* words = S"this is a list of words, with: a bit of punctuation."; Char chars[] = {' ', ', ', '->', ':'}; String* split[] = words->Split(chars); IEnumerator* myEnum = split->GetEnumerator(); while (myEnum->MoveNext()) { String* s = __try_cast(myEnum->Current); if (!s->Trim()->Equals(S"")) Console::WriteLine(s); } } [JScript] import System; public class SplitTest { public static function Main() : void { var words : String = "this is a list of words, with: a bit of punctuation."; var separators : char[] = [' ', ',', '.', ':']; var split : String [] = words.Split(separators); for (var i : int in split) { var s : String = split[i]; if (s.Trim() != "") Console.WriteLine(s); } } } SplitTest.Main();Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.