public static void Main()
SelectMode(CollectNumbers());
public static Collector CollectNumbers()
Console.WriteLine("Enter the length of the numbers:");
return new Collector(int.Parse(Console.ReadLine()));
public static void SelectMode(Collector collector)
Console.WriteLine("Select Mode of The Program:");
Console.WriteLine("1. Print some of statistical values.");
Console.WriteLine("2. Determine whether a value is outlier or not.");
int chosen = int.Parse(Console.ReadLine());
StatisticalMode(collector);
OutlierCheckerMode(collector);
public static void OutlierCheckerMode(Collector collector)
Console.WriteLine("Enter the value:");
(new OutlierChecker(collector)).Is(double.Parse(Console.ReadLine())).PrintResults();
public static void StatisticalMode(Collector collector)
(new StatisticsOperations(collector)).PrintStatisticalValues();
public static void NotFoundMode(Collector collector)
Console.WriteLine("You have selected a wrong mode.");
private double[] numbers;
public Collector(int counter)
this.numbers = new double[counter];
for (int i = 0; i < counter; i++) {
Console.WriteLine("Enter the {0} number:", i + 1);
this.numbers[i] = double.Parse(Console.ReadLine());
Array.Sort(this.numbers);
public double[] GetNumbers()
public double GetNumber(int index)
return this.numbers[index];
return this.numbers.Length;
foreach (var item in this.GetNumbers()) {
return this.Sum() / this.GetLength();
public double GreatestNumber()
double greatest = this.GetNumber(0);
foreach (var item in this.GetNumbers()) {
public double SmallestNumber()
double smallest = this.GetNumber(0);
foreach (var item in this.GetNumbers()) {
public double Percentile(int p)
return this.GreatestNumber();
double rank = (p * (this.GetLength() + 1)) / 100.0d;
double lower = this.GetNumber((int) Math.Floor(rank) - 1);
double upper = this.GetNumber((int) Math.Floor(rank));
return lower + (upper - lower) * (rank - Math.Floor(rank));
public class OutlierChecker
private Collector collector;
protected bool results = false;
public OutlierChecker(Collector collector)
this.collector = collector;
public OutlierChecker Is(double number)
double q1 = this.collector.Percentile(25);
double q2 = this.collector.Percentile(50);
double q3 = this.collector.Percentile(75);
double max = q1 - (1.5 * iqr);
double min = q3 + (1.5 * iqr);
foreach (var item in this.collector.GetNumbers()) {
if ((item < max || item > max) && outlier < item) {
public void PrintResults()
Console.WriteLine("Your entered number is an outlier.");
Console.WriteLine("Your entered number isn't an outlier");
public class StatisticsOperations
private Collector collector;
public StatisticsOperations(Collector collector)
this.collector = collector;
return this.collector.GetNumber(this.collector.GetLength() / 2);
double number = this.collector.GetNumber(0);
foreach (var item in this.collector.GetNumbers()) {
return this.collector.GreatestNumber() - this.collector.SmallestNumber();
public double StandardDivision()
foreach (var item in this.collector.GetNumbers()) {
result += Math.Pow(item - this.collector.Average(), 2);
return Math.Sqrt(result / this.collector.GetLength());
public double SummationOfDivisions()
foreach (var item in this.collector.GetNumbers()) {
result += Math.Pow(item - this.collector.Average(), 2);
public void PrintStatisticalValues()
Console.WriteLine("Median = {0}", this.Median());
Console.WriteLine("Mode = {0}", this.Mode());
Console.WriteLine("Range = {0}", this.Range());
Console.WriteLine("Standard Division = {0}", this.StandardDivision());
Console.WriteLine("Summation of Divisions = {0}", this.SummationOfDivisions());
Console.WriteLine("Quartile 1 = {0}", this.collector.Percentile(25));
Console.WriteLine("Quartile 2 = {0}", this.collector.Percentile(50));
Console.WriteLine("Quartile 3 = {0}", this.collector.Percentile(75));
Console.WriteLine("Percentile 20 = {0}", this.collector.Percentile(20));