diff --git a/Calculator.sln b/Calculator.sln new file mode 100644 index 0000000..edc7351 --- /dev/null +++ b/Calculator.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator", "Calculator\Calculator.csproj", "{A1F2F45D-1B37-43C8-95D8-C4DA753722D6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A1F2F45D-1B37-43C8-95D8-C4DA753722D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1F2F45D-1B37-43C8-95D8-C4DA753722D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1F2F45D-1B37-43C8-95D8-C4DA753722D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1F2F45D-1B37-43C8-95D8-C4DA753722D6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Calculator/App.config b/Calculator/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/Calculator/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calculator/Calc.cs b/Calculator/Calc.cs new file mode 100644 index 0000000..b57be0f --- /dev/null +++ b/Calculator/Calc.cs @@ -0,0 +1,254 @@ +///////////////////////////////////////////////////////////////////// +// File: Calc.cs +// +// Author: Ricky Bastarache +// This assignment represents my own work and is in accordance with the College Academic Policy +// +// Copyright (c) 2016 All Right Reserved by Dave Burchill +// Contributors: +// Description: +// +// Date: Sept 2016 +// +// Revisions: +// +///////////////////////////////////////////////////////////////////// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Calculator +{ + class Calc + { + + private double _lhs; + private double _rhs; + private double _results; + private char _operators; + private bool isContinue = true; + + public Calc() + { } + + + public void calculation(char operators) + { + switch (operators) + { + case 'a': + addition(); + break; + case 's': + subtraction(); + break; + case 'm': + multiplication(); + break; + case 'd': + Division(); + break; + case '!': + case 'e': + exponentiation(); + break; + case '^': + case 'f': + factorial(); + break; + case 'q': + quit(); + break; + default: + break; + }; + } + + + public void addition() + { + _results = _lhs + _rhs; + if (_results > 1000000 || _results < -1000000) + OverFlow(); + else + displayResults(); + } + + + public void subtraction() + { + _results = _lhs - _rhs; + if (_results > 1000000 || _results < -1000000) + OverFlow(); + else + displayResults(); + } + + + public void multiplication() + { + _results = _lhs * _rhs; + if (_results > 1000000 || _results < -1000000) + OverFlow(); + else + displayResults(); + } + + + public void Division() + { + if (_rhs == 0) + divByZero(); + else if (_results > 1000000 || _results < -1000000) + OverFlow(); + else + { + _results = _lhs / _rhs; + displayResults(); + } + + } + + public void factorial() + { + if (_lhs < 0) + Error(); + else + { + + for (int i = 1; i < _lhs; i++) + _results = (_results * i); + + if (_results > 1000000 || _results < -1000000) + OverFlow(); + else + displayResults(); + } + + } + + public void exponentiation() + { + _results = Math.Pow(_lhs, _rhs); + if (_results > 1000000 || _results < -1000000) + OverFlow(); + else + displayResults(); + } + + public void quit() + { + Environment.Exit(0); + } + + public void Run() + { + + while (isContinue) + { + Console.Clear(); + + isLhsNumeric(); + isChar(); + if (_operators.Equals('f') || _operators.Equals('F') || _operators.Equals('^')) + { /*do nothing*/} + else + { + isRhsNumeric(); + calculation(_operators); + } + + } + Environment.Exit(0); + } + + public void isLhsNumeric() + { + bool isNumeric = false; + while (!isNumeric) + { + Console.WriteLine("Enter a Number"); + string lhs = Console.ReadLine(); + isNumeric = double.TryParse(lhs, out _lhs); + if (!isNumeric) + Error(); + else + isNumeric = true; + } + } + + public void isRhsNumeric() + { + bool isNumeric = false; + while (!isNumeric) + { + Console.WriteLine("Enter a Number"); + string rhs = Console.ReadLine(); + isNumeric = double.TryParse(rhs, out _rhs); + if (!isNumeric) + Error(); + else + isNumeric = true; + } + } + + public void isChar() + { + bool isGoodChar = false; + + while (!isGoodChar) + { + Console.WriteLine("Enter an operator"); + string operators = Console.ReadLine(); + bool isChar = char.TryParse(operators.ToLower(), out _operators); + if (_operators.Equals('f') || _operators.Equals('^')) + factorial(); + + if (_operators.Equals('a') || _operators.Equals('A') || _operators.Equals('s') || _operators.Equals('S') || + _operators.Equals('m') || _operators.Equals('M') || _operators.Equals('d') || _operators.Equals('D') || + _operators.Equals('e') || _operators.Equals('E') || _operators.Equals('!') || + _operators.Equals('f') || _operators.Equals('F') || _operators.Equals('^')) + isGoodChar = true; + else + Error(); + + if (_operators.Equals('q') || _operators.Equals('Q')) + { + calculation(_operators); + isGoodChar = true; + } + + + } + } + + public void OverFlow() + { + Console.WriteLine("Over flow"); + Console.ReadKey(); + } + + public void displayResults() + { + Console.WriteLine("Result is: " + _results); + Console.ReadKey(); + } + + public void divByZero() + { + Console.WriteLine("Div0"); + Console.ReadKey(); + } + + public void Error() + { + Console.WriteLine("Error"); + Console.ReadKey(); + } + } + + +} + diff --git a/Calculator/Calculator.csproj b/Calculator/Calculator.csproj new file mode 100644 index 0000000..39b7b23 --- /dev/null +++ b/Calculator/Calculator.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {A1F2F45D-1B37-43C8-95D8-C4DA753722D6} + Exe + Properties + Calculator + Calculator + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Calculator/Program.cs b/Calculator/Program.cs new file mode 100644 index 0000000..da5b39a --- /dev/null +++ b/Calculator/Program.cs @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////// +// File: Program.cs +// +// Author: Ricky Bastarache +// This assignment represents my own work and is in accordance with the College Academic Policy +// +// Copyright (c) 2016 All Right Reserved by Dave Burchill +// Contributors: +// Description: +// +// Date: Sept 2016 +// +// Revisions: +// +///////////////////////////////////////////////////////////////////// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Calculator +{ + class Program + { + static void Main(string[] args) + { + Calc Calculator = new Calc(); + Calculator.Run(); + } + } +} diff --git a/Calculator/Properties/AssemblyInfo.cs b/Calculator/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a102738 --- /dev/null +++ b/Calculator/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Calculator")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Calculator")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a1f2f45d-1b37-43c8-95d8-c4da753722d6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Calculator/bin/Debug/Calculator.exe.config b/Calculator/bin/Debug/Calculator.exe.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/Calculator/bin/Debug/Calculator.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calculator/bin/Debug/Calculator.vshost.exe.config b/Calculator/bin/Debug/Calculator.vshost.exe.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/Calculator/bin/Debug/Calculator.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calculator/bin/Debug/Calculator.vshost.exe.manifest b/Calculator/bin/Debug/Calculator.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/Calculator/bin/Debug/Calculator.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Calculator/obj/Debug/Calculator.csproj.FileListAbsolute.txt b/Calculator/obj/Debug/Calculator.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..630af4f --- /dev/null +++ b/Calculator/obj/Debug/Calculator.csproj.FileListAbsolute.txt @@ -0,0 +1,7 @@ +C:\Users\rick__000\Documents\Visual Studio 2015\Projects\Calculator\Calculator\bin\Debug\Calculator.exe.config +C:\Users\rick__000\Desktop\prog1264Assignment1\Calculator\bin\Debug\Calculator.exe.config +C:\Users\rick__000\Desktop\prog1264Assignment1\Calculator\bin\Debug\Calculator.exe +C:\Users\rick__000\Desktop\prog1264Assignment1\Calculator\bin\Debug\Calculator.pdb +C:\Users\rick__000\Desktop\prog1264Assignment1\Calculator\obj\Debug\Calculator.csprojResolveAssemblyReference.cache +C:\Users\rick__000\Desktop\prog1264Assignment1\Calculator\obj\Debug\Calculator.exe +C:\Users\rick__000\Desktop\prog1264Assignment1\Calculator\obj\Debug\Calculator.pdb diff --git a/Calculator/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/Calculator/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs new file mode 100644 index 0000000..e69de29 diff --git a/Calculator/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs b/Calculator/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs new file mode 100644 index 0000000..e69de29 diff --git a/Calculator/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/Calculator/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs new file mode 100644 index 0000000..e69de29