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

5-5 Practice Problems: Arrays Using the scenario below, answer the following que

ID: 664488 • Letter: 5

Question

5-5 Practice Problems: Arrays

Using the scenario below, answer the following questions:You are preparing for the Boston Marathon. In order to prepare, you need to train for 10 weeks, running an increasing number of miles per week, starting at running at least 2 miles your first week up to 26 miles by week 10. 1.) Initialize the array with the appropriate number of values.2.) What is the value in the array element when the index contains 2?3.) What is your list length?4.) Calculate the sum of the total miles you spent running over the 10 weeks. Calculate the average number of miles you ran.5.) Write a search to determine whether 4 is on your list.

Explanation / Answer

The runner needs to start running at least 2 miles in the first week and must achieve 26 miles by week 10. A good practice is to double the miles for the second week, .

there has to be a target of (2*2=4) miles for the second week.

For the remaining weeks, the increase to be met in the number of miles per week = (26-2)/10 = 2.4 (rounded off to 3 on the upper side) Therefore, each element of the array must be incremented by 3 to achieve the last element.

1- As per scenario at least 2 miles running your first week.but in array intialization start with 0 so array will be {0, 2, 5, 8, 11, 14, 17, 20, 23, 26}

int array = {0, 2, 5, 8, 11, 14, 17, 20, 23, 26}

2- Array indexing start with 0 like a[0],a[1] etc so array element when the index contains 2 value is 5.

3- List Length = 10

4- Total miles = 0+2+5+8+11+14+17+20+23+26 = 126 miles

Average miles = 126/10 = 12.6 miles

5- search()

    {

      for(int i=0; i<array.length; i++)

          {

             if(array[i]==4)

               return true;

         }

           return false;

}

  

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