Итоговая лабораторная работа 3

This commit is contained in:
Danila 2024-04-01 14:05:34 +04:00
parent b967200792
commit dc01587054
5 changed files with 20 additions and 35 deletions

View File

@ -1,5 +1,4 @@
using HoistingCrane.Drawning; using HoistingCrane.Drawning;
using System;
namespace HoistingCrane.CollectionGenericObjects namespace HoistingCrane.CollectionGenericObjects
{ {
public abstract class AbstractCompany public abstract class AbstractCompany
@ -42,13 +41,13 @@ namespace HoistingCrane.CollectionGenericObjects
arr.SetMaxCount = GetMaxCount; arr.SetMaxCount = GetMaxCount;
} }
public static bool operator +(AbstractCompany company, DrawningTrackedVehicle car) public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
{ {
return company.arr?.Insert(car) ?? false; return company.arr?.Insert(car) ?? 0;
} }
public static bool operator -(AbstractCompany company, int position) public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
{ {
return company.arr?.Remove(position) ?? false; return company.arr?.Remove(position);
} }
public DrawningTrackedVehicle? GetRandomObject() public DrawningTrackedVehicle? GetRandomObject()

View File

@ -1,7 +1,4 @@
using HoistingCrane.Drawning; using HoistingCrane.Drawning;
using System;
using System.Collections.Specialized;
namespace HoistingCrane.CollectionGenericObjects namespace HoistingCrane.CollectionGenericObjects
{ {
public class Garage : AbstractCompany public class Garage : AbstractCompany

View File

@ -1,5 +1,4 @@
using System; namespace HoistingCrane.CollectionGenericObjects
namespace HoistingCrane.CollectionGenericObjects
{ {
public interface ICollectionGenericObjects<T> public interface ICollectionGenericObjects<T>
where T: class where T: class
@ -17,7 +16,7 @@ namespace HoistingCrane.CollectionGenericObjects
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
/// <returns></returns> /// <returns></returns>
bool Insert(T obj); int Insert(T obj);
/// <summary> /// <summary>
/// Добавление элемента в коллекцию на определенную позицию /// Добавление элемента в коллекцию на определенную позицию
/// </summary> /// </summary>
@ -30,7 +29,7 @@ namespace HoistingCrane.CollectionGenericObjects
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
bool Remove(int position); T? Remove(int position);
T? Get(int position); T? Get(int position);
} }
} }

View File

@ -1,5 +1,4 @@
using System; namespace HoistingCrane.CollectionGenericObjects
namespace HoistingCrane.CollectionGenericObjects
{ {
public class MassivGenericObjects<T> : ICollectionGenericObjects<T> where T : class public class MassivGenericObjects<T> : ICollectionGenericObjects<T> where T : class
{ {
@ -31,16 +30,16 @@ namespace HoistingCrane.CollectionGenericObjects
return null; return null;
} }
public bool Insert(T obj) public int Insert(T obj)
{ {
for(int i = 0; i < Count; i++) for(int i = 0; i < Count; i++)
{ {
if (arr[i] == null) { if (arr[i] == null) {
arr[i] = obj; Insert(obj,i);
return true; return 1;
} }
} }
return false; return 0;
} }
public bool Insert(T obj, int position) public bool Insert(T obj, int position)
@ -81,14 +80,15 @@ namespace HoistingCrane.CollectionGenericObjects
return false; return false;
} }
public bool Remove(int position) public T? Remove(int position)
{ {
if(position < 0 || position >= arr.Length || arr[position] == null) if(position >= 0 && position < Count)
{ {
return false; arr[position] = null;
return arr[position];
} }
arr[position] = null; return arr[position];
return true;
} }
} }
} }

View File

@ -1,15 +1,5 @@
using HoistingCrane.CollectionGenericObjects; using HoistingCrane.CollectionGenericObjects;
using HoistingCrane.Drawning; using HoistingCrane.Drawning;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HoistingCrane namespace HoistingCrane
{ {
public partial class FormCarCollection : Form public partial class FormCarCollection : Form
@ -49,7 +39,7 @@ namespace HoistingCrane
default: default:
return; return;
} }
if (_company + drawning) if ((_company + drawning) == 1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
@ -91,7 +81,7 @@ namespace HoistingCrane
return; return;
} }
int pos = Convert.ToInt32(maskedTextBox.Text); int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos) if ((_company - pos) == null)
{ {
MessageBox.Show("Объект удален!"); MessageBox.Show("Объект удален!");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();