Question

December 2016 High Temps - 45,40,39,42,44,42,43,36,28,28,35,42,33,31,19,23,58,59,27,37,38,40,41,47,40,66,65,43,41,33,43 Get the top five hottest and top five coldest high...

December 2016 High Temps - 45,40,39,42,44,42,43,36,28,28,35,42,33,31,19,23,58,59,27,37,38,40,41,47,40,66,65,43,41,33,43

Get the top five hottest and top five coldest high temperatures of the month and display them (the day and temperature)

language is php also i already put in array

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Approach:

  • In order to find the top and least temperatures from the given values, it is evident that we require sorting. However, we also need to display the days of the respective temperatures, so we need to somehow store that data as well.
  • We use the following construct in PHP to associate the respective days of December 2016.

$temperature = array("1"=>"45", "2"=>"40" . . . "31"=>"43");

  • In the above construct, the "1" refers to the date and "45" refers to the corresponding temperature. "1" is called the key and "45" is the value in this case. This is known as an associative array.
  • The inbuilt asort() function helps us to sort the array by value in ascending order (temperature values in this case). Similarly, the arsort() sorts the key-value pairs in descending order.

asort($temperature)

arsort($temperature)    ~The r stands for reverse~

  • The for-each loop iterates over the associative array where $x is the key and $x_value is the corresponding value.
  • We use the variable $i in the code below to keep track of 5 temperatures and then break the for-each loop after 5 outputs.

Only showing the array for some temperature values for this example. You can populate the associated array with all values if required. The code below has been tested and works as required by the problem statement.

Code:

<?php

$temperature = array("1"=>"45", "2"=>"40" ,"3"=>"39" ,"29"=>"41" ,"30"=>"41" ,"31"=>"43");

asort($temperature);
echo "Min Values<br>";
$i=0;
foreach($temperature as $x => $x_value) {
    echo "Date=" . $x . ", Temperature=" . $x_value;
    echo "<br>";
    if(++$i==5) break;
}
echo "<br>";

arsort($temperature);
echo "Max Values<br>";
$i=0;
foreach($temperature as $x => $x_value) {
    echo "Date=" . $x . ", Temperature=" . $x_value;
    echo "<br>";
    if(++$i==5) break;
}
?>

Add a comment
Know the answer?
Add Answer to:
December 2016 High Temps - 45,40,39,42,44,42,43,36,28,28,35,42,33,31,19,23,58,59,27,37,38,40,41,47,40,66,65,43,41,33,43 Get the top five hottest and top five coldest high...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I don't understand step 3 also can someone check if I did the setTemps method right?...

    I don't understand step 3 also can someone check if I did the setTemps method right? Step 2: Temps Class For lab9 we will be using arrays to store the high temperatures for a given month and perform some simple statistics for them. You will create a Temps class to store the values and perform the calculations. (Data that you use for this lab was obtained from the national weather service and city‐data.com – from June 2004) Create a new...

  • On this project you will make calculations and conclusions based on real data collected by the...

    On this project you will make calculations and conclusions based on real data collected by the NOAA (The National Oceanic and Atmospheric Administration, an agency of the United States government) on the “Daily Lake Average Surface Water Temperature” of six lakes (Ontario, Erie, Huron, Michigan, Superior, and St. Clair) during the 2017 calendar year. You can find the actual data file here that contain the average temperatures for each day of the year for each of the six lakes. Data...

  • Suppose that the temperature for each day in December was 65 degree high and 25 degree...

    Suppose that the temperature for each day in December was 65 degree high and 25 degree low. What is the payoff from a call option on the cumulative HDD during December with a strike 420 and a payment rate of $5,000 per HDD? We were unable to transcribe this imageA trader has the following portfolio: Long June CDDs in JFK (NY) at 400, Short June CDDs in LGA (NY) at 480. Both are swaps. Assume that due to construction, High...

  • On this project you will make calculations and conclusions based on real data collected by the...

    On this project you will make calculations and conclusions based on real data collected by the NOAA (The National Oceanic and Atmospheric Administration, an agency of the United States government) on the “Daily Lake Average Surface Water Temperature” of six lakes (Ontario, Erie, Huron, Michigan, Superior, and St. Clair) during the 2019 calendar year. You can find the actual data file here that contain the average temperatures for each day of the year for each of the six lakes. Data...

  • Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June....

    Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June. He would like you to write a program to compute some statistics based on the data he has collected. He has placed each daily high temperature on a separate line in a file named “summer_temps.txt”. The high temperatures are in order so that the first one is for June 1, the second is for June 2, and so on. The statistics that the meteorologist...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • Group Project Financial Planning A local dym just went corporate, so you decide to investigate its...

    Group Project Financial Planning A local dym just went corporate, so you decide to investigate its profitabit to see if it stock is worth buying. The gym collect a flat toe of 50 per month from each of its 63 members, but it's maintenance expenses are $170 per month plus an additional $0.15 every time someone uses the gym. The gym has created a solid model they use to predict how much use they get over the year U(m) =...

  • Laura is a very successful businesswoman in the high-stress high-powered world of corporate finance. She has...

    Laura is a very successful businesswoman in the high-stress high-powered world of corporate finance. She has been referred to you by the company’s employment assistance program. You are the company's occupational nurse. Laura presents herself as a no nonsense business professional. She is frank and honest about the events that has brought her to your office. Laura tells you that although she tells herself that she will only have one or two glasses with dinner, she usually finishes the whole...

  • Use this Excel Culminating Project Template (SEE SCREENSHOT BELOW) to help you get started with your...

    Use this Excel Culminating Project Template (SEE SCREENSHOT BELOW) to help you get started with your budget You are the president of Campus Sweaters, Inc. Campus Sweaters manufacturers wool pullover v-neck sweaters of various sizes and colors. You are preparing the budgets for the first quarter of 2016 (January, February, and March). You have the following historical and projected sales in units: Actual or Projected Month Units Actual November 9,000 Actual December 8,000 Projected January 11,000 Projected February 10,000 Projected...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT