Описать класс Vector как вектор из пяти пар двузначных целых чисел - C#
Формулировка задачи:
Описать класс Vector как вектор из 5 пар двузначных целых чисел. Определить оператор > и оператор += для комбинаций векторов(где сравнивается сумма каждой пары чисел) Определить конструктор с параметрами инициализации вектор и деструктор
Создать из класса Vector два производных класса, для одного определить функцию STR, вовзращающую суммы пар чисел, входящих в вектор, для другого - Count, возвращающую среднее арифметическое всех элементов, входящих в вектор. Создайте обьекты этих классов и вызовите с ними STR и Count.
Помогите пожалуйста. Если часть задания с производными классами я более менее понимаю как сделать то первую часть я понимаю слабо.
Хотя бы с 1 частью помогите, про то как определить операторы для комбинаций векторов я даже не подозреваю сейчас.
Заранее благодарен.
Решение задачи: «Описать класс Vector как вектор из пяти пар двузначных целых чисел»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication16
{
// public int[,] matr;
// public int m = 5;
// public int n = 2;
// public Vec5(int m, int n)
// {
// this.m = m;
// this.n = n;
// matr = new int[m, n];
// Random Rand = new Random();
// for (int i = 0; i < this.m; i++)
// {
// for (int j = 0; j < this.n; j++)
// {
// this.matr[i, j] = Rand.Next(10, 99);
// }
// }
// }
// public static bool operator > (Vec5 v1, Vec5 v2)
// {
// bool result = false;
// for (int i = 0; i < 5; i++)
// for (int j = 0; j < 2; j++)
// {
// if (v1[i, j] > v2[i,j])
// {
// result = true;
// }
// else
// {
// result = false;
// break;
// }
// }
// return result;
// }
// public static bool operator < (Vec5 v1, Vec5 v2)
// {
// bool result = false;
// for (int i = 0; i < 5; i++)
// for (int j = 0; j < 2; j++)
// {
// if (v1[i, j] < v2[i, j])
// {
// result = true;
// }
// else
// {
// result = false;
// break;
// }
// }
// return result;
// }
// public static Vec5 operator +(Vec5 v1, Vec5 v2)
// {
// for (int i = 0; i < 5; ++i)
// {
// for (int j = 0; j < 2; ++j)
// {
// v1.matr[i, j] = v1.matr[i, j] + v2.matr[i, j];
// }
// }
// return v1;
// }
// ~Vec5()
// {
// }
//}
//class Vec5_1 : Vec5
//{
// public int[] STRmatr;
// public int STR(Vec5 v1)
// {
// STRmatr = new int[m];
// int j = 0;
// for (int i = 0; i < m; i++)
// {
// STRmatr[i] = v1[i, j] + v1[i, j + 1];
// return STRmatr[1];
// }
// }
//}
//class Vec5_2 : Vec5
//{
// public int count(Vec5 v1)
// {
// int SrArf = 0;
// int Summ = 0;
// for (int i = 0; i < m; i++)
// {
// for (int j = 0; j < n; j++)
// {
// Summ += v1[i, j];
// }
// }
// SrArf = Summ / (n * m);
// return SrArf;
// }
//}
//class Program
//{
// static void Main(string[] args)
// {
// }
//}
//<br>
class Vec5
{
public int[,] A = new int[5,2];
public int this[int i, int j]
{
get {
return A[i,j];
}
set
{
if ((i < 5) &&(j<2))
A[i,j] = value;
}
}
public static bool operator >(Vec5 V1, Vec5 V2)
{
bool result = false;
for (int i = 0; i < 5; i++)
{
for(int j=0;j<2;j++)
{
if (V1[i,j] + V1[i,j+1] > V2[i,j] + V2[i,j+1])
{
result = true;
break;
}
else
result = false;
}
}
return result;
}
public static bool operator <(Vec5 V1, Vec5 V2)
{
bool result = false;
for (int i = 0; i < 5; i++)
{
for(int j=0;j<2;j++)
{
if (V1[i,j] + V1[i,j+1] < V2[i,j] + V2[i,j+1])
{
result = true;
break;
}
else
result = false;
}
}
return result;
}
public static Vec5 operator +(Vec5 V1, Vec5 V2)
{
int j=0;
for (j = 0; j < 2; j++)
{
for (int i = 0; i < 5; i++)
{
V1[1, j] = V1[i, j] + V2[i, j];
}
}
return V1;
}
~Vec5()
{
}
}
class Vec5_1 : Vec5
{
public int[] STRmatr;
public int STR(Vec5 v1)
{
STRmatr = new int[5];
for (int j = 0; j < 2; j++)
{
for (int i = 0; i < 5; i++)
{
STRmatr[i] = v1[i, j] + v1[i, j + 1];
return STRmatr[1];
}
}
}
}
class Vec5_2 : Vec5
{
public int count(Vec5 v1)
{
int SrArf = 0;
int Summ = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 2; j++)
{
Summ += v1[i, j];
}
}
SrArf = Summ /10;
return SrArf;
}
}
//class Vec6_1 : Vec5
//{
// int summ = 0;
// public int STR()
// {
// for (int i = 0; i < 5; i++)
// if (A[i, j] != 0)
// {
// summ += A[i, j] / A[i, j];
// }
// return summ / 6;
// }
//}
//class Vec6_2 : Vec5
//{
// public int Mult()
// {
// int Mult = 0;
// for (int i = 0; i < 6; i++)
// Mult *= A[i,j];
// return Mult;
// }
//}
class Program
{
static void Main(string[] args)
{
Vec5_1 v1 = new Vec5_1();
v1.STR();
Vec5_2 v2 = new Vec5_2();
v2.count();
}
}
}