Мегаобучалка Главная | О нас | Обратная связь


Диаграмма классов проекта



2015-11-10 666 Обсуждений (0)
Диаграмма классов проекта 0.00 из 5.00 0 оценок




Проанализировав сообщения, которыми обмениваются классы в процессе выполнения прецедентов можно построить следующую диаграмму классов проекта.

Для упрощения взаимодействия между классами в процессе работы приложения добавим класс «Управление». Тогда наша диаграмма примет следующий вид:

Из диаграммы классов видно, что объект класса «Интерфейс» вызывает методы класса «Управление» и «Справка». Объект же класса «Управление» в свою очередь вызывает методы объектов классов «Редактор», «История» и «Конвертор_p1_10», «Конвертор_10_p2».

Диаграмма состояний для объекта класса «Управление» представлена ниже:

Объект класса «Управление» может находиться в двух состояниях: «Редактирование» и «Редактирование завершено».

Обмен сообщениями между объектами. Диаграмма последовательностей.

Давайте спроектируем обмен сообщениями между объектами в процессе выполнения прецедента «Преобразовать». На диаграмме последовательностей приведённой ниже приведёна последовательность сообщений между объектами в процессе реализации прецедента «Преобразовать».

На диаграмме последовательностей приведённой ниже приведёна последовательность сообщений между объектами в процессе реализации прецедента «Ввести и отредактировать».

На диаграмме последовательностей приведённой ниже приведёна последовательность сообщений между объектами в процессе реализации прецедента «История».

 

 

Код программы:

Класс Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Windows.Forms;

 

namespace STP_Converter

{

static class Program

{

/// <summary>

/// Главная точка входа для приложения.

/// </summary>

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Main());

}

}

}

Класс Main.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace STP_Converter

