Материал: Объектно-ориентированное программирование на языке С++

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

//m.print(StringGrid1,j);

}(char b)

{MessageDlg ("Заполните поля!", mtError,TMsgDlgButtons() << mbOK,0);

}(int a)

{MessageDlg ("Заполнены не все поля! Будут выведены значения по умолчанию!", mtError,TMsgDlgButtons() << mbOK,0);

moroz_kamera m;.print(StringGrid1,j);=&m;

// p->print(StringGrid1,j);

}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}(i==1) //Холодильники

{

{((Edit1->Text=="") && (Edit2->Text=="")&& (Edit3->Text=="")&&(Edit6->Text=="")&&(Edit18->Text=="")&&(Edit19->Text==""))

{throw(1);}((Edit1->Text=="") || (Edit2->Text=="")|| (Edit3->Text=="")||(Edit6->Text=="")&&(Edit18->Text=="")&&(Edit19->Text==""))

{throw('a');}= (Edit1->Text);= StrToInt(Edit2->Text);= StrToInt(Edit3->Text);_temp =StrToInt( Edit6->Text);_kamer=StrToInt(Edit18->Text);_komponovki=Edit19->Text;m(name,power,cena,max_temp,kol_kamer,shema_komponovki);=&m;>print(StringGrid2,j1);

// m.print(StringGrid2,j1);

}(char b)

{MessageDlg ("Заполните поля!", mtError,TMsgDlgButtons() << mbOK,0);

}(int a)

{MessageDlg ("Заполнены не все поля! Будут выведены значения по умолчанию!", mtError,TMsgDlgButtons() << mbOK,0);

holodilniki m;.print(StringGrid2,j1);}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}(i==2) //Микроволновые печи

{

{

if ((Edit1->Text=="") && (Edit2->Text=="")&& (Edit3->Text=="")&&(Edit7->Text==""))

{throw(1);}((Edit1->Text=="") || (Edit2->Text=="")|| (Edit3->Text=="")||(Edit7->Text==""))

{throw('a');}= (Edit1->Text);= StrToInt(Edit2->Text);= StrToInt(Edit3->Text);=Edit7->Text;_pechi m(name,power,cena,tip);=&m;>print(StringGrid3,j2);

//m.print(StringGrid3,j2);

}(char b)

{MessageDlg ("Заполните поля!", mtError,TMsgDlgButtons() << mbOK,0);

}(int a)

{MessageDlg ("Заполнены не все поля! Будут выведены значения по умолчанию!", mtError,TMsgDlgButtons() << mbOK,0);

microv_pechi m;.print(StringGrid3,j2);}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}(i==3) //Пылесосы

{

{((Edit1->Text=="") && (Edit2->Text=="")&& (Edit3->Text=="")

&&(Edit4->Text=="")&&(Edit20->Text=="")&&(Edit21->Text==""))

{throw(1);}((Edit1->Text=="") || (Edit2->Text=="")|| (Edit3->Text=="")

||(Edit4->Text=="")||(Edit20->Text=="")||(Edit21->Text==""))

{throw('a');}= (Edit1->Text);= StrToInt(Edit2->Text);= StrToInt(Edit3->Text);= StrToInt(Edit4->Text);=StrToInt(Edit20->Text);=StrToInt(Edit21->Text);m(name,power,cena,obv1,pow11,kolnas);=&m;>print(StringGrid4,j3);

//m.print(StringGrid4,j3);

}(char b)

{MessageDlg ("Заполните поля!", mtError,TMsgDlgButtons() << mbOK,0);

}(int a)

{MessageDlg ("Заполнены не все поля! Будут выведены значения по умолчанию!", mtError,TMsgDlgButtons() << mbOK,0);

pilesos m;.print(StringGrid4,j3);

}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}

}

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

//копирование для БК__fastcall TForm1::Button2Click(TObject *Sender)

