| | | 1 | | namespace CalculatorLibrary { |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Performs basic arithmetic operations on integers. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <remarks> |
| | | 7 | | /// This is the sample class the template ships with. When you start your own project, replace it |
| | | 8 | | /// (and <see cref="CalculatorCli"/>) with your own domain classes — see |
| | | 9 | | /// <c>docs/guide/from-topic-to-project.en.md</c> for the step-by-step walkthrough. |
| | | 10 | | /// </remarks> |
| | | 11 | | public class Calculator { |
| | | 12 | | /// <summary>Adds two integers.</summary> |
| | | 13 | | /// <param name="a">The first addend.</param> |
| | | 14 | | /// <param name="b">The second addend.</param> |
| | | 15 | | /// <returns>The sum of <paramref name="a"/> and <paramref name="b"/>.</returns> |
| | | 16 | | public int Add(int a, int b) { |
| | 20 | 17 | | return a + b; |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary>Subtracts one integer from another.</summary> |
| | | 21 | | /// <param name="a">The value to subtract from.</param> |
| | | 22 | | /// <param name="b">The value to subtract.</param> |
| | | 23 | | /// <returns>The result of <paramref name="a"/> minus <paramref name="b"/>.</returns> |
| | | 24 | | public int Subtract(int a, int b) { |
| | 12 | 25 | | return a - b; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary>Multiplies two integers.</summary> |
| | | 29 | | /// <param name="a">The first factor.</param> |
| | | 30 | | /// <param name="b">The second factor.</param> |
| | | 31 | | /// <returns>The product of <paramref name="a"/> and <paramref name="b"/>.</returns> |
| | | 32 | | public int Multiply(int a, int b) { |
| | 12 | 33 | | return a * b; |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary>Divides one integer by another using integer (truncating) division.</summary> |
| | | 37 | | /// <param name="a">The dividend.</param> |
| | | 38 | | /// <param name="b">The divisor.</param> |
| | | 39 | | /// <returns>The integer quotient of <paramref name="a"/> divided by <paramref name="b"/>.</returns> |
| | | 40 | | /// <exception cref="DivideByZeroException">Thrown when <paramref name="b"/> is zero.</exception> |
| | | 41 | | public int Divide(int a, int b) { |
| | 20 | 42 | | if (b == 0) { |
| | 4 | 43 | | throw new DivideByZeroException(); |
| | | 44 | | } |
| | | 45 | | |
| | 16 | 46 | | return a / b; |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | } |