Скачиваний:
16
Добавлен:
01.05.2014
Размер:
20.31 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <stdlib.h>
#include "Abuchalka.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Operations *Op1;
Error * Err;
int bt1 = 0,bt2 =0,bt3 = 0,bt4 =0,bt5=0;
int Rev = 0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
  Rev = 0;
  Revers -> Visible = false;
  Sign -> Caption = "+";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
 
 Revers -> Visible = true;
 Sign -> Caption = "-";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton3Click(TObject *Sender)
{
  Sign -> Caption = "x";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton4Click(TObject *Sender)
{
  Sign -> Caption = "/";
}

Operations :: Operations()
{
}
Operations ::~Operations ()
{
}

//---------------------------------------------------------------------------

bool BoxIsEmpty (int n )
{
 if (n == 1)
   {
     if(  Form1 -> E5 -> Text == "" || Form1 -> B5 -> Text == "" )
        return true;
      else
        return false;
    }

  if (n == 2)
   {
     if(  Form1 -> E4 -> Text == "" ||  Form1 -> B4 -> Text == "" )
        return true;
      else
        return false;
    }
 if (n == 3)
   {
     if(  Form1 -> E3 -> Text == "" ||  Form1 -> B3 -> Text == "" )
        return true;
      else
        return false;
    }
 if (n == 4)
   {
     if(  Form1 -> E2 -> Text == "" ||  Form1 -> B2 -> Text == "" )
        return true;
      else
        return false;
    }

 if (n == 5)
   {
     if(  Form1 -> E1 -> Text == "" ||  Form1 -> B1 -> Text == "" )
        return true;
      else
        return false;
    }
  else
   return true;
}

int Operations :: add(AnsiString A ,AnsiString B)
{
 return (StrToInt(A) + StrToInt(B));
}

int Operations :: sub(AnsiString A ,AnsiString B)
{
 return (StrToInt(A) - StrToInt(B));
}

AnsiString Error :: ErrorMsg (int n)
{
  AnsiString Msg[10] ;
 Msg[0] = " You have already execute the Operation."
  "Continue or start allover by pressing Clear !";
 Msg[1] = "Sorry! But You haven't not enter a value , or you have partly enter them!";
 Msg[2] = "Please choose first an operation then start the session!";
 Msg[3] = "IMPORTANT! USE REVERS WHEN THE FIRST OPERAND IS BIGGER THAN THE SECOND";
 Msg[4] = "НГО МАКЕМЕ М.T.    ------------------------------ Вариант разработки абучаюшей систмы для школнико 1-2 класса.";
 Msg[5] = "";
 Msg[6] = "";
 Msg[7] = "";
 Msg[8] = "";
 Msg[9] = "";

return Msg[n];
}

void Operations :: AddProcess (int n)
{
int temp,val,i,j;
 AnsiString Str;


 if (n == 1 )   // first Step
  {
    if ( Form1 -> E5 -> Text != "" &&  Form1 -> B5 -> Text != "")
      {
        temp = add( Form1 -> E5->Text,Form1 -> B5->Text);
         if (temp >= 10 )
          {
            Form1 -> R6 -> Text = IntToStr(temp-10);
            Form1 -> R5 -> Text = "1";
            Form1 -> Buf -> Text ="1" ;
           }
         else
            Form1 -> R6 -> Text = IntToStr(temp);
      }
  }
 else if (n == 2)
  {
    if ( Form1 -> E5 -> Text != "" &&  Form1 -> B5 -> Text != "")
       {
         if ( Form1 -> E4 -> Text != "" &&  Form1 -> B4 -> Text != "")
           {
             if (Form1 -> R5 -> Text !="")
                {
                  Form1 -> B4 -> Text = IntToStr ( add( Form1 -> B4->Text,Form1 -> R5->Text));
                }

             temp = add( Form1 -> E4->Text,Form1 -> B4->Text);
                if (temp >= 10 )
                   {
                    Form1 -> R5 -> Text = IntToStr(temp-10);
                    Form1 -> R4 -> Text = "1";
                    Form1 -> Buf -> Text ="1";
                   }
                 else
                   {
                    Form1 -> R5 -> Text = IntToStr(temp);
                    Form1 -> Buf -> Text ="";
                   }
           }
       }
  }
 else if (n == 3)
  {
    if (  Form1 -> E4 -> Text != "" &&  Form1 -> B4 -> Text != ""
                            &&  Form1 -> E3 -> Text != "" &&  Form1 -> B3 -> Text != "")
       {
        if ( Form1 -> E3 -> Text != "" &&  Form1 -> B3 -> Text != "")
          {
           if (Form1 -> R4 -> Text !="")
              {
                Form1 -> B3 -> Text = IntToStr ( add( Form1 -> B3->Text,Form1 -> R4->Text));
              }

            temp = add( Form1 -> E3->Text,Form1 -> B3->Text);
             if (temp >= 10 )
               {
                Form1 -> R4 -> Text = IntToStr(temp-10);
                Form1 -> Buf -> Text ="1" ;
                Form1 -> R3 -> Text = "1";
               }
             else
               {
                Form1 -> R4 -> Text = IntToStr(temp);
                Form1 -> Buf -> Text ="";
               }
          }
       }
  }
 else if (n == 4)
  {
   if ( Form1 -> E5 -> Text != "" &&  Form1 -> B5 -> Text != "" &&  Form1 -> E4 -> Text != "" &&  Form1 -> B4 -> Text != ""
                                             &&  Form1 -> E3 -> Text != "" &&  Form1 -> B3 -> Text != "")
       {
        if ( Form1 -> E2 -> Text != "" &&  Form1 -> B2 -> Text != "")
          {
           if (Form1 -> R3 -> Text !="")
             {
              Form1 -> B2-> Text = IntToStr ( add( Form1 -> B2->Text,Form1 -> R3->Text));
             }

              temp = add( Form1 -> E2->Text,Form1 -> B2->Text);
               if (temp >= 10 )
                 {
                  Form1 -> R3 -> Text = IntToStr(temp-10);
                  Form1 -> R2 -> Text = "1";
                  Form1 -> Buf -> Text ="1" ;
                 }
               else
                {
                 Form1 -> Buf -> Text ="";
                 Form1 -> R3 -> Text = IntToStr(temp);
                }
          }
       }
  }
 else if ( n== 5)
  {
   if (Form1 -> E5 -> Text != "" &&  Form1 -> B5 -> Text != ""
                              &&  Form1 -> E4 -> Text != "" &&  Form1 -> B4 -> Text != ""
                              &&  Form1 -> E3 -> Text != "" &&  Form1 -> B3 -> Text != ""
                              &&  Form1 -> E2 -> Text != "" &&  Form1 -> B2 -> Text != "")
     {
       if ( Form1 -> E1 -> Text != "" &&  Form1 -> B1 -> Text != "")
        {
         if (Form1 -> R2 -> Text !="")
          {
           Form1 -> B1-> Text = IntToStr ( add( Form1 -> B1->Text,Form1 -> R2->Text));
          }
           temp = add( Form1 -> E1->Text,Form1 -> B1->Text);
             if (temp >= 10 )
               {
                Form1 -> R2 -> Text = IntToStr(temp-10);
                Form1 -> R1 -> Text = "1";
                Form1 -> Buf -> Text ="1" ;
               }
             else
              {
               Form1 -> R2 -> Text = IntToStr(temp);
               Form1 -> Buf -> Text ="";

              }
        }
     }
  }
}


void Operations :: SubProcess (int n)
{
int temp,val,i,j;
 AnsiString Str;


 if (n == 1 )   // first Step
  {
    if ( Form1 -> E5 -> Text != "" &&  Form1 -> B5 -> Text != "")
       {
        if ( StrToInt ( Form1 -> E5->Text ) < StrToInt ( Form1 -> B5->Text) )
          {
           if ( Form1 -> E4 -> Text != "" &&  Form1 -> B4 -> Text != "")
             {
               Form1 -> EL4 -> Caption = Form1 -> E4 -> Text;
               Form1 -> E4->Text = IntToStr ( sub( Form1 -> E4->Text,"1") );

               //on ajoute la disaine et on effectue l'operation
               temp = add( Form1 -> E5->Text, "10");
               Form1 -> Buf1 -> Text = IntToStr ( temp);
               temp = sub( temp,Form1 -> B5->Text);
               Form1 -> R6 -> Text = IntToStr(temp);
               Form1 -> Buf -> Text ="-1";
             }
            else
             {
               temp = sub(Form1 -> E5->Text, Form1 -> B5->Text);
               Form1 -> R6 -> Text = IntToStr(abs(temp));
               Form1 -> R5 -> Text = "-";
               Form1 -> Buf -> Text ="";
             }
           }
         else
           {
              temp = sub(Form1 -> E5->Text, Form1 -> B5->Text);
               Form1 -> R6 -> Text = IntToStr(abs(temp));
               Form1 -> Buf -> Text ="";
           }
       }
   }
 else if (n == 2)
  {
    if ( Form1 -> E4 -> Text != "" &&  Form1 -> B4 -> Text != "")
       {
        if ( StrToInt ( Form1 -> E4->Text ) < StrToInt ( Form1 -> B4->Text) )
          {
           if ( Form1 -> E3 -> Text != "" &&  Form1 -> B3 -> Text != "")
             {
               Form1 -> EL3 -> Caption = Form1 -> E3 -> Text;
               Form1 -> E3->Text = IntToStr ( sub( Form1 -> E3->Text,"1") );

               //on ajoute la disaine et on effectue l'operation
               temp = add( Form1 -> E4->Text, "10");
               Form1 -> Buf1 -> Text = IntToStr ( temp);
               temp = sub( temp,Form1 -> B4->Text);
               Form1 -> R5 -> Text = IntToStr(temp);
               Form1 -> Buf -> Text ="-1";
             }
            else
             {
               temp = sub(Form1 -> E4->Text, Form1 -> B4->Text);
               Form1 -> R5 -> Text = IntToStr(abs(temp));
               Form1 -> R4 -> Text = "-";
               Form1 -> Buf -> Text ="";
             }
           }
         else
           {
              temp = sub(Form1 -> E4->Text, Form1 -> B4->Text);
               Form1 -> R5 -> Text = IntToStr(abs(temp));
               Form1 -> Buf -> Text ="";
           }
       }
   }
 else if (n == 3)
  {
   if ( Form1 -> E3 -> Text != "" &&  Form1 -> B3 -> Text != "")
       {
        if ( StrToInt ( Form1 -> E3->Text ) < StrToInt ( Form1 -> B3->Text) )
          {
           if ( Form1 -> E2 -> Text != "" &&  Form1 -> B2 -> Text != "")
             {
               Form1 -> EL2 -> Caption = Form1 -> E2 -> Text;
               Form1 -> E2->Text = IntToStr ( sub( Form1 -> E2->Text,"1") );

               //on ajoute la disaine et on effectue l'operation
               temp = add( Form1 -> E3->Text, "10");
               Form1 -> Buf1 -> Text = IntToStr ( temp);
               temp = sub( temp,Form1 -> B3->Text);
               Form1 -> R4 -> Text = IntToStr(temp);
               Form1 -> Buf -> Text ="-1";
             }
            else
             {
               temp = sub(Form1 -> E3->Text, Form1 -> B3->Text);
               Form1 -> R4 -> Text = IntToStr(abs(temp));
               Form1 -> R3 -> Text = "-";
               Form1 -> Buf -> Text ="";
             }
           }
         else
           {
              temp = sub(Form1 -> E3->Text, Form1 -> B3->Text);
               Form1 -> R4 -> Text = IntToStr(abs(temp));
               Form1 -> Buf -> Text ="";
           }
       }
   }
 else if (n == 4)
  {
   if ( Form1 -> E2 -> Text != "" &&  Form1 -> B2 -> Text != "")
       {
        if ( StrToInt ( Form1 -> E2->Text ) < StrToInt ( Form1 -> B2->Text) )
          {
           if ( Form1 -> E1 -> Text != "" &&  Form1 -> B1 -> Text != "")
             {
               Form1 -> EL1 -> Caption = Form1 -> E1 -> Text;
               Form1 -> E1->Text = IntToStr ( sub( Form1 -> E1->Text,"1") );

               //on ajoute la disaine et on effectue l'operation
               temp = add( Form1 -> E2->Text, "10");
               Form1 -> Buf1 -> Text = IntToStr ( temp);
               temp = sub( temp,Form1 -> B2->Text);
               Form1 -> R3 -> Text = IntToStr(temp);
               Form1 -> Buf -> Text ="-1";
             }
            else
             {
               temp = sub(Form1 -> E2->Text, Form1 -> B2->Text);
               Form1 -> R3 -> Text = IntToStr(abs(temp));
               Form1 -> R2 -> Text = "-";
               Form1 -> Buf -> Text ="";
             }
           }
         else
           {
              temp = sub(Form1 -> E2->Text, Form1 -> B2->Text);
               Form1 -> R3 -> Text = IntToStr(abs(temp));
               Form1 -> Buf -> Text ="";
           }
       }
   }
 else if ( n== 5)
   {
   if ( Form1 -> E1 -> Text != "" &&  Form1 -> B1 -> Text != "")
       {
         if ( StrToInt ( Form1 -> E1->Text ) < StrToInt ( Form1 -> B1->Text) )
          {
               temp = sub(Form1 -> E1->Text, Form1 -> B1->Text);
               Form1 -> R2 -> Text = IntToStr(abs(temp));
               Form1 -> R1 -> Text = "-";
               Form1 -> Buf -> Text ="";
           }
         else
           {
              temp = sub(Form1 -> E1->Text, Form1 -> B1->Text);
              Form1 -> R2 -> Text = IntToStr(abs(temp));
              Form1 -> Buf -> Text ="";
              if (Rev == 1)
               Form1 -> R1 -> Text = "-";
           }
       }
   }
}



  void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  int i,j;

 if (Sign -> Caption == "+")
  {
   if  (bt1 == 1)
     Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
      if (BoxIsEmpty(1))
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
      else
       {
        Op1 -> AddProcess(1);
        bt1 = 1;
       }
   }
 else if (Sign -> Caption == "-")
  {
   if  (bt1 == 1)
     Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
      if (BoxIsEmpty(1))
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
      else
       {
        Op1 -> SubProcess(1);
        bt1 = 1;
       }
   }
 else
  if (Sign -> Caption == "")
    Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(2);
  }
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
 int i,j;

 if (Sign -> Caption == "+")
  {
   if  (bt2 == 0)
     {
       if (BoxIsEmpty(2))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> AddProcess(2);
          bt2 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  if (Sign -> Caption == "-")
  {
   if  (bt2 == 0)
     {
       if (BoxIsEmpty(2))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> SubProcess(2);
          bt2 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  if (Sign -> Caption == "")
    Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(2);



}
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
int i,j;

 if (Sign -> Caption == "+")
  {
   if  (bt3 == 0)
     {
       if (BoxIsEmpty(3))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> AddProcess(3);
          bt3 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
 if (Sign -> Caption == "-")
  {
   if  (bt3 == 0)
     {
       if (BoxIsEmpty(3))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> SubProcess(3);
          bt3 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  if (Sign -> Caption == "")
    Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(2);


}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
int i,j;

 if (Sign -> Caption == "+")
  {
   if  (bt4 == 0)
     {
       if (BoxIsEmpty(4))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> AddProcess(4);
          bt4 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  if (Sign -> Caption == "-")
  {
   if  (bt4 == 0)
     {
       if (BoxIsEmpty(4))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> SubProcess(4);
          bt4 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  if (Sign -> Caption == "")
    Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(2);

}
//---------------------------------------------------------------------------








void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
Rev = 0;
 bt1 = 0,bt2= 0, bt3 = 0,bt4 =0,bt5=0;
E1 -> Text = ""; E2 -> Text =""; E3 -> Text ="";
E4 -> Text = ""; E5 -> Text = "";

B1 -> Text = ""; B2 -> Text ="";
B3 -> Text = ""; B4 -> Text =""; B5 -> Text = "";

R1 -> Text = ""; R2 -> Text =""; R3 -> Text = "";
R4 -> Text ="";R5 -> Text = "";R6 -> Text = "";
Form1 -> MsgBox-> Lines -> Text = "Message Box";
Form1 -> Buf -> Text ="";
Form1 -> Buf1 -> Text ="";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{
int i,j;


 if (Sign -> Caption == "+")
  {
   if  (bt5 == 0)
     {
       if (BoxIsEmpty(5))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> AddProcess(5);
          bt5 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  
 if (Sign -> Caption == "-")
  {
   if  (bt5 == 0)
     {
       if (BoxIsEmpty(5))
         Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(1);
       else
         {
          Op1 -> SubProcess(5);
          bt5 = 1;
         }
      }
     else
       Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(0);
  }
 else
  if (Sign -> Caption == "")
    Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(2);


}
//---------------------------------------------------------------------------





void __fastcall TForm1::ReversClick(TObject *Sender)
{
Rev = 1;
 AnsiString t1,t2,t3,t4,t5;

 t1 = E1 -> Text ;
 t2 = E2 -> Text ;
 t3 = E3 -> Text ;
 t4 = E4 -> Text ;
 t5 = E5 -> Text ;

 E1 -> Text = B1 -> Text ;
 E2 -> Text = B2 -> Text ;
 E3 -> Text = B3 -> Text ;
 E4 -> Text = B4 -> Text ;
 E5 -> Text = B5 -> Text ;

 B1 -> Text = t1 ;
 B2 -> Text = t2 ;
 B3 -> Text = t3 ;
 B4 -> Text = t4 ;
 B5 -> Text = t5 ;

}
//---------------------------------------------------------------------------





void __fastcall TForm1::ReversMouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
 Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(3);
}
//---------------------------------------------------------------------------





void __fastcall TForm1::BitBtn8Click(TObject *Sender)
{
 Form1 -> Close();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn7Click(TObject *Sender)
{
 Form1 -> MsgBox-> Lines -> Text = Err -> ErrorMsg(4);
}
//---------------------------------------------------------------------------






void __fastcall TForm1::BitBtn6Click(TObject *Sender)
{
int temp;

      Label3 -> Caption =   Edit1->Text;
       Label4 -> Caption =   Edit2->Text;

 
 if (Sign -> Caption == "+")
      {
   temp = Op1 -> add(Edit1->Text, Edit2 ->Text);
              Form1 -> Label5 -> Caption = IntToStr(temp);
     Label7 -> Caption ="+";
      }

  if (Sign -> Caption == "-")
    {
         Label7 -> Caption ="-";
   temp = Op1 -> sub(Edit1->Text, Edit2 ->Text);
              Form1 -> Label5 -> Caption = IntToStr(temp);
     }
 }
//---------------------------------------------------------------------------

Соседние файлы в папке OOP