私は現在、ブール論理と真理値表を扱っています。(a,b)
2変数テーブルを生成するクラスを作成することができました。私の主な関心は、テーブル内の特定の入力を選択し、その出力に「true」値を設定することです。上記を介してハードコーディングし、それらの値の出力結果をと呼ばれる複数行のテキストボックスにoverride bool GetTruthValue()
表示することができました。真理値を計算するロジックをユーザーが提供したい。私の現在のアプローチでは、ロジックはコードによって提供されています。どの入力の出力値が`trueになるかをユーザーに選択させるにはどうすればよいですか?チェックボックスまたは個別のtexbox(1または0)で示しますか?または他の提案?true
OutputTextBox
namespace table_outputs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public abstract class TwoItemTruthRow
{
protected TwoItemTruthRow(bool a, bool b)
{
A = a; B = b;
}
public bool A { get; protected set; }
public bool B { get; protected set; }
public abstract bool GetTruthValue();
}
public class MyCustomTwoItemTruthRow : TwoItemTruthRow
{
public MyCustomTwoItemTruthRow(bool a, bool b)
: base(a, b)
{
}
public override bool GetTruthValue()
{
// My custom logic- Hard coded
return (A && B) || (A && !B) || (!A && !B);
}
}
private static string GetHorizontalLineText()
{
return "-----------------------------------------------\r\n";
}
private static string GetFormattedTwoItemText(MyCustomTwoItemTruthRow item)
{
return string.Format("{0}\t{1}\r\n", item.A, item.B);
}
private static IEnumerable<MyCustomTwoItemTruthRow> GenerateTruthTableTwo()
{
for (var a = 0; a < 2; a++)
for (var b = 0; b < 2; b++)
yield return new MyCustomTwoItemTruthRow(
Convert.ToBoolean(a),
Convert.ToBoolean(b));
}
private void GenerateTableButton_Click(object sender, EventArgs e)
{
InputTextBox.Clear();
InputTextBox.Text += "A\tB\r\n";
InputTextBox.Text += GetHorizontalLineText();
var myTruthTable = GenerateTruthTable().ToList();
foreach (var item in myTruthTable)
{
InputTextBox.Text += GetFormattedTwoItemText(item);
InputTextBox.Text += GetHorizontalLineText();
}
}
private void ShowTrueValuesButton_Click(object sender, EventArgs e)
{
OutputTextBox.Clear();
OutputTextBox.Text += "True Values\r\n";
OutputTextBox.Text += "A\tB\r\n";
OutputTextBox.Text += GetHorizontalLineText();
var myTruthTable = GenerateTruthTableTwo().ToList();
foreach (var item in myTruthTable)
{
if (item.GetTruthValue())
OutputTextBox.Text += GetFormattedTwoItemText(item);
}
}
}
}
現在のWinForm