Write and test a C function named makeMilesKmTable to displa

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:

Solution

#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);
}

 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 startin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site