diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b06e864 --- /dev/null +++ b/.gitignore @@ -0,0 +1,212 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml diff --git a/assignment 1.sln b/assignment 1.sln new file mode 100644 index 0000000..e706c06 --- /dev/null +++ b/assignment 1.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "assignment 1", "assignment 1\assignment 1.csproj", "{0FAA29FE-A787-4EC0-BBDE-DE4E4B94E83F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0FAA29FE-A787-4EC0-BBDE-DE4E4B94E83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0FAA29FE-A787-4EC0-BBDE-DE4E4B94E83F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0FAA29FE-A787-4EC0-BBDE-DE4E4B94E83F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0FAA29FE-A787-4EC0-BBDE-DE4E4B94E83F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/assignment 1/App.config b/assignment 1/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/assignment 1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/assignment 1/Calculator.cs b/assignment 1/Calculator.cs new file mode 100644 index 0000000..7ba99f3 --- /dev/null +++ b/assignment 1/Calculator.cs @@ -0,0 +1,309 @@ +/** + * @file + * Michael Landry mic_23@hotmail.com + * @version 1.0 + * + * @section LICENSE + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * https://www.gnu.org/copyleft/gpl.html + * + * @section DESCRIPTION + * + * This is a simple calculator programe. It will do +, -, /, *, exponential and factorial + * it also check for input error + * + * The time class represents a moment of time. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace assignment_1 +{ + + class Calculator + { + // private member use in the calculator class + public const int MILLION = 1000000; + private double _lhs; + private double _rhs; + private double _result; + private long _longResult; + private char _operators; + private bool userContinue = true; + + // constructor with no parameter + public Calculator() + { } + + // switch to redirec, according to the operator, to the good function to do the calculation + 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; + }; + } + + // Do the addition and check if the resuls is over 1,000,000 or less that -1,000,000 + // and call overflow or displayResult depend of the result + public void addition() + { + _result = _lhs + _rhs; + if (_result > MILLION || _result < -MILLION) + overflow(); + else + displayResult(); + } + + // Do the subtraction and check if the resuls is over 1,000,000 or less that -1,000,000 + // and call overflow or displayResult depend of the result + public void subtraction() + { + _result = _lhs - _rhs; + if (_result > MILLION || _result < -MILLION) + overflow(); + else + displayResult(); + } + + // Do the multiplication and check if the resuls is over 1,000,000 or less that -1,000,000 + // and call overflow or displayResult depend of the result + public void multiplication() + { + _result = _lhs * _rhs; + if (_result > MILLION || _result < -MILLION) + overflow(); + else + displayResult(); + } + + // Do the division and check if the resuls is over 1,000,000 or less that -1,000,000 + // and call overflow or displayResult depend of the result + public void division() + { + if (_rhs == 0) + { + div0(); + } + else if (_result > MILLION || _result < -MILLION) + overflow(); + else + { + _result = _lhs / _rhs; + displayResult(); + } + + } + + // Do the factorial and check if the user enter a negatif value. if yes + // message a error. check if the resuls is over 1,000,000 or less that -1,000,000 + // and call overflow or displayResult depend of the result + public void factorial() + { + if (_lhs < 0) + error(); + else + { + _longResult = Convert.ToInt64(_lhs); + + for (int i = 1; i < _lhs; i++) + { + _longResult = (_longResult * i); + } + _result = _longResult; + if (_result > MILLION || _result < -MILLION) + overflow(); + else + displayResult(); + } + + } + // Do the exponentiation and check if the resuls is over 1,000,000 or less that -1,000,000 + // and call overflow or displayResult depend of the result + public void exponentiation() + { + _result = Math.Pow(_lhs, _rhs); + if (_result > 1000000 || _result < -1000000) + overflow(); + else + displayResult(); + } + + // if the user press q or Q the programe exit + public void quit() + { + Environment.Exit(0); + } + + // the calculation loop + public void calculatorRun() + { + Menu menu = new Menu(); + + while (userContinue) + { + Console.Clear(); + // display the menu + menu.displayMenu(); + // check if the user enter a numeric + isLhsNumeric(); + // check if the user enter a char for the operator + isChar(); + // if the operator is f or ^ do nothing + if (_operators.Equals('f') || _operators.Equals('^')) + { } + // else ask for the rhs and do the calculation + else + { + isRhsNumeric(); + calculation(_operators); + } + + } + Environment.Exit(0); + } + + // check if the lhs number is numeric if yes assigne to _lhs + public void isLhsNumeric() + { + bool isNumeric = false; + while (!isNumeric) + { + Console.WriteLine("Enter a Number"); + string lhs = Console.ReadLine(); + // check if the user enter a interger if yes place it to _lhs + isNumeric = double.TryParse(lhs, out _lhs); + // if is not a numeric print a error message + if (!isNumeric) + { + error(); + } + else + isNumeric = true; + } + } + + // check if the rhs number is numeric if yes assigne to _rhs + public void isRhsNumeric() + { + bool isNumeric = false; + while (!isNumeric) + { + Console.WriteLine("Enter a Number"); + string rhs = Console.ReadLine(); + // check if the user enter a interger if yes place it to _rhs + isNumeric = double.TryParse(rhs, out _rhs); + // if is not a numeric print a error message + if (!isNumeric) + { + error(); + } + else + isNumeric = true; + } + } + + // check if the operator is a char and if is a good operator and assigne to _operator + public void isChar() + { + bool goodChar = false; + + while (!goodChar) + { + Console.WriteLine("Enter operator"); + string operators = Console.ReadLine(); + // put the operator to lower and check if the operator is a char if yes put it to _operators + bool isChar = char.TryParse(operators.ToLower(), out _operators); + // if the operator is f or ^ redirect to factorial + // because factorial don't need rhs + if (_operators.Equals('f') || _operators.Equals('^')) + { + factorial(); + } + // check if the operator is one of the good chose + if (_operators.Equals('a') || _operators.Equals('s') || + _operators.Equals('m') || _operators.Equals('d') || + _operators.Equals('e') || _operators.Equals('!') || + _operators.Equals('f') || _operators.Equals('^')) + goodChar = true; + // if the opperator is not a good operator print a error message + else + { + error(); + } + // if the operator is q sent to calculation to go to the exit function + if (_operators.Equals('q')) + { + calculation(_operators); + goodChar = true; + } + + + } + } + // if the result is over 1,000,000 or -1,000,000 display this message + public void overflow() + { + Console.WriteLine("Overflow"); + Console.ReadKey(); + } + // display the result of the operation + public void displayResult() + { + Console.WriteLine("The result is: " + _result); + Console.ReadKey(); + } + // if the division is divide by 0 display this message + public void div0() + { + Console.WriteLine("Div0"); + Console.ReadKey(); + } + // if user try to enter a wrong value to number or operator display this mesage + public void error() + { + Console.WriteLine("Error"); + Console.ReadKey(); + } + } + + +} + diff --git a/assignment 1/Menu.cs b/assignment 1/Menu.cs new file mode 100644 index 0000000..3b43c4c --- /dev/null +++ b/assignment 1/Menu.cs @@ -0,0 +1,59 @@ +/** + * @file + * Michael Landry mic_23@hotmail.com + * @version 1.0 + * + * @section LICENSE + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * https://www.gnu.org/copyleft/gpl.html + * + * @section DESCRIPTION + * + * This is a simple calculator programe. It will do +, -, /, *, exponential and factorial + * it also check for input error + * + * The time class represents a moment of time. + */ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace assignment_1 +{ + class Menu + { + public Menu() + { + + } + + // display the menu for the user to know the sysbole to use + public void displayMenu() + { + Console.Clear(); + Console.WriteLine("***************Calculator***************\n"); + Console.WriteLine("Legend: A or a is +"); + Console.WriteLine(" S or s is -"); + Console.WriteLine(" M or m is *"); + Console.WriteLine(" D or d is /"); + Console.WriteLine(" !, E or e is Exponentiation"); + Console.WriteLine(" ^, F or f is Factorial\n"); + Console.WriteLine(" Please enter a number"); + } + + + } +} diff --git a/assignment 1/Program.cs b/assignment 1/Program.cs new file mode 100644 index 0000000..cf44e38 --- /dev/null +++ b/assignment 1/Program.cs @@ -0,0 +1,47 @@ +/** + * @file + * Michael Landry mic_23@hotmail.com + * @version 1.0 + * + * @section LICENSE + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * https://www.gnu.org/copyleft/gpl.html + * + * @section DESCRIPTION + * + * This is a simple calculator programe. It will do +, -, /, *, exponential and factorial + * it also check for input error + * + * The time class represents a moment of time. + */ + + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace assignment_1 +{ + class Program + { + static void Main(string[] args) + { + + Calculator runCalculator = new Calculator(); + + runCalculator.calculatorRun(); + } + } +} diff --git a/assignment 1/Properties/AssemblyInfo.cs b/assignment 1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e7dc746 --- /dev/null +++ b/assignment 1/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("assignment 1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("assignment 1")] +[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("0faa29fe-a787-4ec0-bbde-de4e4b94e83f")] + +// 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/assignment 1/assignment 1.csproj b/assignment 1/assignment 1.csproj new file mode 100644 index 0000000..2321b4b --- /dev/null +++ b/assignment 1/assignment 1.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {0FAA29FE-A787-4EC0-BBDE-DE4E4B94E83F} + Exe + Properties + assignment_1 + assignment 1 + 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