Question

Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named g

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

#include <iostream>

using namespace std;

//method to get average of three numbers
float getAverage(int x, int y, int z)
{
return (x+y+z) / 3.0;
}

//method to get maximum of three values
int getmaximum(int x, int y, int z)
{
if(x>=y && x>=z)
return x;
else if(y>z)
return y;
return z;
}

int main()
{
//variable declaration
int x, y, z;
  
//get user input
cout<<"Enter three whole numbers: ";
cin>>x>>y>>z;
  
//method calling and display result
cout<<"avg = "<<getAverage(x, y, z)<<endl;
cout<<"max = "<<getmaximum(x, y, z)<<endl;

return 0;
}

OUTPUT:

Enter three whole numbers: 10 20 30
avg = 20
max = 30

Add a comment
Know the answer?
Add Answer to:
Question 19 4 pts Using the program below, please complete the program by adding 2 functions...
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
  • When I run this code use ./main How to fix it when program reminds segmentation fault...

    When I run this code use ./main How to fix it when program reminds segmentation fault (core dumped)? #include <iostream> void set_num(int* i_prt, int num) { *i_prt = num; } int main(int argc, char** argv) { int x; set_num(&x, 13); std::cout << "x: " << x << std::endl; int* y; set_num(y, 4); std::cout << "*y:" << *y << std::endl; }

  • // the program attempts to sort three integers // in increasing order, it is incomplete //...

    // the program attempts to sort three integers // in increasing order, it is incomplete // Mikhail Nesterenko // 9/3/2009 #include <iostream> using std::cin; using std::cout; using std::endl; int main(){ // inputs the numbers cout << "Enter three numbers: "; int x, y, z; cin >> x >> y >> z; int tmp; // orders x and y if (x > y){ tmp = x; x = y; y = tmp; } // orders y and z if (y >...

  • 1. In ANSII standard C++, there is no library function to convert an integer to a...

    1. In ANSII standard C++, there is no library function to convert an integer to a string. Your program should develop such a function. In other words complete the following program using your itos function. (Use of other C functions is prohibitted) // this program will read in an integer and convert it to a string #include <iostream> #include <cstdlib> #include <string> using namespace std; string itos(int n) { } int main(int argc, char* argv[]){ int n = atoi(argv[1]); cout...

  • Write a C++ program In this assignment you will complete the definition of two functions that...

    Write a C++ program In this assignment you will complete the definition of two functions that implement the repeated squaring algorithm described in the Stamp textbook on pages 98-99. Note that your implementation should not use the pow() function, the powl() functions, or any other built-in exponentiation functions. program4-driver.cpp - This file contains a completed main() function that serves as the driver to parse the command line, pass the values to the powerModN() function, and print the result. Make no...

  • In c++ programming, can you please edit this program to meet these requirements: The program that...

    In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; }    while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...

  • Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks....

    Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks. The first function prints out the numbers from the first argument up to and including the number passed as the second argument counting by the first argument (i.e. if the arguments are 2 and 10, the information below was given: #include <iostream> using namespace std; // function definitions// // main program int main() {   int firstNumber,secondNumber;   char countType, doAgain;   // we will do this...

  • What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int &...

    What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int & x); int z = 10; void main() { char x = 'y'; int y = 5; int z = 100; y = DontPanic(z); cout << x << " " << y << " " << z << endl; } int DontPanic(int & x) { int * p; p = & z; x = (*p)++ + 1; cout << x << " " << *p...

  • 61. The following program is accepted by the compiler:         int sum( int x, int y...

    61. The following program is accepted by the compiler:         int sum( int x, int y )         {             int result;             result = x + y;            }                            T__   F__ 62. The following implementation is accepted by the compiler:         void product()         {             int a; int b; int c; int result;             cout << "Enter three integers: ";             cin >> a >> b >> c;             result = a * b * c;            ...

  • C++ code for CIS054 Create a program that uses a function to determine the length of...

    C++ code for CIS054 Create a program that uses a function to determine the length of a line by inputting the X,Y coordinates of the line endpoints. Show the result with a precision of four decimal places. The function prototype is to be specified as follows:     double LengthOfLine (double X1, double Y1, double X2, double Y2); // returns length of line by using this code: #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(int argc, char* argv[])...

  • You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function...

    You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function into a file named Q1.cpp. Q1.cpp should only include your function implementation, the necessary #include directives if needed, and should not contain anything else such as the main function or global variable declarations. Test your code using a separate main.cpp file where you implement a sufficient number of test cases. You should use Q1.h as a header file and Q1main.cpp as a main function...

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