{

{q1;name,raspoloshenie;power,cena,max_temp,kol_kamer;=Edit12->Text;(q1 == "") {throw(1);}->Visible=True;->Visible=True;pos = StrToInt(Edit12->Text);= StringGrid1->Cells [0][pos];= StrToInt(StringGrid1->Cells [1][pos]);= StrToInt(StringGrid1->Cells [2][pos]);_temp=StrToInt(StringGrid1->Cells [3][pos]);_kamer= StrToInt(StringGrid1->Cells [4][pos]);=StringGrid1->Cells [5][pos];_kamera n(name,power,cena,max_temp,kol_kamer,raspoloshenie);

moroz_kamera m(n); //в объект m копируем n

m.print(StringGrid8, x1);

}(int a)

{MessageDlg ("Введите № записи для копирования", mtError, TMsgDlgButtons() << mbOK,0);

}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}

//Сравнение для канц товаров__fastcall TForm1::Button3Click(TObject *Sender)

{try

{int a1, a2;o1,o2;=Edit10->Text;=Edit11->Text;(o1 == "") {throw(1);}(o2 == "") {throw(2);}=StrToInt(Edit10->Text);=StrToInt(Edit11->Text);m1(StringGrid2->Cells[0][a1],StrToInt(StringGrid2->Cells[1][a1]),StrToInt(StringGrid2->Cells[2][a1]),StrToInt(StringGrid2->Cells[3][a1]),StrToInt(StringGrid2->Cells[4][a1]),StringGrid2->Cells[5][a1]);pic m2(StringGrid2->Cells[0][a2],StrToInt(StringGrid2->Cells[1][a2]),StrToInt(StringGrid2->Cells[2][a2]),StrToInt(StringGrid2->Cells[3][a2]),StrToInt(StringGrid2->Cells[4][a2]),StringGrid2->Cells[5][a2]);if (m1==m2) {Edit13->Text = "Равны";} else {Edit13->Text = "Не равны";} //сравнение

}(int a)

{MessageDlg ("Заполните поля!", mtError, TMsgDlgButtons() << mbOK,0);}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}

//Сравнение__fastcall TForm1::Button3Click(TObject *Sender)

{try{a1, a2;o1,o2;=Edit10->Text;=Edit11->Text;(o1 == "") {throw(1);}(o2 == "") {throw(2);}=StrToInt(Edit10->Text);=StrToInt(Edit11->Text);ob1(StringGrid2->Cells[0][a1],StrToInt(StringGrid2->Cells[1][a1]),StrToInt(StringGrid2->Cells[2][a1]),StrToInt(StringGrid2->Cells[3][a1]),StrToInt(StringGrid2->Cells[4][a1]),StringGrid2->Cells[5][a1]);holodilniki ob2(StringGrid2->Cells[0][a2],StrToInt(StringGrid2->Cells[1][a2]),StrToInt(StringGrid2->Cells[2][a2]),StrToInt(StringGrid2->Cells[3][a2]),StrToInt(StringGrid2->Cells[4][a2]),StringGrid2->Cells[5][a2]);if (ob1==ob2) {Edit13->Text = "Равны";} else {Edit13->Text = "Не равны";} //сравнение (перегрузка)

}catch (int a)

{MessageDlg ("Заполните поля!", mtError, TMsgDlgButtons() << mbOK,0);}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

} //------------------ Edit14->Color=clRed;->Color=clRed;}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}__fastcall TForm1::Button4Click(TObject *Sender)

{(RadioGroup1->ItemIndex==0)

{i=1;_kamera m;.clear("moroz_kamera");(StringGrid1->Cells[0][i]!="")

{_kamera ob1(StringGrid1->Cells[0][i],StrToInt(StringGrid1->Cells[1][i]),StrToInt(StringGrid1->Cells[2][i]),StrToInt(StringGrid1->Cells[3][i]),StrToInt(StringGrid1->Cells[4][i]),StringGrid1->Cells[5][i]);.save("moroz_kamera");=i+1;

}

}(RadioGroup1->ItemIndex==1)

{i=1;m;.clear("holodilniki");(StringGrid2->Cells[0][i]!="")

{ob1(StringGrid2->Cells[0][i],StrToInt(StringGrid2->Cells[1][i]),StrToInt(StringGrid2->Cells[2][i]),StrToInt(StringGrid2->Cells[3][i]),StrToInt(StringGrid2->Cells[4][i]),StringGrid2->Cells[5][i]);.save("holodilniki");=i+1;

}

}(RadioGroup1->ItemIndex==2)

{i=1;_pechi m;.clear("microv_pechi");(StringGrid3->Cells[0][i]!="")

{_pechi ob1(StringGrid3->Cells[0][i],StrToInt(StringGrid3->Cells[1][i]),StrToInt(StringGrid3->Cells[2][i]),StringGrid3->Cells[3][i]);.save("microv_pechi");=i+1;

}

}(RadioGroup1->ItemIndex==3)

{i=1;m;.clear("pilesos");(StringGrid4->Cells[0][i]!="")

{ob1(StringGrid4->Cells[0][i],StrToInt(StringGrid4->Cells[1][i]),StrToInt(StringGrid4->Cells[2][i]),StrToInt(StringGrid4->Cells[3][i]),StrToInt(StringGrid4->Cells[4][i]),StrToInt(StringGrid4->Cells[5][i]));.save("pilesos");=i+1;

}}

} ;