{

public partial class Main : Form

{

const string Zero = "0";

Manager manager;

public Main()

{

InitializeComponent();

trackBarInput_Scroll(null, null);

trackBarOutput_Scroll(null, null);

txtInput.Text = Zero;

manager = new Manager();

}

 

private void btnBS_Click(object sender, EventArgs e)

{

if (txtInput.Text.Length > 0)

{

txtInput.Text = txtInput.Text.Substring(0, txtInput.Text.Length - 1);

}

if (txtInput.Text.Length == 0)

txtInput.Text = Zero;

}

private void btnDEL_Click(object sender, EventArgs e)

{

if (txtInput.Text.Length > 0)

{

txtInput.Text = txtInput.Text.Substring(1);

}

if (txtInput.Text.Length == 0)

txtInput.Text = Zero;

}

private void btnCL_Click(object sender, EventArgs e)

{

txtInput.Text = Zero;

txtOutput.Text = Zero;

}

 

private void btnSeparator_Click(object sender, EventArgs e)

{

if (!txtInput.Text.Contains('.'))

txtInput.Text += '.';

}

 

private void trackBarInput_Scroll(object sender, EventArgs e)

{

labelInput.Text = trackBarInput.Value.ToString();

CorrectInput(trackBarInput.Value);

}

private void CorrectInput(int newBase)

{

btn2.Enabled = btn3.Enabled

= btn4.Enabled = btn5.Enabled = btn6.Enabled = btn7.Enabled

= btn8.Enabled = btn9.Enabled = btnA.Enabled = btnB.Enabled

= btnC.Enabled = btnD.Enabled = btnE.Enabled = btnF.Enabled = false;

if (newBase == 2) return;

btn2.Enabled = true;

if (newBase == 3) return;

btn3.Enabled = true;

if (newBase == 4) return;

btn4.Enabled = true;

if (newBase == 5) return;

btn5.Enabled = true;

if (newBase == 6) return;

btn6.Enabled = true;

if (newBase == 7) return;

btn7.Enabled = true;

if (newBase == 8) return;

btn8.Enabled = true;

if (newBase == 9) return;

btn9.Enabled = true;

if (newBase == 10) return;

btnA.Enabled = true;

if (newBase == 11) return;

btnB.Enabled = true;

if (newBase == 12) return;

btnC.Enabled = true;

if (newBase == 13) return;

btnD.Enabled = true;

if (newBase == 14) return;

btnE.Enabled = true;

if (newBase == 15) return;

btnF.Enabled = true;

}

private void trackBarOutput_Scroll(object sender, EventArgs e)

{

labelOutput.Text = trackBarOutput.Value.ToString();

}

private void ButtonCtrl(object sender, EventArgs e)

{

if (((Button)sender).Enabled == false)

return;

if (((Button)sender).Tag != null)

{

if (txtInput.Text.Equals(Zero, StringComparison.OrdinalIgnoreCase))

txtInput.Text = "";

txtInput.Text += ((Button)sender).Tag.ToString();

}

}

 

private void btnPlusMin_Click(object sender, EventArgs e)

{

if (txtInput.Text[0] == '-')

txtInput.Text = txtInput.Text.Substring(1);

else

txtInput.Text = "-" + txtInput.Text;

}

 

private void btnEnter_Click(object sender, EventArgs e)

{

manager.SetValue(txtInput.Text);

string result = manager.GetValue(trackBarInput.Value, trackBarOutput.Value, 30);

if (result == null)

{

MessageBox.Show("Входное число имело некоректный вид. Преобразование невозможно.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

if (result.Length > 30)

MessageBox.Show("Количество разрядов в выходном числе слишком большое. Преобразование невозможно.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);

else

txtOutput.Text = result;

}

 

private void Main_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.NumPad0 || e.KeyCode == Keys.D0)

ButtonCtrl(btn0, null);

if (e.KeyCode == Keys.NumPad1 || e.KeyCode == Keys.D1)

ButtonCtrl(btn1, null);

if (e.KeyCode == Keys.NumPad2 || e.KeyCode == Keys.D2)

ButtonCtrl(btn2, null);

if (e.KeyCode == Keys.NumPad3 || e.KeyCode == Keys.D3)

ButtonCtrl(btn3, null);

if (e.KeyCode == Keys.NumPad4 || e.KeyCode == Keys.D4)

ButtonCtrl(btn4, null);

if (e.KeyCode == Keys.NumPad5 || e.KeyCode == Keys.D5)

ButtonCtrl(btn5, null);

if (e.KeyCode == Keys.NumPad6 || e.KeyCode == Keys.D6)

ButtonCtrl(btn6, null);

if (e.KeyCode == Keys.NumPad7 || e.KeyCode == Keys.D7)

ButtonCtrl(btn7, null);

if (e.KeyCode == Keys.NumPad8 || e.KeyCode == Keys.D8)

ButtonCtrl(btn8, null);

if (e.KeyCode == Keys.NumPad9 || e.KeyCode == Keys.D9)

ButtonCtrl(btn9, null);

if (e.KeyCode == Keys.A)

ButtonCtrl(btnA, null);

if (e.KeyCode == Keys.B)

ButtonCtrl(btnB, null);

if (e.KeyCode == Keys.C)

ButtonCtrl(btnC, null);

if (e.KeyCode == Keys.D)

ButtonCtrl(btnD, null);

if (e.KeyCode == Keys.E)

ButtonCtrl(btnE, null);

if (e.KeyCode == Keys.F)

ButtonCtrl(btnF, null);

if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Enter)

btnEnter_Click(btnEnter, null);

if (e.KeyCode == Keys.Separator || e.KeyCode == Keys.Separator)

btnSeparator_Click(btnSeparator, null);

}

 

private void выходToolStripMenuItem_Click(object sender, EventArgs e)

{

Close();

}

 

private void historyToolStripMenuItem_Click(object sender, EventArgs e)

{

manager.SetValue(txtInput.Text);

string result = manager.GetValue(trackBarInput.Value, trackBarOutput.Value, 0);

if (result != null)

{

HistoryForm history = new HistoryForm(manager._History);

history.Show();

}

}

 

 

private void panelCtrl_Paint(object sender, PaintEventArgs e)

{

 

}

 

private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)

{

AboutBox1 ab1 = new AboutBox1();

ab1.Show();

}

 

 

}

}

 

Класс Manager.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace STP_Converter

{

class Manager

{

string ValueInput;

int BaseIn =10, BaseOut =16;

_Pto10 _pto10;

_10toP _10top;

public History _History { get; private set; }

public Manager()

{

_pto10 = new _Pto10();

_10top = new _10toP();

_History = new History();

}

public void SetValue(string Value)

{

this.ValueInput = Value;

}

private bool Validating()

{

for (int i = 0; i < ValueInput.Length; i++)

{

if (i == 0 && ValueInput[i] == '-')

continue;

if (_pto10.PCharToInt(ValueInput[i]) >= BaseIn)

return false;

}

return true;

}

public string GetValue(int BaseIn, int BaseOut, int Precision)

{

this.BaseIn = BaseIn;

this.BaseOut = BaseOut;

if (!Validating())

return null;

_pto10.Create(BaseIn, Precision);

_10top.Create(BaseOut, Precision);

string result = _pto10.DoTransfer(ValueInput);

result = _10top.DoTransfer(result);

_History.AddRecords(ValueInput, BaseIn, result, BaseOut);

return result;

}

 

}

}

 

Класс BaseConvert.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace STP_Converter

{

class BaseConvert

{

protected int Base { get; set; }

protected int Precision { get; set; }

protected char[] IntToChar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

public virtual bool Create(int Base, int Precision)

{

if (Base > 16 || Base < 2)

return false;

this.Base = Base;

if (Precision < 0)

return false;

this.Precision = Precision;

return true;

}

public virtual bool SetP(int P)

{

if (P > 16 || P < 2)

return false;

this.Base = P;

return true;

}

public virtual string DoTransfer(string Value)

{

return Value;

}

}

}

 

Класс 10toP.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace STP_Converter

{

class _10toP : BaseConvert

{

public override string DoTransfer(string Value)

{

int Int;

double Part;

if (Value.Contains('.'))

{

Part = double.Parse("0," + Value.Substring(Value.IndexOf('.') + 1));

Int = int.Parse(Value.Substring(0, Value.IndexOf('.')));

}

else

{

Int = int.Parse(Value);

Part = 0;

}

if (Precision == 0)

return Int10ToP(Int);

string ret = Int10ToP(Int);

if (Part != 0)

{

ret += "."+Frac10ToP(Part);

}

return ret;

}

public char IntToPChar(int Value)

{

if (Value < 0 || Value > 9)

return '#';

return Value.ToString()[0];

}

public string Int10ToP(int Value)

{

string sign = Value < 0 ? "-" : "";

string result = "";

Value = Value < 0 ? Value * -1 : Value;

while (Value != 0)

{

result += IntToChar[Value % Base].ToString();

Value = Value / Base;

}

result.ToCharArray().ToList().Reverse();

string ret = sign;

for (int i = result.Length-1; i >= 0; i--)

{

ret += result[i];

}

return ret;

}

public string Frac10ToP(double Frac)

{

string result = "";

for (int i = 0; i < Precision && Frac != 0; i++)

{

result += IntToChar[(int)(Frac * Base)].ToString();

Frac = Frac * Base - (int)(Frac * Base);

}

return result;

}

}

}

 

Класс Pto10.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace STP_Converter

{

class _Pto10 : BaseConvert

{

public override string DoTransfer(string Value)

{

string Int;

string Part;

if (Value.Contains('.'))

{

Part = Value.Substring(Value.IndexOf('.') + 1);

Int = Value.Substring(0, Value.IndexOf('.'));

}

else

{

Int = Value;

Part = "0";

}

double result = PIntTo10(Int)+PFracTo10(Part);

return result.ToString().Replace(',','.');

}

public int PCharToInt(char Number)

{

for (int i = 0; i < IntToChar.Length; i++)

if (IntToChar[i] == Number)

return i;

return -1;

}

public int PIntTo10(string Value)

{

int Sign=1;

if (Value[0] == '-')

{

Sign = -1;

Value = Value.Substring(1);

}

int result = 0;

for (int i = 0; i < Value.Length; i++)

{

result += (int)Math.Pow(Convert.ToDouble(Base), Convert.ToDouble(Value.Length - 1 - i))*PCharToInt(Value[i]);

}

return result * Sign;

}

public double PFracTo10(string Value)

{

double result = 0;

for (int i = 0; i < Precision && i < Value.Length; i++)

{

result += Math.Pow(Convert.ToDouble(Base), Convert.ToDouble((i + 1) * -1)) * PCharToInt(Value[i]); // перевод

}

return result;

}

}

}

 

Класс History.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace STP_Converter

{

public class History

{

public List<string> Records { get; private set; }

public void AddRecords(string ValueInput, int BaseInput, string ValueOutput, int BaseOutput)

{

if (Records == null)

Records = new List<string>();

Records.Add(ValueInput + " (" + BaseInput.ToString() + ") --> " + ValueOutput + " (" + BaseOutput + ")");

}

public void Clear()

{

Records.Clear();

}

}

}

 

Класс AboutBox1.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Linq;

using System.Reflection;

using System.Windows.Forms;

 

namespace STP_Converter

{

partial class AboutBox1 : Form

{

public AboutBox1()

{

InitializeComponent();

this.Text = "Конвертер для чисел";//String.Format("О {0}", AssemblyTitle);

this.labelProductName.Text = "Конвертер";//AssemblyProduct;

this.labelVersion.Text = String.Format("Версия 2.0.1", AssemblyVersion);

// this.labelCopyright.Text = "Фёдоров А.В., Новиков А.Н., Саренков Н.А., \nДубинин К.С. норм пацаны группа ЗП-11";

this.labelCompanyName.Text = "СибГУТИ";

this.textBoxDescription.Text = Саренков Н.А. группа ЗП-11 Программа преобразует число из одной системы счисления в другую. Системы счисления выбираются из диапозона (2-16).";// AssemblyDescription;

}

 

#region Методы доступа к атрибутам сборки

 

public string AssemblyTitle

{

get

{

object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);

if (attributes.Length > 0)

{

AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];

if (titleAttribute.Title != "")

{

return titleAttribute.Title;

}

}

return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);

}

}

 

public string AssemblyVersion

{

get

{

return Assembly.GetExecutingAssembly().GetName().Version.ToString();

}

}

 

public string AssemblyDescription

{

get

{

object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);

if (attributes.Length == 0)

{

return "";

}

return ((AssemblyDescriptionAttribute)attributes[0]).Description;

}

}

 

public string AssemblyProduct

{

get

{

object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);

if (attributes.Length == 0)

{

return "";

}

return ((AssemblyProductAttribute)attributes[0]).Product;

}

}

 

public string AssemblyCopyright

{

get

{

object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

if (attributes.Length == 0)

{

return "";

}

return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;

}

}

 

public string AssemblyCompany

{

get

{

object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);

if (attributes.Length == 0)

{

return "";

}

return ((AssemblyCompanyAttribute)attributes[0]).Company;

}

}

#endregion

 

private void okButton_Click(object sender, EventArgs e)

{

Close();

}

 

private void tableLayoutPanel_Paint(object sender, PaintEventArgs e)

{

 

}

 

private void labelCopyright_Click(object sender, EventArgs e)

{

 

}

}

}

 



2015-11-10 666 Обсуждений (0)
Диаграмма классов проекта 0.00 из 5.00 0 оценок









Обсуждение в статье: Диаграмма классов проекта

Обсуждений еще не было, будьте первым... ↓↓↓

Отправить сообщение

Популярное:
Личность ребенка как объект и субъект в образовательной технологии: В настоящее время в России идет становление новой системы образования, ориентированного на вхождение...
Как выбрать специалиста по управлению гостиницей: Понятно, что управление гостиницей невозможно без специальных знаний. Соответственно, важна квалификация...
Генезис конфликтологии как науки в древней Греции: Для уяснения предыстории конфликтологии существенное значение имеет обращение к античной...



©2015-2024 megaobuchalka.ru Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. (666)

Почему 1285321 студент выбрали МегаОбучалку...

Система поиска информации

Мобильная версия сайта

Удобная навигация

Нет шокирующей рекламы



(0.006 сек.)