Write a static method that would appear in the Metric Class
Write a static method that would appear in the Metric Class. This method would be a utility method that converts an amount of miles to kilometers. Both the miles and the kilometer amount will be floating point amounts. The method receives the miles amount through a parameter. The method returns the calculated kilometers. The conversion rate for calculating kilometers from miles is 1.609. That is a miles amount times 1.609 will produce a kilometers amount.
Solution
#include <stdio.h>
#include<conio.h>
using namespace std;
//function declaration
int calculate_km(int);
//function definition
int calculate_km(int mile)
{
//conversion from mile to kilmetre
int kilometre=(1.609*mile);
return kilometre;
}
//execution starts here
int main(void)
{
float km, miles;
getchar();
printf(\"enter the miles\ \");
scanf(\"%f\", &miles);
//function call to calculate km by inputting miles as parameter
km=calculate_km(miles);
//print kilometre and mile
printf\"%f mile means %f kilometre\",miles, km);
//see output
getch();
}
