answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tekilochka [14]
1 year ago
5

Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). O

riginal main():
int main() {
double milesPerHour;
double minutesTraveled;
double hoursTraveled;
double milesTraveled;

cin >> milesPerHour;
cin >> minutesTraveled;

hoursTraveled = minutesTraveled / 60.0;
milesTraveled = hoursTraveled * milesPerHour;
cout << "Miles: " << milesTraveled << endl; return 0;
}
#include
using namespace std;
//please write your answer here.
int main() {
double milesPerHour;
double minutesTraveled;

cin >> milesPerHour;
cin >> minutesTraveled;

cout << "Miles: " << MphAndMinutesToMiles(milesPerHour, minutesTraveled) << endl;
return 0;
}
Computers and Technology
1 answer:
babymother [125]1 year ago
6 0

Answer:

The program to this question can be given as:

Program:

#include <iostream> //header file

using namespace std; //using namespace

double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled) //defining method

{

return (minutesTraveled/ 60.0)*milesPerHour; //return value.

}

int main() //defining main method

{

double milesPerHour,minutesTraveled; //define variable

cout<<"Enter miles per hour :";  

cin >> milesPerHour;  

cout<<"Enter travelling minutes :";

cin >> minutesTraveled;

cout << "Miles: "<< MphAndMinutesToMiles(milesPerHour, minutesTraveled)<< endl;

return 0;

}

Output:

Enter miles per hour :12

Enter travelling minutes :20

Miles: 4

Explanation:

The explanation of the above C++ program can be given as:

  • In the first header file is include the function is define that is "MphAndMinutesToMiles". This function accepts two parameters that are "milesPerHour and minutesTraveled".
  • Both parameter datatype is double and the function return type is also double. Inside a function calculate miles and return its value.
  • In the main method, two variable defines that takes value from the user side and pass into the function. To print function return value we use "cout" function that prints function return value.
You might be interested in
An mp3 takes up about 16 kilobytes of memory per second of music. if you owned a one terabyte hard drive and filled it with only
xxTIMURxx [149]

60 sec. = 1 min. 3,600 sec = 1 hr. (60 sec x 60 minutes) 86,400 sec= 24 hr. (3,600 x 24) Given : 16,000 (bytes per seconds, for mp3 ) 86,400 X 16,000 = 1,382,400,000 bytes for 24 hrs. 1,382,400,000 = 1,382.4 mega bytes (Mb.) for 24 hrs of music Looking for how many days are in 1,000,000 Mb. 1,000,000 / 1,382.4 = 723.379629 Days worth of music.


8 0
1 year ago
Write a fragment of code that reads in strings from standard input, until end-of-file and prints to standard output the largest
Nady [450]

Answer:

Explanation:

Sample input file: numbers.txt

8 9 7 67 78 45 67 99 1001

Sample Output:

The largest value is:1001

Code to Copy:

// include stdafx, if using visual studio.

#include "stdafx.h"

// declare the necessary header files.

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

// Start the main function

int main()

{

// create the object of ifstream.

ifstream in_file;

// Open the file

in_file.open("numbers.txt");

// Declare the string variable

string str;

// Declare the integer variables.

int maximum = 0;

int num;

// Check whether the file open

if (in_file.is_open())

{

// Traverse the file till the end.

while (!in_file.eof())

{

// traversing the value.

in_file >> str;

// convert the string into integer.

num = stoi(str);

// Check whether value is max or not.

if (maximum < num)

{

// Update the value of maximum.

maximum = num;

}

}

}

// Display the statement on console.

cout << "The largest value is:" << maximum << endl;

// Close the file.

in_file.close();

system("pause");

return 0;

}

8 0
1 year ago
Create two classes. The first, named Sale, holds data for a sales transaction. Its private data members include the day of the m
olya-2409 [2.1K]

Answer:

A C++ program was used in creating two classes. the code is stated below.

Explanation:

Solution

The C++ program is executed below:

#include<iostream>

using namespace std;

//declare class (will be define later)

class Salesperson;

//class Sale

class Sale

{

  //private members of class

  private:

      string day;

      double amtOfSale;

      int salesPersonId;

 //public methods

  public:

      //constructor that takes day,amount of sale and salesPersonId as parameters

      Sale(string date,double sale,int id)

      {

          //set the private members to the initial values passed

          day=date;

          amtOfSale=sale;

          salesPersonId=id;

      }    

      //declare a friend function that takes objects of the two classes as parameters

      friend void display(Sale,Salesperson);

};  

//define class Salesperson

class Salesperson

{

  //private members of the class

  private:

      int salesPersonId;

      string lastName;    

  //public methods

  public:

      //constructor that takes name and id as parameters

      Salesperson(int id,string name)

      {

          //set the members of the class with the parameters passed

          salesPersonId=id;

          lastName=name;

      }  

      //declare a friend function that takes objects of the two classes as parameters

      friend void display(Sale,Salesperson);

};

//define the friend funtion

void display(Sale saleObj,Salesperson personObj)

{

  //display the sales info using the objects of the two classes

  cout<<"\nSale #"<<saleObj.salesPersonId<<" on "<<saleObj.day<<" for $"<<saleObj.amtOfSale<<" sold by #"<<personObj.salesPersonId<<" "<<personObj.lastName;

}  

int main()

{

  //create object for Sale class and pass default values

  Sale sObj1("12/25/2016",559.95,103);

  //create object for Salesperson class and pass default values

  Salesperson pObj1(103,"Woods");

 

  //create another object for Sale class and pass default values

  Sale sObj2("11/15/2016",359.95,106);

  //create another object for Salesperson class and pass default values

  Salesperson pObj2(106,"Hansen");

  //using the friend function dislay the sales info

  display(sObj1,pObj1);

  display(sObj2,pObj2);

  return 0;

}

4 0
2 years ago
Which are technical and visual demands that need to be considered when planning a project? Choose three answers
iren [92.7K]

Answer: Resolution or DPI, deliverables, and file types are important technical and visual demands to consider when planning a project.

Explanation: Keep in mind whether or not the project will be published in print or on the Web.

4 0
1 year ago
Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a
Nikolay [14]

Answer:

e) Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

Explanation:

<em>if - elseif - else statements work in sequence in which they are written. </em>

  • <em> </em>In case <em>if() statement is true, </em>else if() and else statements will not get executed.
  • In case <em>else if() statement is true</em>, conditions in if() and else if() will be checked and else statement will not be executed.
  • In case <em>if() and else if() both are false</em>, else statement will be executed<em>.</em>

First, let us consider code segment I.

In this, first of all "pea" is checked in if() statement which will look for "pea" only in the String str. So, even if "pearl" or "pear" or "pea" is present in 'str' the result will be true and "pea" will get printed always.

After that there are else if() and else statements which will not get executed because if() statement was already true. As a result else if() and else statements will be skipped.

Now, let us consider code segment II.

In this, "pearl" is checked in if() condition, so it will result in desired output.

Executable code is attached hereby.

Correct option is (e).

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
3 0
1 year ago
Other questions:
  • Splunk uses ________ to categorize the type of data being indexed..
    11·2 answers
  • Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
    6·1 answer
  • What company built its first computer from a wooden box
    12·2 answers
  • You are researching RAM for a computer you are building for a friend who will be using the system as a home office server for he
    14·1 answer
  • Prompt: Which references and reference formats are you most likely to use? Why?<br><br><br> ED2020
    13·2 answers
  • Why is the following statement true - ideally, your information is abbreviated
    10·2 answers
  • Describe the basic features of the relational data model and discuss their importance to the end user and the designer. Describe
    9·1 answer
  • int decode2(int x, int y, int z); is compiled into 32bit x86 assembly code. The body of the code is as follows: NOTE: x at %ebp+
    5·1 answer
  • When pasting an object which has been copied from a different slide, where on the slide does the object paste, assuming nothing
    15·1 answer
  • In cell M2, enter a formula using a nested IF function as follows to determine first if a student has already been elected to of
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!