//загрузить

//---------------------------------------------------------------__fastcall TForm1::Button5Click(TObject *Sender)

{(RadioGroup1->ItemIndex==0)

{_kamera m;.load("moroz_kamera",StringGrid1,j1);

}(RadioGroup1->ItemIndex==1)

{m;.load("holodilniki",StringGrid2,j2);

}(RadioGroup1->ItemIndex==2)

{_pechi m;.load("microv_pechi",StringGrid3,j3);

}(RadioGroup1->ItemIndex==3)

{m;.load("pilesos",StringGrid4,j4);

}}

//соритровка по убываниюsort_ub (TStringGrid * s, int a)

{b,c;e;(int i=1; s->Cells[a][i]!="";i++)(int j=i+1;s->Cells[a][j]!="";j++)

{ b =StrToInt(s->Cells[a][i]);= StrToInt(s->Cells[a][j]);(c>b)

{(int j1=0; j1<s->ColCount;j1++) //меняются строки

{= s->Cells[j1][i];>Cells[j1][i] = s->Cells[j1][j];>Cells[j1][j]= e;

//Form1->Refresh();

}}

}

};sort_voz (TStringGrid * s, int a)

{b,c;e;(int i=1; s->Cells[a][i]!="";i++)(int j=i+1;s->Cells[a][j]!="";j++)

{ b =StrToInt(s->Cells[a][i]);= StrToInt(s->Cells[a][j]);(c<b)

{(int j1=0; j1<s->ColCount;j1++)

{= s->Cells[j1][i];>Cells[j1][i] = s->Cells[j1][j];->Cells[j1][j]= e;

}}}};

// сортировка по возрастанию

void sort_voz (TStringGrid * s, int a)

{b,c;e;(int i=1; s->Cells[a][i]!="";i++)(int j=i+1;s->Cells[a][j]!="";j++)

{ b =StrToInt(s->Cells[a][i]);= StrToInt(s->Cells[a][j]);(c<b)

{(int j1=0; j1<s->ColCount;j1++)

{= s->Cells[j1][i];>Cells[j1][i] = s->Cells[j1][j];>Cells[j1][j]= e;

// Form1->Refresh();

}}

}

};__fastcall TForm1::Button7Click(TObject *Sender)

{=0;=0;=0;=0;=0;=0;=0;=0;(int i = 0; i < StringGrid1->ColCount; i++)(int j = 1; j < StringGrid1->RowCount; j++)->Cells[i][j] = "";

}__fastcall TForm1::Button8Click(TObject *Sender)

