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

Write and test a C++ function named makeMilesKmTable() to display a table of mil

ID: 3799692 • Letter: W

Question

Write and test a C++ function named makeMilesKmTable() to display a table of miles converted to kilometers. The arguments to the function should be the starting and stopping values of miles and the increment. The output should be a table of miles and their equivalent kilometer values. Use the relationship that 1 mile = 1.61 kilometers, b. Modify the function written for Exercise 6a so that two columns are printed. For example, if the starting value is 1 mile, the ending value is 20 miles, and the increment is 1, the display should look like the following:

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;

void makeMilesKmTable(double start, double stop, int increment)

{

int split_table_index = (int)(start + stop)/2;
double miles1, miles2;
const char separator = ' ';

miles1 = start;

cout<<" Miles"<<" "<<"= Kilometers"<<setw(10)<<"Miles"<<" "<<"= Kilometers" <<" ";

for(double i = start; i<= split_table_index; i+=1)
{
miles1 = i;
miles2 = miles1 - start + split_table_index + increment;
cout<<" "<<miles1<<" "<<setprecision (2) << fixed << miles1*1.61 <<setw(20)<< miles2<<" "<< setprecision (2) << fixed<<miles2*1.61 <<" ";   
}

}

int main()
{
makeMilesKmTable(1,20, 1);
}

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