/// <summary> /// Returns a more human-readable string that represents the current calculation instance. /// </summary> /// <param name="option">The spacing option.</param> /// <returns> /// A string with better readability. /// </returns> /// <seealso cref="SpacingOption" /> public override string ToFormattedString(SpacingOption option = SpacingOption.None) { string operatorSign = null; string spacing = ""; switch (option) { case SpacingOption.Thin: spacing = " "; break; case SpacingOption.Thick: spacing = " "; break; } switch (Operator) { case Operator.Add: operatorSign = $"{spacing}+{spacing}"; break; case Operator.Sub: operatorSign = $"{spacing}-{spacing}"; break; case Operator.Mul: operatorSign = $"{spacing}×{spacing}"; break; case Operator.Div: operatorSign = $"{spacing}÷{spacing}"; break; } if (Left is CompositeCalculation && !(Right is CompositeCalculation) && OperatorPrecedence((Left as CompositeCalculation).Operator) < OperatorPrecedence(this.Operator)) { return($"({Left.ToFormattedString(option)}){operatorSign}{Right.ToFormattedString(option)}"); } if (!(Left is CompositeCalculation) && Right is CompositeCalculation && OperatorPrecedence((Right as CompositeCalculation).Operator) < OperatorPrecedence(this.Operator)) { return($"{Left.ToFormattedString(option)}{operatorSign}({Right.ToFormattedString(option)})"); } if (Left is CompositeCalculation && Right is CompositeCalculation) { return($"({Left.ToFormattedString(option)}){operatorSign}({Right.ToFormattedString(option)})"); } return($"{Left.ToFormattedString(option)}{operatorSign}{Right.ToFormattedString(option)}"); }
/// <summary> /// Initializes a new instance of the <see cref="QuestionGenerator{T}"/> class. /// </summary> /// <param name="placeHolder">The place holder of the question where the students should put the answer in.</param> /// <param name="spacingOption">The <see cref="SpacingOption"/> value which indicates the spacing options of the generated question.</param> protected QuestionGenerator(string placeHolder, SpacingOption spacingOption) { this.placeHolder = placeHolder; this.spacingOption = spacingOption; }
/// <summary> /// Returns a more human-readable string that represents the current calculation instance. /// </summary> /// <param name="option">The spacing option.</param> /// <returns>A string with better readability.</returns> /// <seealso cref="SpacingOption"/> public override string ToFormattedString(SpacingOption option = SpacingOption.None) => this.Value.ToString();
/// <summary> /// Initializes a new instance of the <see cref="ClozeQuestionGenerator"/> class. /// </summary> /// <param name="placeHolder">The place holder of the question where the students should put the answer in.</param> /// <param name="spacingOption">The <see cref="SpacingOption"/> value which indicates the spacing options of the generated question.</param> public ClozeQuestionGenerator(string placeHolder = "( )", SpacingOption spacingOption = SpacingOption.Thin) : base(placeHolder, spacingOption) { }
/// <summary> /// Initializes a new instance of the <see cref="RegularQuestionGenerator"/> class. /// </summary> /// <param name="placeHolder">The place holder of the question where the students should put the answer in.</param> /// <param name="spacingOption">The <see cref="P:CalculateIt2.Engine.Generation.QuestionGenerator`1.SpacingOption" /> value which indicates the spacing options of the generated question.</param> public RegularQuestionGenerator(string placeHolder = "____", SpacingOption spacingOption = SpacingOption.Thin) : base(placeHolder, spacingOption) { }
/// <summary> /// Returns a more human-readable string that represents the current calculation instance. /// </summary> /// <param name="option">The spacing option.</param> /// <returns>A string with better readability.</returns> /// <seealso cref="SpacingOption"/> public abstract string ToFormattedString(SpacingOption option = SpacingOption.None);
/// <summary> /// Initializes a new instance of the <see cref="ComparisonQuestionGenerator"/> class. /// </summary> /// <param name="threshold">The threshold.</param> /// <param name="placeHolder">The place holder.</param> /// <param name="spacingOption">The spacing option.</param> public ComparisonQuestionGenerator(int threshold, string placeHolder = "\u25CB", SpacingOption spacingOption = SpacingOption.Thin) : base(placeHolder, spacingOption) { this.threshold = threshold; }