]]> ]]>

Квадратное уравнение в Objeck

Пример для версий Objeck 2.0.3
use IO;

bundle Default {
    class Quadratic {
        function : Main(args : String[]) ~ Nil {
            A := Console->ReadString()->ToInt();
            if (A=0) {
                "Not a quadratic equation."->PrintLine();
                return;
            };
            B := Console->ReadString()->ToInt();
            C := Console->ReadString()->ToInt();
            D := 1.0*(B*B-4*A*C);
            if (D=0) {
                "x = "->Print();
                (0-B/2.0/A)->PrintLine();
            };
            if (D>0) {
                "x1 = "->Print();
                ((0-B+(D->SquareRoot()))/2.0/A)->PrintLine();
                "x2 = "->Print();
                ((0-B-(D->SquareRoot()))/2.0/A)->PrintLine();
            };
            if (D<0) {
                out := "x1 = (";
                out->Append(0-B/2.0/A);
                out->Append(",");
                out->Append(((D->Abs())->SquareRoot())/2/A);
                out->Append(")");
                out->PrintLine();
                out := "x2 = (";
                out->Append(0-B/2.0/A);
                out->Append(",");
                out->Append(0-((D->Abs())->SquareRoot())/2/A);
                out->Append(")");
                out->PrintLine();
            };
        }
    }
}

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам