Question

 CHALLENGE ACTIVITY   13.2.1: Functions: Factoring out a unit-conversion calculation. 

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

CHALLENGE ACTIVITY 13.2.1: Functions: Factoring out a unit-conversion calculation Write a function so that the main code belo

13. 2.2: Function stubs: Statistics. 

Define stubs for the functions called by the below main0. Each stub should print "FIXME: Finish FunctionName0" followed by a newline, and should return -1. Example output:

CHALLENGE ACTIVITY 13.2.2: Function stubs: Statistics. Define stubs for the functions called by the below maino. Each stub sh


3 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

1)

#include

using namespace std;


double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled);


int main ()

{

  double milesPerHour;

  double minutesTraveled;

  

  cin>>milesPerHour;

  cin>>minutesTraveled;

  

  cout return 0;

}


double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled){

  double hoursTraveled = minutesTraveled/60.0;

  double milesTraveled = hoursTraveled*milesPerHour;

  return milesTraveled;

}


2)

#include

using namespace std;


// function prototypes

int GetUserNum();

int ComputeAvg(int, int);


int main ()

{

  int userNum1;

  int userNum2;

  int avgResult;

  

  userNum1 = GetUserNum();

  userNum2 = GetUserNum();

  

  avgResult = ComputeAvg(userNum1, userNum2);

  

  cout return 0;

}


int GetUserNum(){

  // ask user to enter number and return that number

  int num;

  cout cin>>num;

  return num;

}

int ComputeAvg(int userNum1, int userNum2){

  // return average

  return (userNum1+userNum2)/2;

}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
CHALLENGE ACTIVITY 13.2.1: Functions: Factoring out a unit-conversion calculation Write a function so that the main...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 6.5.1: Functions: Factoring out a unit-conversion calculation. PYTHON CODING Write a function so that the main program b...

    6.5.1: Functions: Factoring out a unit-conversion calculation.PYTHON CODINGWrite a function so that the main program below can be replaced by the simpler code that calls function mph_and_minutes_to_miles(). Original main program:miles_per_hour = float(input()) minutes_traveled = float(input()) hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('Miles: %f' % miles_traveled)Sample output with inputs: 70.0 100.0Miles: 116.666667

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • Define stubs for the methods called by the below main(). Each stub should print "FIXME: Finish...

    Define stubs for the methods called by the below main(). Each stub should print "FIXME: Finish methodName()" followed by a newline, and should return -1. Example output: FIXME: Finish getUserNum() FIXME: Finish getUserNum() FIXME: Finish computeAverage() Avg: -1 import java.util.Scanner; public class MethodStubs{ /* Your solution goes here */ public static void main(String [] args) { int userNum1; int userNum2; int avgResult; MethodStubs stubTester = new MethodStubs(); userNum1 = stubTester.getUserNum(); userNum2 = stubTester.getUserNum(); avgResult = stubTester.computeAverage(userNum1, userNum2); System.out.println("Avg: " +...

  • All JAVA code 6.2.2: Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints...

    All JAVA code 6.2.2: Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. Ex: printFeetInchShort(5, 8) prints: 5' 8" Hint: Use \" to print a double quote Sample program: import java.util.Scanner; public class HeightPrinter { /* Your solution goes here */ public static void main (String [] args) { printFeetInchShort(5, 8); System.out.println(""); return; } } 6.4.1: Define stubs for the methods called by the below main(). Each stub should print "FIXME: Finish...

  • C++ Write a function so that the main() code below can be replaced by the simpler...

    C++ Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). 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; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> using...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • You are to write two functions, printString() and testString(), which are called from the main function....

    You are to write two functions, printString() and testString(), which are called from the main function. printString (string) prints characters to std::cout with a space after every character and a newline at the end. testString (string) returns true if the string contains two consecutive characters that are the same, false otherwise. See the main() to see how the two functions are called. Some sample runs are given below: string: “hello” printString prints: h e l l o testString returns: true...

  • c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study...

    c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study the syntax of passing an array as a function parameter) The program prompts the user to first enter the number of tests given in a course, and then prompts him/her to enter the mark for each test. The marks are stored in an array. This takes place in the main() function. It then passes the array to a function named 'average' that calculates and...

  • Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development p...

    Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development practices and problem solving strategies: a) Start by writing the documentation for the function. Use docstrings shown in lecture and lab. b) Write test calls to the function in your main function for the different cases of input the function will encounter. This will help you understand the behavior of the function and later behave as tests for your function. c) Define the function d)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT