- •Курсовая работа
- •На тему: Проектирование и реализация программ в технологии «абстрактных типов данных»
- •Задание
- •Общие требования
- •Тип числа – «Калькулятор простых дробей». Требования.
- •Необходимо предусмотреть следующие варианты использования (прецеденты) калькулятора:
- •Спецификация типа данных «простые дроби».
- •Спецификация типа данных «память».
- •Операции
- •Спецификация типа данных «Процессор».
- •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) {
- •Поле ввода
- •Управление вычислением
- •Дополнительные возможности
Void SetOperation(tOprtn toprtn) {
this->controller->PrepareOperation(gcnew TFrac(Controller<TFrac>::SysToStd(this->textBox1->Text)), toprtn);
this->controller->CurOperation = this->arithmeticOperation;
this->controller->OnPrepare = true;
this->controller->OnOperationClicked = true;
this->textBox1->Text = Controller<TFrac>::StdToSys(this->controller->Result->getStrFrac());
}
Void SetFunction(tFunc tfunc) {
this->controller->PrepareFunction(gcnew TFrac(Controller<TFrac>::SysToStd(this->textBox1->Text)), tfunc);
this->controller->CurOperation = this->functionOperation;
this->controller->Run();
this->controller->PostAction();
this->textBox1->Text = Controller<TFrac>::StdToSys(this->controller->Operand->getStrFrac());
}
void ButtonNumbersClicked(String^ text) {
if (this->controller->OnPrepare) {
this->textBox1->Text = "";
this->controller->OnPrepare = false;
}
if (this->textBox1->Text->StartsWith("0")) {
this->textBox1->Text = "0\\0";
return;
}
int pos = this->textBox1->Text->IndexOf("\\");
if (pos > -1) {
String ^ str = this->textBox1->Text->Substring(pos + 1);
String ^ str1 = this->textBox1->Text->Substring(0, pos);
if (str->StartsWith("0")) {
this->textBox1->Text = str1 + "\\";
return;
}
}
this->textBox1->Text = this->textBox1->Text + text;
}
void ResultClicked() {
if (this->controller->OnOperationClicked) {
this->controller->Operand = gcnew TFrac(Controller<TFrac>::SysToStd(this->textBox1->Text));
this->controller->OnOperationClicked = false;
}
this->controller->Run();
this->textBox1->Text = Controller<TFrac>::StdToSys(this->controller->Result->getStrFrac());
}
void BackSpace() {
if (!this->textBox1->Text->Length)
return;
this->textBox1->Text = this->textBox1->Text->Substring(0, this->textBox1->Text->Length - 1);
}
void CE() {
this->textBox1->Text = "0\\0";
this->controller->OnPrepare = true;
}
void Reset() {
this->controller->ResetController();
this->textBox1->Text = Controller<TFrac>::StdToSys(this->controller->Result->getStrFrac());
}
#pragma endregion
private: System::Void button23_Click(System::Object^ sender, System::EventArgs^ e) {
BackSpace();
}
private: System::Void button25_Click(System::Object^ sender, System::EventArgs^ e) {
CE();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
this->controller = gcnew Controller<TFrac>();
this->arithmeticOperation = gcnew ArithmeticOperation<TFrac>();
this->functionOperation = gcnew FunctionOperation<TFrac>();
this->textBox1->Text = Controller<TFrac>::StdToSys(this->controller->Result->getStrFrac());
this->controller->OnPrepare = true;
}
private: System::Void button27_Click(System::Object^ sender, System::EventArgs^ e) {
SetOperation(Sub);
}
};
}
Operation.cpp
#pragma once
#include "stdafx.h"
#include "TProc.cpp"
#include "TMemory.cpp"
#include "TFrac.cpp"
template <class T>
