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, gall

ID: 3684655 • 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 240.52, 300, 189.6, 310.6, 280.7, 206.9, 199.4, 160.3, 177.4, 192.16. The numbers should be stored in gallons are 10.3, 15.6, 8.7, 14, 16.3, 15.7, 14.9, 10.7, 8.3, 8.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

// Example program
#include <iostream>
using namespace std;

int main()
{
double miles[] = {240.52,300,189.6,310.6,280.7,206.9,199.4,160.3,177.4,192.16};
double gallons[] = {10.3,15.6,8.7,14,16.3,15.7,14.9,10.7,8.3,8.4};
double mpg[10];
for(int i=0;i<10;i++)
{
*(mpg+i) = (*(miles+i))/(*(gallons+i));
cout<<*(mpg+i)<<' ';
}
}

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