Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a two class application that has a one-dimensional array as a data member.

ID: 3695121 • Letter: W

Question

Write a two class application that has a one-dimensional array as a data member. The array stores temperatures for any given week. Provide constructors for instantiating the class and methods to return the highest temperature, lowest temperature, average temperature, and the average temperature excluding the lowest temperature. Provide a method that accepts as an argument a temperature and returns the number of days the temperatures were below that value. Override the ToString( ) method to return the temperature range for the given week. Write a second class to test your class. This is needed for C#

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace temperatue_2classes_cs
{
class first
{
double[] t = new double[7];
public first(double[] t1)
{
for (int i = 0; i < 7; i++)
{
t[i] = t1[i];
}
}

public double hightemp()
{
double max = t[0];

for (int i = 0; i < 7; i++)
{
if (t[i] > max)
{
max = t[i];
}

}
return max;

}

public double lowtemp()
{
double min = t[0];

for (int i = 0; i < 7; i++)
{
if (t[i] < min)
{
min = t[i];
}

}
return min;

}

public double avgtemp()
{
double av, s = 0;

for (int i = 0; i < 7; i++)
{
s = s + t[i];

}
av = s / 7;
return av;

}
public int daysbelow(double a)
{
int c = 0;
for (int i = 0; i < 7; i++)
{
if (t[i] < a)
{
c++;
}

}
return c;
}
public double ToString(double max, double min)
{
return max - min;
}
}

class Program
{
static void Main(string[] args)
{
double[] t1=new double[7];
for(int i =0;i<7;i++)
{
Console.WriteLine ("Enter Tempreture for "+(i+1)+" day");
t1[i]=Convert.ToDouble ( Console.ReadLine ());
}


  

first o = new first(t1);
double h=o.hightemp ();
Console.WriteLine ("Highest Tempreture ="+h);
double l=o.lowtemp ();
Console.WriteLine ("Lowest Tempreture ="+l);

double av=o.avgtemp ();
Console.WriteLine ("Average Tempreture ="+av);


int c= o.daysbelow (10);
Console.WriteLine ("Number of days below 10 are "+c);

double r=o.ToString (h,l);
Console.WriteLine ("Range of Tempreture ="+r);
Console.ReadKey ();
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote