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...
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...
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;...
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:...
#include<iostream> using namespace std; int main() {    int number_resistors;    double Resistors;    double series;...
#include<iostream> using namespace std; int main() {    int number_resistors;    double Resistors;    double series;    double parellel;    cout << "how many resistors: ";    cin >> number_resistors;    while (number_resistors != 0)    {        cout << "Enter the values of" << number_resistors << " resistors ";        for (int i = 0; i < number_resistors; i++) {            cin >> Resistors;            series += Resistors;                parellel...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT