- •Курсовая работа
- •На тему: Проектирование и реализация программ в технологии «абстрактных типов данных»
- •Задание
- •Общие требования
- •Тип числа – «Калькулятор простых дробей». Требования.
- •Необходимо предусмотреть следующие варианты использования (прецеденты) калькулятора:
- •Спецификация типа данных «простые дроби».
- •Спецификация типа данных «память».
- •Операции
- •Спецификация типа данных «Процессор».
- •Form1.H
- •InitializeComponent();
- •If (components)
- •Void InitializeComponent(void)
- •Void SetOperation(tOprtn toprtn) {
- •Void SetFunction(tFunc tfunc) {
- •Interface class Operation {
- •Int countOp;
- •Void Run() {
- •Void PrepareMemoryFunction() {
- •Void PostAction() {
- •Void ResetController() {
- •Void set(bool onPrepare) {
- •Void set(bool onOperationClicked) {
- •Поле ввода
- •Управление вычислением
- •Дополнительные возможности
Form1.H
#pragma once
#include "Controller.cpp"
#include "FunctionOperation.cpp"
#include "ArithmeticOperation.cpp"
namespace kw_stp {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
If (components)
{
delete components;
}
}
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::Windows::Forms::Button^ button18;
private: System::Windows::Forms::Button^ button19;
private: System::Windows::Forms::Button^ button20;
private: System::Windows::Forms::Button^ button21;
private: System::Windows::Forms::Button^ button22;
private: System::Windows::Forms::Button^ button24;
private: System::Windows::Forms::Button^ button23;
private: System::Windows::Forms::Button^ button25;
private: System::Windows::Forms::Button^ button26;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Button^ button27;
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
Void InitializeComponent(void)
{
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->button18 = (gcnew System::Windows::Forms::Button());
this->button19 = (gcnew System::Windows::Forms::Button());
this->button20 = (gcnew System::Windows::Forms::Button());
this->button21 = (gcnew System::Windows::Forms::Button());
this->button22 = (gcnew System::Windows::Forms::Button());
this->button24 = (gcnew System::Windows::Forms::Button());
this->button23 = (gcnew System::Windows::Forms::Button());
this->button25 = (gcnew System::Windows::Forms::Button());
this->button26 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button27 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(31, 184);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(32, 32);
this->button1->TabIndex = 0;
this->button1->Text = L"M+";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(31, 148);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(32, 32);
this->button2->TabIndex = 2;
this->button2->Text = L"MS";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(31, 74);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(32, 32);
this->button3->TabIndex = 4;
this->button3->Text = L"MC";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// button4
//
this->button4->Location = System::Drawing::Point(31, 110);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(32, 32);
this->button4->TabIndex = 3;
this->button4->Text = L"MR";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(69, 74);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(32, 32);
this->button5->TabIndex = 8;
this->button5->Text = L"7";
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button6
//
this->button6->Location = System::Drawing::Point(69, 110);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(32, 32);
this->button6->TabIndex = 7;
this->button6->Text = L"4";
this->button6->UseVisualStyleBackColor = true;
this->button6->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button7
//
this->button7->Location = System::Drawing::Point(69, 148);
this->button7->Name = L"button7";
this->button7->Size = System::Drawing::Size(32, 32);
this->button7->TabIndex = 6;
this->button7->Text = L"1";
this->button7->UseVisualStyleBackColor = true;
this->button7->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button8
//
this->button8->Location = System::Drawing::Point(69, 184);
this->button8->Name = L"button8";
this->button8->Size = System::Drawing::Size(32, 32);
this->button8->TabIndex = 5;
this->button8->Text = L"0";
this->button8->UseVisualStyleBackColor = true;
this->button8->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button9
//
this->button9->Location = System::Drawing::Point(107, 74);
this->button9->Name = L"button9";
this->button9->Size = System::Drawing::Size(32, 32);
this->button9->TabIndex = 12;
this->button9->Text = L"8";
this->button9->UseVisualStyleBackColor = true;
this->button9->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button10
//
this->button10->Location = System::Drawing::Point(107, 110);
this->button10->Name = L"button10";
this->button10->Size = System::Drawing::Size(32, 32);
this->button10->TabIndex = 11;
this->button10->Text = L"5";
this->button10->UseVisualStyleBackColor = true;
this->button10->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button11
//
this->button11->Location = System::Drawing::Point(107, 148);
this->button11->Name = L"button11";
this->button11->Size = System::Drawing::Size(32, 32);
this->button11->TabIndex = 10;
this->button11->Text = L"2";
this->button11->UseVisualStyleBackColor = true;
this->button11->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button12
//
this->button12->Location = System::Drawing::Point(107, 184);
this->button12->Name = L"button12";
this->button12->Size = System::Drawing::Size(32, 32);
this->button12->TabIndex = 9;
this->button12->Text = L"+/-";
this->button12->UseVisualStyleBackColor = true;
this->button12->Click += gcnew System::EventHandler(this, &Form1::button12_Click);
//
// button13
//
this->button13->Location = System::Drawing::Point(145, 74);
this->button13->Name = L"button13";
this->button13->Size = System::Drawing::Size(32, 32);
this->button13->TabIndex = 16;
this->button13->Text = L"9";
this->button13->UseVisualStyleBackColor = true;
this->button13->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button14
//
this->button14->Location = System::Drawing::Point(145, 110);
this->button14->Name = L"button14";
this->button14->Size = System::Drawing::Size(32, 32);
this->button14->TabIndex = 15;
this->button14->Text = L"6";
this->button14->UseVisualStyleBackColor = true;
this->button14->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button15
//
this->button15->Location = System::Drawing::Point(145, 148);
this->button15->Name = L"button15";
this->button15->Size = System::Drawing::Size(32, 32);
this->button15->TabIndex = 14;
this->button15->Text = L"3";
this->button15->UseVisualStyleBackColor = true;
this->button15->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button16
//
this->button16->Location = System::Drawing::Point(145, 184);
this->button16->Name = L"button16";
this->button16->Size = System::Drawing::Size(32, 32);
this->button16->TabIndex = 13;
this->button16->Text = L"\\";
this->button16->UseVisualStyleBackColor = true;
this->button16->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button17
//
this->button17->Location = System::Drawing::Point(183, 74);
this->button17->Name = L"button17";
this->button17->Size = System::Drawing::Size(32, 32);
this->button17->TabIndex = 20;
this->button17->Text = L"/";
this->button17->UseVisualStyleBackColor = true;
this->button17->Click += gcnew System::EventHandler(this, &Form1::button17_Click);
//
// button18
//
this->button18->Location = System::Drawing::Point(183, 110);
this->button18->Name = L"button18";
this->button18->Size = System::Drawing::Size(32, 32);
this->button18->TabIndex = 19;
this->button18->Text = L"*";
this->button18->UseVisualStyleBackColor = true;
this->button18->Click += gcnew System::EventHandler(this, &Form1::button18_Click);
//
// button19
//
this->button19->Location = System::Drawing::Point(183, 148);
this->button19->Name = L"button19";
this->button19->Size = System::Drawing::Size(32, 32);
this->button19->TabIndex = 18;
this->button19->Text = L".";
this->button19->UseVisualStyleBackColor = true;
this->button19->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button20
//
this->button20->Location = System::Drawing::Point(183, 184);
this->button20->Name = L"button20";
this->button20->Size = System::Drawing::Size(32, 32);
this->button20->TabIndex = 17;
this->button20->Text = L"+";
this->button20->UseVisualStyleBackColor = true;
this->button20->Click += gcnew System::EventHandler(this, &Form1::button20_Click);
//
// button21
//
this->button21->Location = System::Drawing::Point(221, 110);
this->button21->Name = L"button21";
this->button21->Size = System::Drawing::Size(32, 32);
this->button21->TabIndex = 24;
this->button21->Text = L"Sqr";
this->button21->UseVisualStyleBackColor = true;
this->button21->Click += gcnew System::EventHandler(this, &Form1::button21_Click);
//
// button22
//
this->button22->Location = System::Drawing::Point(221, 148);
this->button22->Name = L"button22";
this->button22->Size = System::Drawing::Size(32, 32);
this->button22->TabIndex = 23;
this->button22->Text = L"1/x";
this->button22->UseVisualStyleBackColor = true;
this->button22->Click += gcnew System::EventHandler(this, &Form1::button22_Click);
//
// button24
//
this->button24->Location = System::Drawing::Point(221, 184);
this->button24->Name = L"button24";
this->button24->Size = System::Drawing::Size(32, 32);
this->button24->TabIndex = 21;
this->button24->Text = L"=";
this->button24->UseVisualStyleBackColor = true;
this->button24->Click += gcnew System::EventHandler(this, &Form1::button24_Click);
//
// button23
//
this->button23->Location = System::Drawing::Point(82, 38);
this->button23->Name = L"button23";
this->button23->Size = System::Drawing::Size(48, 30);
this->button23->TabIndex = 25;
this->button23->Text = L"BS";
this->button23->UseVisualStyleBackColor = true;
this->button23->Click += gcnew System::EventHandler(this, &Form1::button23_Click);
//
// button25
//
this->button25->Location = System::Drawing::Point(136, 38);
this->button25->Name = L"button25";
this->button25->Size = System::Drawing::Size(48, 30);
this->button25->TabIndex = 26;
this->button25->Text = L"CE";
this->button25->UseVisualStyleBackColor = true;
this->button25->Click += gcnew System::EventHandler(this, &Form1::button25_Click);
//
// button26
//
this->button26->Location = System::Drawing::Point(190, 38);
this->button26->Name = L"button26";
this->button26->Size = System::Drawing::Size(48, 30);
this->button26->TabIndex = 27;
this->button26->Text = L"C";
this->button26->UseVisualStyleBackColor = true;
this->button26->Click += gcnew System::EventHandler(this, &Form1::button26_Click);
//
// textBox1
//
this->textBox1->Enabled = false;
this->textBox1->Location = System::Drawing::Point(0, 12);
this->textBox1->Name = L"textBox1";
this->textBox1->ReadOnly = true;
this->textBox1->Size = System::Drawing::Size(284, 20);
this->textBox1->TabIndex = 0;
this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// button27
//
this->button27->Location = System::Drawing::Point(221, 74);
this->button27->Name = L"button27";
this->button27->Size = System::Drawing::Size(32, 32);
this->button27->TabIndex = 28;
this->button27->Text = L"-";
this->button27->UseVisualStyleBackColor = true;
this->button27->Click += gcnew System::EventHandler(this, &Form1::button27_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 238);
this->Controls->Add(this->button27);
this->Controls->Add(this->button26);
this->Controls->Add(this->button25);
this->Controls->Add(this->button23);
this->Controls->Add(this->button21);
this->Controls->Add(this->button22);
this->Controls->Add(this->button24);
this->Controls->Add(this->button17);
this->Controls->Add(this->button18);
this->Controls->Add(this->button19);
this->Controls->Add(this->button20);
this->Controls->Add(this->button13);
this->Controls->Add(this->button14);
this->Controls->Add(this->button15);
this->Controls->Add(this->button16);
this->Controls->Add(this->button9);
this->Controls->Add(this->button10);
this->Controls->Add(this->button11);
this->Controls->Add(this->button12);
this->Controls->Add(this->button5);
this->Controls->Add(this->button6);
this->Controls->Add(this->button7);
this->Controls->Add(this->button8);
this->Controls->Add(this->button3);
this->Controls->Add(this->button4);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->KeyPreview = true;
this->Name = L"Form1";
this->Text = L"Калькулятор дробей";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::Form1_KeyPress);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
#pragma region My
/// <summary>
/// Контроллер операций.
/// </summary>
Controller<TFrac>^ controller;
ArithmeticOperation<TFrac>^ arithmeticOperation;
FunctionOperation<TFrac>^ functionOperation;
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->controller->PrepareMemoryFunction();
this->controller->Stored += gcnew TFrac(Controller<TFrac>::SysToStd(this->textBox1->Text));
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox1->Text = Controller<TFrac>::StdToSys(this->controller->Stored->getStrFrac());
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this->controller->Stored = gcnew TFrac(Controller<TFrac>::SysToStd(this->textBox1->Text));
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
this->controller->Stored = gcnew TFrac();
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
Button ^button = (Button^)sender;
ButtonNumbersClicked(button->Text);
}
private: System::Void button26_Click(System::Object^ sender, System::EventArgs^ e) {
Reset();
}
private: System::Void button20_Click(System::Object^ sender, System::EventArgs^ e) {
SetOperation(Add);
}
private: System::Void button18_Click(System::Object^ sender, System::EventArgs^ e) {
SetOperation(Mul);
}
private: System::Void button17_Click(System::Object^ sender, System::EventArgs^ e) {
SetOperation(Dvd);
}
private: System::Void button24_Click(System::Object^ sender, System::EventArgs^ e) {
ResultClicked();
}
private: System::Void button22_Click(System::Object^ sender, System::EventArgs^ e) {
SetFunction(Rev);
}
private: System::Void button21_Click(System::Object^ sender, System::EventArgs^ e) {
SetFunction(Sqr);
}
private: System::Void button12_Click(System::Object^ sender, System::EventArgs^ e) {
if (!this->textBox1->Text->Length)
return;
if (this->textBox1->Text->StartsWith("-"))
this->textBox1->Text = this->textBox1->Text->Substring(1);
else
this->textBox1->Text = "-" + this->textBox1->Text;
}
private: System::Void Form1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
if (Char::IsNumber(e->KeyChar) || e->KeyChar == '.' || e->KeyChar == '\\') {
System::String^ s = "";
s += wchar_t(e->KeyChar);
ButtonNumbersClicked(s);
}
switch(e->KeyChar) {
case '+':
SetOperation(Add);
break;
case '*':
SetOperation(Mul);
break;
case '/':
SetOperation(Dvd);
break;
case '-':
SetOperation(Sub);
break;
case '=':
ResultClicked();
break;
case Keys::Back:
BackSpace();
break;
}
e->Handled = true;
}
#pragma region Operations
private:
