gcain9059
19.12.2019 •
Computers and Technology
Write a function so that the main() code below can be replaced by the simpler code that calls function original 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;
// write your answer here.
int main() {
double milesperhour;
double minutestraveled;
cin > > milesperhour;
cin > > minutestraveled;
cout < < "miles: " < < mphandminutestomiles(milesperhour, minutestraveled) < < endl;
return 0;
}
Solved
Show answers
More tips
- H Health and Medicine How to Treat Styes: Causes, Symptoms, and Home Remedies...
- C Computers and Internet How to Learn to Type Fast?...
- F Food and Cooking Delight for Gourmets: How to Prepare Liver Pate...
- S Style and Beauty How to braid friendship bracelets?...
- H Health and Medicine Mercury Thermometer Danger: What to do when a thermometer breaks?...
- F Food and Cooking Which Calamari Salad is the Most Delicious?...
- S Society and Politics 10 Tips for Boosting Your Self-Esteem...
- F Food and Cooking The Most Delicious and Simple Fish in Batter Recipe...
- H Health and Medicine What is Autism? Understanding the Basics of This Neurodevelopmental Disorder...
- P Philosophy How to Develop Extrasensory Abilities?...
Answers on questions: Computers and Technology
- M Mathematics The length of AB is what ft...
- B Biology Why do the components of maternal cytoplasm influence early development? HINT: It s not A. A. because the components of maternal cytoplasm suppress the components of paternal...
- M Mathematics Can someone please help me without any links or guessing? I’m putting a lot of points into this one so if you could just help me that would be very much appreciated! Justin made...
- M Mathematics Consider a system of two linear equations in two variables. If the graphs of the equations are not the same line, is it possible for the system to have infinitely many solutions....
- E English How does paragraph 3 relate to the other paragraphs in the section Unlikely in the Extreme ? Paragraph 3 introduces a problem, and the other paragraphs explain the solution to...
- S Spanish Can someone please help me I dont understand this at all...
- B Biology Why are gene therapy clinical trials being conducted? A. To make the treatment safer, expand its applications, and create more permanent results B. To make the treatment safer...
- M Mathematics WILL MARK BRAINLIEST The graph of F(x), shown below, has the same shape as the graph of G(X) = x3 - x2, but it is shifted to the left 2 units. What is its equation? O A. F(x)...
- M Mathematics Chapter 7 need help ASAP...
- M Mathematics 18 and 19 please i really need help :)...
Ответ:
The program illustrates the use of functions.
Functions are used to group similar set of instructions together in order to achieve a specific outcome.
The required function is as follows:
double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled){
return milesPerHour * minutesTraveled/60;
}
The first line of the function declares the function, and its parameters.
double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled)
The function name is MphAndMinutesToMilesThe function type is doubleThe function parameters are milesPerHour and minutesTraveledThe second line of the function calculates the miles traveled, and returns it back to main().
return milesPerHour * minutesTraveled/60;
See attachment for complete program and the sample run
Read more about similar programs at:
link
Ответ:
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.Ответ:
int vowels(string s){
int count=0;
for(int i=0;s[i]!='\0';i++){
if(s[i]=='a' || s[i]=='e' ||s[i]=='i'||s[i]=='o'||
s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||
s[i]=='O' || s[i]=='U'){
count++;
}
}
return count;
}
Explanation:
Create the function with return type int and declare the parameter as a string.
define the variable count for storing the output. Then, take a for loop for traversing each character of the string and if statement for checking the condition of the vowel.
vowel are 'a', 'e', 'i', 'o', 'u' in lower case. we must take care of the upper case as well.
vowel are 'A', 'E', 'I', 'O', 'U' in upper case.
if the condition is true to update the count by 1.
This process continues until the string not empty.
and finally, return the count.