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

1 // This program converts the speeds 60 kph through 2 // 130 kph (in 10 kph inc

ID: 3673306 • Letter: 1

Question

1 // This program converts the speeds 60 kph through
2 // 130 kph (in 10 kph increments) to mph.
3 #include <iostream>
4 #include <iomanip>
5 using namespace std;
6
7 int main()
8 {
9        // Constants for the speeds
10       const int START KPH = 60, // Starting speed
11                      END_KPH = 130, // Ending speed
12                      INCREMENT = 10; // Speed increment
13
14       // Constant for the conversion factor
15       cont double CONVERSION_FACTOR = 0.6214;
16  
17       // Variables
18       int kph;               // To hold speeds in kph
19       double mph:       // To hold speeds in mph
20
21       // Set the numeric output formatting.
22       cout << fixed << showpoint << setprecision(1);
23
24       // Display the table headings.
25       cout << "KPH/tMPH ";
26       cout << "--------------- ";
27
28       // Display the speeds.
29       for (kph = START_KPH; kph <= END_KPH; kph += INCREMENT)
30       {
31            // Calculate mph
32            mph = kph * CONVERSION_FACTOR;
33
34            // Display the speeds in kph and mph.
35            cout << kph << " " << mph << endl;
36
37       }    
38       return 0;
39 }

Program Output
KPH          MPH
---------------
60              37.3
70              43.5
80              49.7
90              55.9
100            62.1
110            68.4
120            74.6
130            80.8

****add the following in the code listing****
     (a) Conversion from MPH to KPH
     (b) conversion factor CONVERSION_FACTOR_M_TO_K = 1.6093
     (c) Convert from 20 MPH to 100 MPH in 10 MPH increments
     (d) Output the results in an additional table.



Explanation / Answer

// This program converts the speeds 60 kph through
// 130 kph (in 10 kph increments) to mph.
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
// Constants for the speeds
const int START_KPH = 60, END_KPH = 130, INCREMENT = 10;

const int START_MPH = 20, END_MPH = 100, INCREMENT_MPH = 10;

// Constant for the conversion factor
const double CONVERSION_FACTOR = 0.6214;
const double CONVERSION_FACTOR_MPH = 1.6093;
// Variables
int kph;               // To hold speeds in kph
double mph;       // To hold speeds in mph

// Set the numeric output formatting.
cout<< fixed << showpoint << setprecision(1);

// Display the table headings.
cout<< "KPH MPH ";
cout<< "--------------- ";

// Display the speeds.
for (kph = START_KPH; kph <= END_KPH; kph += INCREMENT)
{
      // Calculate mph
      mph = kph * CONVERSION_FACTOR;

      // Display the speeds in kph and mph.
      cout << kph << " " << mph << endl;

}  

int MPH;
double KPH;
// Display the table headings.
cout << " MPH KPH ";
cout << "--------------- ";

for (MPH = START_MPH; MPH <= END_MPH; MPH += INCREMENT)
{
      // Calculate mph
      KPH = MPH * CONVERSION_FACTOR_MPH;

      // Display the speeds in kph and mph.
      cout << MPH << " " << KPH << endl;

}
        return 0;
}