Студопедия Главная Случайная страница Обратная связь

Разделы: Автомобили Астрономия Биология География Дом и сад Другие языки Другое Информатика История Культура Литература Логика Математика Медицина Металлургия Механика Образование Охрана труда Педагогика Политика Право Психология Религия Риторика Социология Спорт Строительство Технология Туризм Физика Философия Финансы Химия Черчение Экология Экономика Электроника

КАЗАНЬ - 2013





Задача № 1

1. Постановка задачи.

Составить программу калькулятор.

 

2. Листинг программы.

 

#pragma once

 

namespace калькулятор {

 

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;

 

 

public ref class Form1: public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

 

ac=0;

fd=true;

label1->Text="0";

}

 

protected:

 

~Form1()

{

if (components)

{

delete components;

}

}

private: System::Windows::Forms::Label^ label1;

protected:

private: System::Windows::Forms::Button^ button1;

private: System::Windows::Forms::Button^ button2;

private: System::Windows::Forms::Button^ button3;

private: System::Windows::Forms::Button^ button4;

private: System::Windows::Forms::Button^ button5;

private: System::Windows::Forms::Button^ button6;

private: System::Windows::Forms::Button^ button7;

private: System::Windows::Forms::Button^ button8;

private: System::Windows::Forms::Button^ button9;

private: System::Windows::Forms::Button^ button10;

private: System::Windows::Forms::Button^ button11;

private: System::Windows::Forms::Button^ button12;

private: System::Windows::Forms::Button^ button13;

private: System::Windows::Forms::Button^ button14;

private: System::Windows::Forms::Button^ button15;

private: System::Windows::Forms::Button^ button16;

private: System::Windows::Forms::Button^ button17;

 

private:

 

System::ComponentModel::Container ^components;

double ac;

int op;

bool fd;

 

#pragma region Windows Form Designer generated code

 

void InitializeComponent(void)

{

this->label1 = (gcnew System::Windows::Forms::Label());

this->button1 = (gcnew System::Windows::Forms::Button());

this->button2 = (gcnew System::Windows::Forms::Button());

this->button3 = (gcnew System::Windows::Forms::Button());

this->button4 = (gcnew System::Windows::Forms::Button());

this->button5 = (gcnew System::Windows::Forms::Button());

this->button6 = (gcnew System::Windows::Forms::Button());

this->button7 = (gcnew System::Windows::Forms::Button());

this->button8 = (gcnew System::Windows::Forms::Button());

this->button9 = (gcnew System::Windows::Forms::Button());

this->button10 = (gcnew System::Windows::Forms::Button());

this->button11 = (gcnew System::Windows::Forms::Button());

this->button12 = (gcnew System::Windows::Forms::Button());

this->button13 = (gcnew System::Windows::Forms::Button());

this->button14 = (gcnew System::Windows::Forms::Button());

this->button15 = (gcnew System::Windows::Forms::Button());

this->button16 = (gcnew System::Windows::Forms::Button());

this->button17 = (gcnew System::Windows::Forms::Button());

this->SuspendLayout();

//

// label1

//

this->label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;

this->label1->Location = System::Drawing::Point(13, 9);

this->label1->Name = L"label1";

this->label1->Size = System::Drawing::Size(177, 19);

this->label1->TabIndex = 0;

this->label1->Text = L"label1";

//

// button1

//

this->button1->Location = System::Drawing::Point(13, 35);

this->button1->Name = L"button1";

this->button1->Size = System::Drawing::Size(55, 23);

this->button1->TabIndex = 1;

this->button1->Tag = L"7";

this->button1->Text = L"7";

this->button1->UseVisualStyleBackColor = true;

this->button1->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button2

//

this->button2->Location = System::Drawing::Point(13, 64);

this->button2->Name = L"button2";

this->button2->Size = System::Drawing::Size(55, 23);

this->button2->TabIndex = 2;

this->button2->Tag = L"4";

this->button2->Text = L"4";

this->button2->UseVisualStyleBackColor = true;

this->button2->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button3

//

this->button3->Location = System::Drawing::Point(13, 93);

this->button3->Name = L"button3";

this->button3->Size = System::Drawing::Size(55, 23);

this->button3->TabIndex = 3;

this->button3->Tag = L"1";

this->button3->Text = L"1";

this->button3->UseVisualStyleBackColor = true;

this->button3->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button4

//

this->button4->Location = System::Drawing::Point(74, 35);

this->button4->Name = L"button4";

this->button4->Size = System::Drawing::Size(55, 23);

this->button4->TabIndex = 4;

this->button4->Tag = L"8";

this->button4->Text = L"8";

this->button4->UseVisualStyleBackColor = true;

this->button4->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button5

//

this->button5->Location = System::Drawing::Point(74, 64);

this->button5->Name = L"button5";

this->button5->Size = System::Drawing::Size(55, 23);

this->button5->TabIndex = 5;

this->button5->Tag = L"5";

this->button5->Text = L"5";

this->button5->UseVisualStyleBackColor = true;

this->button5->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button6

//

this->button6->Location = System::Drawing::Point(74, 93);

this->button6->Name = L"button6";

this->button6->Size = System::Drawing::Size(55, 23);

this->button6->TabIndex = 6;

this->button6->Tag = L"2";

this->button6->Text = L"2";

this->button6->UseVisualStyleBackColor = true;

this->button6->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button7

//

this->button7->Location = System::Drawing::Point(135, 35);

this->button7->Name = L"button7";

this->button7->Size = System::Drawing::Size(55, 23);

this->button7->TabIndex = 7;

this->button7->Tag = L"9";

this->button7->Text = L"9";

this->button7->UseVisualStyleBackColor = true;

this->button7->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button8

//

this->button8->Location = System::Drawing::Point(135, 64);

this->button8->Name = L"button8";

this->button8->Size = System::Drawing::Size(55, 23);

this->button8->TabIndex = 8;

this->button8->Tag = L"6";

this->button8->Text = L"6";

this->button8->UseVisualStyleBackColor = true;

this->button8->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button9

//

this->button9->Location = System::Drawing::Point(135, 93);

this->button9->Name = L"button9";

this->button9->Size = System::Drawing::Size(55, 23);

this->button9->TabIndex = 9;

this->button9->Tag = L"3";

this->button9->Text = L"3";

this->button9->UseVisualStyleBackColor = true;

this->button9->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button10

//

this->button10->Location = System::Drawing::Point(13, 122);

this->button10->Name = L"button10";

this->button10->Size = System::Drawing::Size(55, 23);

this->button10->TabIndex = 10;

this->button10->Tag = L"0";

this->button10->Text = L"0";

this->button10->UseVisualStyleBackColor = true;

this->button10->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button11

//

this->button11->Location = System::Drawing::Point(74, 122);

this->button11->Name = L"button11";

this->button11->Size = System::Drawing::Size(55, 23);

this->button11->TabIndex = 11;

this->button11->Tag = L"-1";

this->button11->Text = L",";

this->button11->UseVisualStyleBackColor = true;

this->button11->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button12

//

this->button12->Location = System::Drawing::Point(197, 122);

this->button12->Name = L"button12";

this->button12->Size = System::Drawing::Size(55, 23);

this->button12->TabIndex = 12;

this->button12->Tag = L"-2";

this->button12->Text = L"=";

this->button12->UseVisualStyleBackColor = true;

this->button12->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button13

//

this->button13->Location = System::Drawing::Point(135, 122);

this->button13->Name = L"button13";

this->button13->Size = System::Drawing::Size(56, 23);

this->button13->TabIndex = 13;

this->button13->Tag = L"-5";

this->button13->Text = L"C";

this->button13->UseVisualStyleBackColor = true;

this->button13->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button14

//

this->button14->Location = System::Drawing::Point(196, 64);

this->button14->Name = L"button14";

this->button14->Size = System::Drawing::Size(56, 23);

this->button14->TabIndex = 14;

this->button14->Tag = L"-6";

this->button14->Text = L"*";

this->button14->UseVisualStyleBackColor = true;

this->button14->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button15

//

this->button15->Location = System::Drawing::Point(196, 35);

this->button15->Name = L"button15";

this->button15->Size = System::Drawing::Size(56, 23);

this->button15->TabIndex = 15;

this->button15->Tag = L"-4";

this->button15->Text = L"-";

this->button15->UseVisualStyleBackColor = true;

this->button15->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button16

//

this->button16->Location = System::Drawing::Point(196, 5);

this->button16->Name = L"button16";

this->button16->Size = System::Drawing::Size(56, 23);

this->button16->TabIndex = 16;

this->button16->Tag = L"-3";

this->button16->Text = L"+";

this->button16->UseVisualStyleBackColor = true;

this->button16->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// button17

//

this->button17->Location = System::Drawing::Point(196, 93);

this->button17->Name = L"button17";

this->button17->Size = System::Drawing::Size(56, 23);

this->button17->TabIndex = 17;

this->button17->Tag = L"-7";

this->button17->Text = L"/";

this->button17->UseVisualStyleBackColor = true;

this->button17->Click += gcnew System::EventHandler(this, &Form1::button10_Click);

//

// Form1

//

this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);

this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

this->ClientSize = System::Drawing::Size(270, 165);

this->Controls->Add(this->button17);

this->Controls->Add(this->button16);

this->Controls->Add(this->button15);

this->Controls->Add(this->button14);

this->Controls->Add(this->button13);

this->Controls->Add(this->button12);

this->Controls->Add(this->button11);

this->Controls->Add(this->button10);

this->Controls->Add(this->button9);

this->Controls->Add(this->button8);

this->Controls->Add(this->button7);

this->Controls->Add(this->button6);

this->Controls->Add(this->button5);

this->Controls->Add(this->button4);

this->Controls->Add(this->button3);

this->Controls->Add(this->button2);

this->Controls->Add(this->button1);

this->Controls->Add(this->label1);

this->Name = L"Form1";

this->Text = L"Form1";

this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);

this->ResumeLayout(false);

 

}

#pragma endregion

private: System::Void button10_Click(System::Object^ sender, System::EventArgs^ e) {

System::Windows::Forms::Button ^btn;

btn=(Button^)sender;

if(Convert::ToInt32(btn->Tag)>0)

{

if(fd)

{label1->Text=btn->Text;

fd=false;

}

else

label1->Text+=btn->Text;

return;

}

if(Convert::ToInt32(btn->Tag)==0)

{

if(fd)label1->Text=btn->Text;

if(label1->Text!="0")

label1->Text+=btn->Text;

return;

}

if(Convert::ToInt32(btn->Tag)==-1)

{

if(fd)

{

label1->Text="0,";

fd=false;}

else

if(label1->Text->IndexOf(",")==-1)

label1->Text+=btn->Text;

return;

}

if(Convert::ToInt32(btn->Tag)==-5)

{

ac=0;

op=0;

label1->Text="0";

fd=true;

return;}

if(Convert::ToInt32(btn->Tag)<-1)

{

double n;

n=Convert::ToDouble(label1->Text);

if(ac!=0)

{

switch(op)

{

case-3:ac+=n;break;

case-4:ac-=n;break;

case-2:ac=n;break;

case-7:ac/=n;break;

case-6:ac*=n;break;

}

label1->Text=ac.ToString("N");

}

else

ac=n;

op=Convert::ToInt32(btn->Tag);

fd=true;

}}

 

 

private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

}

};

}

 

3.Входные величины: необходимо набрать с клавиатуры нужные данные.

 

4.Выходные величины:

 

 

 

5.Вывод. При выполнении работы мы приобрели навыки программирования в приложении Windows Forms.

 







Дата добавления: 2015-10-01; просмотров: 395. Нарушение авторских прав; Мы поможем в написании вашей работы!




Аальтернативная стоимость. Кривая производственных возможностей В экономике Буридании есть 100 ед. труда с производительностью 4 м ткани или 2 кг мяса...


Вычисление основной дактилоскопической формулы Вычислением основной дактоформулы обычно занимается следователь. Для этого все десять пальцев разбиваются на пять пар...


Расчетные и графические задания Равновесный объем - это объем, определяемый равенством спроса и предложения...


Кардиналистский и ординалистский подходы Кардиналистский (количественный подход) к анализу полезности основан на представлении о возможности измерения различных благ в условных единицах полезности...

Приготовление дезинфицирующего рабочего раствора хлорамина Задача: рассчитать необходимое количество порошка хлорамина для приготовления 5-ти литров 3% раствора...

Дезинфекция предметов ухода, инструментов однократного и многократного использования   Дезинфекция изделий медицинского назначения проводится с целью уничтожения патогенных и условно-патогенных микроорганизмов - вирусов (в т...

Машины и механизмы для нарезки овощей В зависимости от назначения овощерезательные машины подразделяются на две группы: машины для нарезки сырых и вареных овощей...

Йодометрия. Характеристика метода Метод йодометрии основан на ОВ-реакциях, связанных с превращением I2 в ионы I- и обратно...

Броматометрия и бромометрия Броматометрический метод основан на окислении вос­становителей броматом калия в кислой среде...

Метод Фольгарда (роданометрия или тиоцианатометрия) Метод Фольгарда основан на применении в качестве осадителя титрованного раствора, содержащего роданид-ионы SCN...

Studopedia.info - Студопедия - 2014-2025 год . (0.012 сек.) русская версия | украинская версия