{

{a1, a2;o1,o2;=Edit9->Text;=Edit22->Text;(o1 == "") {throw(1);}(o2 == "") {throw(2);}=StrToInt(Edit9->Text);=StrToInt(Edit22->Text);_pechi ob1(StringGrid3->Cells[0][a1],StrToInt(StringGrid3->Cells[1][a1]),StrToInt(StringGrid3->Cells[2][a1]),StringGrid3->Cells[3][a1]);microv_pechi ob2(StringGrid3->Cells[0][a2],StrToInt(StringGrid3->Cells[1][a2]),StrToInt(StringGrid3->Cells[2][a2]),StringGrid3->Cells[3][a2]);if (ob1==ob2) {Edit23->Text = "Равны";} else {Edit23->Text = "Не равны";} //сравнение (перегрузка)}(int a)

{MessageDlg ("Заполните поля для ввода", mtError, TMsgDlgButtons() << mbOK,0);->Text=clRed;->Text=clRed;}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}__fastcall TForm1::Button9Click(TObject *Sender)

{

{a1, a2;o1,o2;=Edit24->Text;=Edit25->Text;(o1 == "") {throw(1);}(o2 == "") {throw(2);}=StrToInt(Edit24->Text);=StrToInt(Edit25->Text);ob1(StringGrid4->Cells[0][a1],StrToInt(StringGrid4->Cells[1][a1]),StrToInt(StringGrid4->Cells[2][a1]),StrToInt(StringGrid4->Cells[3][a1]),StrToInt(StringGrid4->Cells[4][a1]),StrToInt(StringGrid4->Cells[5][a1]));pilesos ob2(StringGrid4->Cells[0][a2],StrToInt(StringGrid4->Cells[1][a2]),StrToInt(StringGrid4->Cells[2][a2]),StrToInt(StringGrid4->Cells[3][a2]),StrToInt(StringGrid4->Cells[4][a1]),StrToInt(StringGrid4->Cells[5][a1]));if (ob1==ob2) {Edit26->Text = "Равны";} else {Edit26->Text = "Не равны";} //сравнение (перегрузка)

}(int a)

{MessageDlg ("Заполните поля для ввода", mtError, TMsgDlgButtons() << mbOK,0);

}(EConvertError &err)

{MessageDlg ("Проверьте ввод данных", mtError,TMsgDlgButtons() << mbOK,0);}

}__fastcall TForm1::Edit4KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit20KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit21KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit3KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit24KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------------------__fastcall TForm1::Edit25KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit12KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit6KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit18KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

//---------------------------------------------------------------__fastcall TForm1::Edit5KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit8KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit9KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit22KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit14KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//--------------------------------------------------------------__fastcall TForm1::Edit15KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//-------------------------------------------------------------__fastcall TForm1::Edit10KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

//---------------------------------------------------------------__fastcall TForm1::Edit11KeyPress(TObject *Sender, char &Key)

{(((Key < '0') || (Key > '9')) && (Key != VK_BACK)) Key = NULL;

}

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

Приложение 3. Руководство пользователя

 

Общие сведения о программе

Данный программный продукт предназначен для работы с объектами предметной области "Бытовая техника". В программе реализованы следующие функции:

ввод данных с клавиатуры;

загрузка данных из файла;

сохранение данных в файл;

просмотр данных об объектах выбранного класса;

сортировка данных об объектах выбранного класса, по полю "цена";

сравнение объектов по цене

копирование данных;

Описание установки

Данная программа не требует установки.

Описание запуска

Для запуска программы необходимо запустить файл с расширением .exe, находящийся в рабочем каталоге программы. После этого откроется главная форма программного продукта (Рис.1 "Главное окно программы").

Рис. П3.1. Главное окно программы.

 

Ввод данных с клавиатуры.

Для ввода данных необходимо выбрать в меню необходимую бытовую технику, заполнить поля "Название", "Мощность", "Стоимость" и соответствующие поля различных предметов интерьера. Далее нажать кнопку "Добавить", при этом предмет добавиться в таблицу.

Рис. П3.2. Ввод данных.

 

Файловый ввод / вывод.

Для файлового ввода / вывод необходимо воспользоваться кнопками "Сохранить" и "Загрузить".

Сортировка данных.

Сортировка осуществляется по полю "Цена", для ее осуществления необходимо выбрать вид сортировки: по возрастанию или по убыванию.

Рис. П3.3. Исходные данные.

Рис. П3.4. Сортировка по возрастанию.

Рис. П3.5. Сортировка по убыванию.

 

Сравнение данных.

Для сравнения данных необходимо ввести номера элементов интерьера в таблице по счету и нажать на кнопку "Сравнить".

Рис. П3.6. Сравнение по цене.

Рис. П3.7. Сравнение по цене.

 

Копирование данных.

Для копирования данных (строки таблицы) необходимо внести номер таблицы и нажать кнопку "Копировать", при этом появится новая таблица с результатом копирования.

Рис. П3.8. Копирование данных.

 

 

Обработка исключительных ситуаций

В программе предусмотрена обработка исключительных ситуации.

)        Если заполнены не все поля, появляется сообщение.

Рис. П3.11. Ошибка ввода.

)        Где предусмотрено вводить числовые значения невозможен ввод букв.