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

C++ problem,please explain your code, Thank you! The following code defines a cl

ID: 3576813 • Letter: C

Question

C++ problem,please explain your code, Thank you!

The following code defines a class called WeatherForecaster and a struct called ForecastDay. Write the method to find the minimum low temperature stored in the ForecastDay array. The method should print the temperature in the minimumLowTemp method.

struct ForecastDay{

std::string day;

  int highTemp;

  int lowTemp;

};

class WeatherForecaster

{

  public:

WeatherForecaster( );

~WeatherForecaster( );

  void addDayToData(ForecastDay);

  void printDaysInData( ); //prints the unique dates in the data

void minimumLowTemp( );

  private:

  int arrayLength;

  int index;

ForecastDay yearData[100]; //data for each day

};

WeatherForecaster::WeatherForecaster()

{

//ctor

arrayLength = 100;

index = 0;

}

void WeatherForecaster::addDayToData(ForecastDay fd){

yearData[index] = fd;

index++;

}

//Your code goes here.

Explanation / Answer

struct ForecastDay{

    std::string day;

    int highTemp;

    int lowTemp;

};

class WeatherForecaster

{

    public:

        WeatherForecaster( );

        ~WeatherForecaster( );

        void addDayToData(ForecastDay);

        void printDaysInData( ); //prints the unique dates in the data

        void minimumLowTemp( );

    private:

        int arrayLength;

        int index;

        ForecastDay yearData[100]; //data for each day

};

WeatherForecaster::WeatherForecaster()

{

    //ctor

    arrayLength = 100;

    index = 0;
}

void WeatherForecaster::addDayToData(ForecastDay fd){

    yearData[index] = fd;

    index++;

}


void WeatherForecaster::minimumLowTemp( ){
int i,minTemp;
//initialising the varialble minTemp with the first element of array yearData[],here yearData is the array of the structure and yearData[1].lowTemp refers to the lowTemp variable or first element of that array
minTemp=yearData[1].lowTemp;
//loop to find the minimum temperature
for(i=0;i<arrayLength;i++)
{
if(yearData[i].lowTemp<minTemp)
minTemp=yearData[i].lowTemp; //if the temperature in the array is less than minTemp then assign it to the variable minTemp
}
cout<<"The minimum temperature is "<<minTemp; //printing the minimum temperature

}

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