-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copied node classes from inclass exercises. Stuff won't work.
- Loading branch information
Stephen Graham
committed
Oct 27, 2023
1 parent
4d3c179
commit 9659708
Showing
16 changed files
with
231 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
class AdditionNode : OperatorNode | ||
{ | ||
public AdditionNode() | ||
: base("+") | ||
{ | ||
this.Precidence = 1; | ||
} | ||
|
||
public override double Evaluate() | ||
{ | ||
return Expression.Evaluate(this.Left) + Expression.Evaluate(this.Right); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
class DivisionNode : OperatorNode | ||
{ | ||
public DivisionNode() | ||
{ | ||
this.Precidence = 2; | ||
} | ||
|
||
public override double Evaluate() | ||
{ | ||
return Expression.Evaluate(this.Left) / Expression.Evaluate(this.Right); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
class ExponentNode : OperatorNode | ||
{ | ||
public ExponentNode() | ||
{ | ||
this.Precidence = 3; | ||
} | ||
public override double Evaluate() | ||
{ | ||
return System.Math.Pow(Expression.Evaluate(this.Left), Expression.Evaluate(this.Right)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
class MultiplicationNode : OperatorNode | ||
{ | ||
public MultiplicationNode() | ||
{ | ||
this.Precidence = 2; | ||
} | ||
|
||
public override double Evaluate() | ||
{ | ||
return Expression.Evaluate(this.Left) * Expression.Evaluate(this.Right); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,67 @@ | ||
// <copyright file="OperatorNode.cs" company="Stephen Graham - 011706998"> | ||
// Copyright (c) Stephen Graham - 011706998. All rights reserved. | ||
// </copyright> | ||
// CptS 321: Expression Tree Code Demo of how NOT to code your assignements | ||
// Problems and sollutions of this code will be discussed in class | ||
// Note that if you sumbit this code you will not get ANY points for the assignments | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Node that performs operations on other nodes. | ||
/// </summary> | ||
public class OperatorNode : Node | ||
public abstract class OperatorNode : Node | ||
{ | ||
private static List<char> validOperators = new List<char> { '+', '-', '*', '/' }; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OperatorNode"/> class. | ||
/// Creates an operator node with a character argument. | ||
/// </summary> | ||
/// <param name="c"> operator character.</param> | ||
public OperatorNode(char c) | ||
{ | ||
this.IsOperand = false; | ||
this.IsParenthesis = false; | ||
} | ||
|
||
public OperatorNode(string c) | ||
{ | ||
this.Operator = c; | ||
this.Precidence = 1; | ||
this.IsOperand = false; | ||
this.IsParenthesis = false; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OperatorNode"/> class. | ||
/// </summary> | ||
public OperatorNode() | ||
{ | ||
this.Precidence = 1; | ||
this.IsOperand = false; | ||
this.IsParenthesis = false; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the operator node. | ||
/// </summary> | ||
public string Operator { get; set; } | ||
|
||
/// <summary> | ||
/// Returns true if operator is from valid list. | ||
/// </summary> | ||
/// <param name="c"> Char of operator.</param> | ||
/// <returns> bool. </returns> | ||
public static bool ValidOperators(char c) | ||
public static bool ValidOperators(string c) | ||
{ | ||
if (validOperators.Contains(c)) | ||
switch (c) | ||
{ | ||
return true; | ||
case "+": | ||
case "-": | ||
case "*": | ||
case "/": | ||
case "^": | ||
case "(": | ||
case ")": | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// The operation to do to the nodes children, depending upon the character input. | ||
/// </summary> | ||
/// <returns> A double value of the operation. </returns> | ||
public double Operate() | ||
public static bool ValidOperators(char c) | ||
{ | ||
switch (this.Operator) | ||
switch (c) | ||
{ | ||
case "+": | ||
return ExpressionTree.Evaluate(this.Left) + ExpressionTree.Evaluate(this.Right); | ||
case "-": | ||
return ExpressionTree.Evaluate(this.Left) - ExpressionTree.Evaluate(this.Right); | ||
case "*": | ||
return ExpressionTree.Evaluate(this.Left) * ExpressionTree.Evaluate(this.Right); | ||
case "/": | ||
return ExpressionTree.Evaluate(this.Left) / ExpressionTree.Evaluate(this.Right); | ||
default: | ||
throw new NotSupportedException( | ||
"Operator " + this.Operator.ToString() + " not supported."); | ||
case '+': | ||
case '-': | ||
case '*': | ||
case '/': | ||
case '^': | ||
case '(': | ||
case ')': | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public string Operator { get; set; } | ||
|
||
public abstract double Evaluate(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
internal class OperatorNodeFactory | ||
{ | ||
public static OperatorNode CreateOperatorNode(char op) | ||
{ | ||
switch (op) | ||
{ | ||
case '+': | ||
AdditionNode add = new AdditionNode(); | ||
return add; | ||
case '-': | ||
SubractionNode sub = new SubractionNode(); | ||
return sub; | ||
case '*': | ||
MultiplicationNode mul = new MultiplicationNode(); | ||
return mul; | ||
case '/': | ||
DivisionNode div = new DivisionNode(); | ||
return div; | ||
case '^': | ||
ExponentNode exp = new ExponentNode(); | ||
return exp; | ||
case '(': | ||
ParenthesisNode par = new ParenthesisNode(); | ||
return par; | ||
} | ||
|
||
throw new Exception("Operater not supported"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
class ParenthesisNode : OperatorNode | ||
{ | ||
public ParenthesisNode() | ||
{ | ||
this.IsParenthesis = true; | ||
} | ||
|
||
public override double Evaluate() | ||
{ | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SpreadsheetEngine | ||
{ | ||
class SubractionNode : OperatorNode | ||
{ | ||
public SubractionNode() | ||
{ | ||
this.Precidence = 1; | ||
} | ||
|
||
public override double Evaluate() | ||
{ | ||
return Expression.Evaluate(this.Left) - Expression.Evaluate(this.Right); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# SA0001: XML comment analysis disabled | ||
dotnet_diagnostic.SA0001.severity = warning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters