Question

In: Computer Science

#include <iostream> #include <iomanip> using namespace std; int main() {             float miles;   //miles traveled          &nbsp

#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

……………………………………………………………………..

  1. 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>

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

……………………………………………………………………..

Solutions

Expert Solution

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


Related Solutions

#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count =...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count = 0, maximum = 0, minimum = 0;     cout << "Enter your student ID number: ";     cin >> studentid;     cout << "Student ID Number = " << studentid << endl;     while (studentid != 0)     {          numberreverse[count] = studentid % 10;          if (count == 0)          {              minimum = numberreverse[count];              maximum = minimum;          }          else...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char**...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char** argv) { int number, sum, count; // Write a while loop that reads a number from the user and loop // until the number is divisible by 7 cout << "What is the number? "; cin >> number; while ( ... ) { ... } cout << number << " is divisible by 7!! << endl << endl; // Write a for loop that...
9. #include <fstream> #include <iostream> using namespace std; int main() {     float bmi;     ifstream...
9. #include <fstream> #include <iostream> using namespace std; int main() {     float bmi;     ifstream inFile;     inFile.open("bmi.txt");     while (!inFile.eof())       {          inFile >> bmi;          if( bmi < 18.5)           {               cout << bmi << " is underweight " ;           }         else if( bmi >= 18.5 && bmi <= 24.9)           {               cout << bmi << " is in normal range " ;           }         else if( bmi >= 25.0 &&...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int SIZE = 20;     char str[SIZE];     char str1[SIZE];     int n;     int k =1;        printf("Enter a word: \n");     fgets(str,SIZE,stdin);     printf("Enter another word: \n");     fgets(str1,SIZE,stdin);        if (str1[strlen(str1) - 1] == '\n')     {         str1[strlen(str1)-1] = '\0';     }     if (str[strlen(str) - 1] == '\n')     {         str[strlen(str)-1] = '\0';     }      ...
9. #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt");...
9. #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt"); while (!inFile.eof()) { inFile >> bmi; if( bmi < 18.5) { cout << bmi << " is underweight " ; } else if( bmi >= 18.5 && bmi <= 24.9) { cout << bmi << " is in normal range " ; } else if( bmi >= 25.0 && bmi <= 29.9) { cout << bmi << " is overweight " ; } else...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1;...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1; hour <= 12; hour++)     {         for (min = 0; min <= 59; min++)         {             cout << hour << ":" << min << "AM" << endl;         }     }       return 0; } 1.      Type in the above program as time.cpp. Add a comment to include your name and date. Compile and run. 2.      What is the bug or logic error in the above program? Add the...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool a = true; bool b= true;    //Print the Conjunction function cout<<"\n\nConjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(P∧Q)" <<endl; cout<< a <<"\t"<< b <<"\t"<< conjunction(a,b) <<endl; cout<< a <<"\t"<< !b <<"\t"<< conjunction(a,!b) <<endl; cout<< !a <<"\t"<< b <<"\t"<< conjunction(!a,b) <<endl; cout<< !a <<"\t"<< !b <<"\t"<< conjunction(!a,!b)<<endl;    //Print the Disjunction function cout<<"\n\nDisjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(PVQ)" <<endl; cout<< a <<"\t"<< b <<"\t"<< disjunction(a,b) <<endl;...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool a = true; bool b= true;    //Print the Conjunction function cout<<"\n\nConjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(P∧Q)" <<endl; cout<< a <<"\t"<< b <<"\t"<< conjunction(a,b) <<endl; cout<< a <<"\t"<< !b <<"\t"<< conjunction(a,!b) <<endl; cout<< !a <<"\t"<< b <<"\t"<< conjunction(!a,b) <<endl; cout<< !a <<"\t"<< !b <<"\t"<< conjunction(!a,!b)<<endl;    //Print the Disjunction function cout<<"\n\nDisjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(PVQ)" <<endl; cout<< a <<"\t"<< b <<"\t"<< disjunction(a,b) <<endl;...
I need a Flowgorithm chart of this #include using namespace std; int main() {    float...
I need a Flowgorithm chart of this #include using namespace std; int main() {    float CISBook[] = {55.5,35.8,67.5};    float MATHBook[] = {25.5, 54.5};    float MECBook[] = {65.0,75.5,86.8};    float sumCIS=0, sumMATH = 0, sumMEC = 0;              for (int i=0; i<4; i++)    {sumCIS += CISBook[i];}       for (int i=0; i<3; i++)    {sumMATH += MATHBook[i];}       for (int i=0; i<4; i++)    {sumMEC += MECBook[i];}       cout<<"\nTotal for CIS Books:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT