0% found this document useful (0 votes)
22 views3 pages

Note: Actual Namespace Depends On The Project Name.: Program Doubleintabstract Doubleintabstract

The document defines classes for representing pairs of integers and lists of pairs. It includes methods for generating random pairs, sorting them, and analyzing patterns in their values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Note: Actual Namespace Depends On The Project Name.: Program Doubleintabstract Doubleintabstract

The document defines classes for representing pairs of integers and lists of pairs. It includes methods for generating random pairs, sorting them, and analyzing patterns in their values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;

namespace MyApp // Note: actual namespace depends on the project name.


{
internal class Program
{
public abstract class DoubleIntAbstract
{
protected int i1, i2;
public DoubleIntAbstract(int i1, int i2)
{
this.i1 = i1;
this.i2 = i2;
}
abstract protected double Combine();
public int Compare(DoubleIntAbstract diOther)
{
if (this.Combine() > diOther.Combine())
return 1; // Bigger
else if (this.Combine() < diOther.Combine())
return -1; // Smaller
else
return 0; // The same
}
public void PrintRaw()
{
Console.Write(i1.ToString() + "-" + i2.ToString() + "␣␣");
}
public void PrintCombine()
{
Console.Write(Combine().ToString("N2") + "␣");
}
}

public class DoubleInt : DoubleIntAbstract


{
public DoubleInt(int i1, int i2) : base(i1, i2)
{

}
// Extra functions to be implemented here
protected override double Combine()
{
return Math.Sqrt(this.i1*this.i1 + this.i2*this.i2);
}

public class NumberSeries


{
public List<DoubleInt> lstData = new List<DoubleInt>();
// Extra functions to be implemented here

public int SuccessiveDecrease()


{
int count = 0;
for (int i = 0; i < lstData.Count-2; i++)
{
if (this.lstData[i].Compare(this.lstData[i + 1]) +
this.lstData[i + 1].Compare(this.lstData[i + 2]) == 2) {
count += 1;
}
}
return count;
}

public int LongestUnchange()


{
List<int> comparisonList = new List<int>(this.lstData.Count - 1);
for (int i = 0; i < lstData.Count - 1; i++)
{
comparisonList.Add(this.lstData[i].Compare(this.lstData[i +
1]));
}
int currentCount = 0, maxCount = 0;
for (int i = 0; i < comparisonList.Count; i++)
{
if (comparisonList[i] == 0)
{
currentCount += 1;
if (currentCount > maxCount)
maxCount = currentCount;
}
else
{
currentCount = 0;
}

}
return maxCount+1; // This is necessary as the value before the
zeros will be the same as the values denoted by zeros
}

public NumberSeries(int n, int min, int max)


{
lstData = new List<DoubleInt>(n);
Random rand = new Random();
for (int i = 0; i < n; i++)
{
DoubleInt x = new DoubleInt(rand.Next(min, max+1),
rand.Next(min, max+1));
this.lstData.Add(x);
}
}

static void Main(string[] args)


{
NumberSeries ns = new NumberSeries(15, 2, 6);
Console.WriteLine("15␣random␣DoubleInt␣with␣min=2␣and␣max=6:");
foreach (DoubleInt di in ns.lstData)
di.PrintRaw();
Console.WriteLine();
foreach (DoubleInt di in ns.lstData)
di.PrintCombine();
Console.WriteLine();
Console.WriteLine("SuccessiveDecrease():␣" +
ns.SuccessiveDecrease());
Console.WriteLine("LongestUnchange():␣" + ns.LongestUnchange());
}

}
}

You might also like