Exemple #1
0
    public Question(string val1, string op, string val2, string val3, mathOp mo, quesType qt, string q)
    {
        this.val1     = val1;
        this.val2     = val2;
        this.op       = op;
        this.val3     = val3;
        this.mo       = mo;
        this.qt       = qt;
        this.question = q;
        switch (qt)
        {
        case quesType.Basic:
            ans = val3.ToString();
            break;

        case quesType.Algebra:
            ans = val2.ToString();
            break;

        case quesType.Operation:
            ans = op;
            break;

        default:
            ans = "Error";
            Debug.LogErrorFormat("Unhandled question type: {0}", qt);
            break;
        }
    }
Exemple #2
0
    Question MakeQuestion(List <mathOp> ops, List <quesType> types)
    {
        quesType qt   = types[Random.Range(0, types.Count)];
        mathOp   mo   = ops[Random.Range(0, types.Count)];
        int      val1 = Random.Range(MINNUM, MAXNUM + 1);
        int      val2 = Random.Range(MINNUM, MAXNUM + 1);
        int      val3 = -23;     // Poor choice of error value, but rolling with it. TODO
        string   sol  = "Error"; // Correct solution that a ship will carry

        switch (mo)
        {
        case mathOp.Add:
            val3 = val1 + val2;
            break;

        case mathOp.Subtract:
            val3 = val1 - val2;
            break;

        case mathOp.Multiply:
            val3 = val1 * val2;
            break;

        default:
            Debug.LogErrorFormat("Unhandled math operator: {0}", mo);
            break;
        }
        string quesStr = "Error";

        switch (qt)
        {
        case quesType.Basic:
            quesStr = string.Format("{0}{1}{2}=?", val1, opMap[mo], val2);
            sol     = val3.ToString();
            break;

        case quesType.Algebra:
            quesStr = string.Format("{0}{1}?={2}", val1, opMap[mo], val3);
            sol     = val2.ToString();
            break;

        case quesType.Operation:
            quesStr = string.Format("{0}?{1}={2}", val1, val2, val3);
            sol     = opMap[mo];
            break;

        default:
            Debug.LogErrorFormat("Unhandled ques type: {0}", qt);
            break;
        }
        Question quesOut = new Question(val1.ToString(), opMap[mo], val2.ToString(), val3.ToString(), mo, qt, quesStr);

        return(quesOut);
    }
        static void InvokeFunc(mathOp op)
        {
            Console.WriteLine("enter v1");
            double v1 = double.Parse(Console.ReadLine());

            Console.WriteLine("enter v2");
            double v2 = double.Parse(Console.ReadLine());

            var res = op(v1, v2);

            Console.WriteLine("The result of this operation is " + res);
        }
Exemple #4
0
        //main()
        static void Main(string[] args)
        {
            //Header Prompt
            Console.WriteLine("\nLet's demonstrate the usefulness of Airthmetic\n" +
                              "operations by using Lambda Expressions.\n");

            //Lambda Expressions, Arithmetic Expressions
            mathOp div = (x, y) => x / y;
            mathOp exp = (x, y) => Math.Pow(x, y);
            mathOp min = (x, y) => Math.Min(x, y);

            string[] expr;
            var      expr1 = 0.0;
            var      expr2 = 0.0;


            //Prompt for Division
            Console.Write("LET'S DO SOME DIVISION:\t");
            try{
                // expr = Console.ReadLine().Split();
                // expr1 = double.Parse(expr[0]);
                expr1 = 10.2;
                // expr2 = double.Parse(expr[1]);
                expr2 = 13.9;
            } catch (Exception e) when(e is FormatException || e is OverflowException)
            {
                Console.WriteLine("\n\nYou have entered invalid input. Restarting.\n\n");
                Main(args);
            }
            //Lambda Expression, Print Result
            Console.WriteLine("The result is:\t" + div(expr1, expr2));


            //Prompt for Exponentiation
            Console.Write("\nLET'S DO SOME EXPONENTIATION:\t");
            try{
                // expr = Console.ReadLine().Split();
                // expr1 = double.Parse(expr[0]);
                expr1 = 9.3;
                // expr2 = double.Parse(expr[1]);
                expr2 = 3.4;
            } catch (Exception e) when(e is FormatException || e is OverflowException)
            {
                Console.WriteLine("\n\nYou have entered invalid input. Restarting.\n\n");
                Main(args);
            }
            //Lambda Expression, Print Result
            Console.WriteLine("The result is:\t" + exp(expr1, expr2));


            //Prompt for Minimum
            Console.Write("\nLET'S DO SOME MINIMUM:\t");
            try{
                // expr = Console.ReadLine().Split();
                // expr1 = double.Parse(expr[0]);
                expr1 = 7.3;
                // expr2 = double.Parse(expr[1]);
                expr2 = 1.2;
            } catch (Exception e) when(e is FormatException || e is OverflowException)
            {
                Console.WriteLine("\n\nYou have entered invalid input. Restarting.\n\n");
                Main(args);
            }
            //Lambda Expression, Print Result
            Console.Write("The result is:\t" + min(expr1, expr2));
        }