예제 #1
0
        public NetCalculator()
        {
            InitializeComponent();

            express = new Expression.Expression();
            fontToolStripComboBox.Text = font = "Arial";

            TermForm = new NetTerm(richExpression, express);
            this.AddOwnedForm(TermForm);
        }
예제 #2
0
        public NetTerm(RichTextBox r, Expression.Expression e)
        {
            InitializeComponent();
            rich    = r;
            express = e;

            // Show given variables
            foreach (Expression.KeyValuePair <string, double> kvp in express.Variables)
            {
                string[][] row = { new string[] { kvp.Key, kvp.Value.ToString() } };
                dataGridViewVars.Rows.Add(row);
            }
            // Add some sample rows
            string[][] rowsv =
            {
                new string[] { "c",      "299792458"        },
                new string[] { "Gconst", "6.67428e-11"      },
                new string[] { "phi",    "(1 + sqrt 5) / 2" },
            };
            foreach (string[] row in rowsv)
            {
                express.Variables.Add(new Expression.KeyValuePair <string, double>(row[0], express.Evaluate(row[1])));
                dataGridViewVars.Rows.Add(row);
            }

            // Show given functions
            foreach (Expression.KeyValuePair <string, string[]> kvp in express.Functions)
            {
                string[][] row = { new string[] { kvp.Key, ComposeArgs(ref kvp.Value), kvp.Value[0] } };
                dataGridViewVars.Rows.Add(row);
            }
            // Add some sample rows
            string[][] rowsf =
            {
                new string[] { "PlankMass", "",        "sqrt( hbar*299792458/6.6742867e-11 )"    },
                new string[] { "Fermat",    "a, b, n", "a^n + b^n"                               },
                new string[] { "Binet",     "n",       "(phi^n - (-phi)^-n)/(phi^n - (-phi)^-1)" },
            };
            foreach (string[] row in rowsf)
            {
                string[] func;
                DecomposeArgs(row[2], row[1], out func);                 // No throw with valid predefined data!
                express.Functions.Add(new Expression.KeyValuePair <string, string[]>(row[0], func));
                dataGridViewFuncs.Rows.Add(row);
            }
        }
예제 #3
0
 public Form1()
 {
     InitializeComponent();
     expression = new Expression();
 }