In: Computer Science
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
milesHours = miles / hours;
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
1. Rewrite the above program such that function main call a return type function named findMilesPerHours to calculate the number of miles per hours. Finish function prototype, call and function definition.#include <iostream>
#include <iomanip>
// Function prototype here
……………………………………………………………………..
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
// Function call here
……………………………………………………………………..
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
// Function definition here
……………………………………………………………………..
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype here
……………………………………………………………………..
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
// Function call here
……………………………………………………………………..
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
// Function definition here
……………………………………………………………………..
Program 1 :
1. Rewrite the above program such that function main call a return type function named findMilesPerHours to calculate the number of miles per hours. Finish function prototype, call and function definition.
#include <iostream>
#include <iomanip>
// Function prototype here
float findMilesPerHours(float,float);
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" <<
endl;
cin >> miles;
cout << "Please input the hours traveled" <<
endl;
cin >> hours;
milesPerHour = findMilesPerHours(miles, hours);
cout << fixed << showpoint <<
setprecision(2);
cout << "Your speed is " << milesPerHour
<< " miles per hour" << endl;
return 0;
}
// Function definition here
float findMilesPerHours(float miles,float hours){
return miles / hours;
}
=====================================
Program 2
Rewrite the above program such that function main will call the void function named findMilesPerHours to calculate the number of miles per hours. Finish function prototype, call and function definition.
#include <iostream>
#include <iomanip>
// Function prototype here
void findMilesPerHours(float, float, float
&);
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" <<
endl;
cin >> miles;
cout << "Please input the hours traveled" <<
endl;
cin >> hours;
findMilesPerHours(miles, hours, milesPerHour);
cout << fixed << showpoint <<
setprecision(2);
cout << "Your speed is " << milesPerHour
<< " miles per hour" << endl;
return 0;
}
// Function definition here
void findMilesPerHours(float miles,float hours, float
&milesPerHour){
milesPerHour = miles / hours;
}