Question

Write a driver C++ program that will test the following functions in the same order they...

Write a driver C++ program that will test the following functions in the same order they are written next. You can test your program by reading the following values: n1= 10 and n2= 20 from the user:

The main program sends the values of the variables n1 and n2 to the function. The function calculates the average and sends it back to main program through the parameter list as call by reference parameter and will not use the return statement.

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

#include <bits/stdc++.h>
using namespace std;

void cal_avg(int a,int b,double &avg){
avg = (a+b)/2.0;
}

int main(){
int a,b;
cin >> a >> b;
double avg;
cal_avg(a,b,avg);
cout << avg << endl;
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a driver C++ program that will test the following functions in the same order they...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that is made of functions main() and rShift(). The rShift() function...

    Write a complete C++ program that is made of functions main() and rShift(). The rShift() function must be a function without return with 6 parameters. rShift() should do following. Shift the first 4 formal parameters' value one place to right circularly and send the updated values out to the caller function, i.e. main. Furthermore, after calling this function with first 4 actual parameters, say a1, a2, a3, a4, and these actual parameters should shift their value one place to right...

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Using C++ Reference Parameters Assignment Write a program that asks the user for 3 numbers, sends...

    Using C++ Reference Parameters Assignment Write a program that asks the user for 3 numbers, sends the numbers to a function that calculates the sum and product and returns the sum and product to the main function. In the main function, use a cout statement to display the sum and product. * You are returning the multiple values sum and product.

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • Write a C++ program using user defined functions that will read in the lengths of two...

    Write a C++ program using user defined functions that will read in the lengths of two side of a right triangle and then calculate the length of the hypotenuse. The program should do this twice. The program should the following user defined functions: Function readA will read in a value for side A from the user and return it to main. (it will not receive any input data from main) Function readB will read in a value for side B...

  • PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

    PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI() This function prints out your name and lists any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one...

  • In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt...

    In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...

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