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

C++. Write a program that declares three one dimensional arrays named miles, gal

ID: 3931017 • Letter: C

Question

C++.

Write a program that declares three one dimensional arrays named miles, gallons, and mpg. Each array should be declared in main() and should be capable of holding ten double-precision numbers. The numbers that should be stored in miles are 229.33, 307, 139.1, 220.6, 290.8, 189.9, 199.1, 163.7, 177.9, 193.16. The numbers should be stored in gallons are 10.1, 12.6, 4.7, 14.7, 17.3, 16.9, 13.2, 11.7, 7.3, 9.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the equivalent element of the gallons array. (e.g., mpg [0] = miles [0]/gallons [0]). Use pointers when calculating and displaying the elements of the mpg array.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;



main()
{
double miles[10]={229.33,307,139.1,220.6,290.8,189.9,199.1,163.7,177.9,193.16};
double gallons[10]={10.1,12.6,4.7,14.7,17.3,16.9,13.2,11.7,7.3,9.4};
double mpg[10]={0};

double* mpgptr1=mpg;

for(int i=0;i<10;i++)
{
   *mpgptr1=miles[i]/gallons[i];
   mpgptr1++;
  
}

double* mpgptr2=mpg;

for(int i=0;i<10;i++)
{
   cout<<*mpgptr2<<" "<<endl;
   mpgptr2++;
  
}

return 0;

}

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