Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in c++ pPeiin ae were to be assigned to orr[10001? nction Prototypes/Function De

ID: 3599192 • Letter: I

Question

in c++

pPeiin ae were to be assigned to orr[10001? nction Prototypes/Function Definitions Write the function prototype and definition for the function sum that accepts two integer arguments by value and returns the sum of the two arguments added together Write th by reference, prompts the user for an integer value, and assigns that value to the passed Write the function prototype and definition for the void function displayAveroge that will accept a double argument and integer argument by value with a default value of 1. The double value is the actual overage to display and the integer argument is the number of decimal points the average will be displayed with. Write the function prototype and definition for the function power that will accept two integer arguments by value and will return the baseen The first argument is the base and the second is the exponent. Validate that the arguments are not negative, otherwise return-I Write the function prototype and definition for the function printArroy that will accept a const integer array and an integer for the current count of elems. This function will print the contents of the passed integer array e function prototype and definition for the void function getinteger that accepts one integer argument

Explanation / Answer

Code for functions :


#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

//function sum returns sum of 2 arguments
int sum(int a,int b){
return a+b;
}

//takes input from the user and assigns to the passed argument by reference
void getInteger(int &num){
  
int a;
cout<<"Enter a number :"<<endl;
cin>>a;
num = a;
}

//displays the average passed with precision value
void displayAverage(double average,int uptoDecimal = 1){
cout<<fixed<<setprecision(uptoDecimal)<<average<<endl;
}

//returns a^b , -1 if any number is negative
int power(int a,int b){
  
if(a<0||b<0)
return -1;
  
return pow(a,b);
}

//test functions
int main(void) {

//test sum
cout<<"Sum of 3 and 4 is : "<<sum(3,4)<<endl;
  
//test assign
int num = 0;
getInteger(num);
cout<<"Number assigned is : "<<num<<endl;
  
//test average
displayAverage(11.9123223,3);
      
//test power
cout<<power(4,2)<<endl;
  
return 0;
}


Output :

Sum of 3 and 4 is : 7
Enter a number :
3
Number assigned is : 3
11.912
16


**If you have any query , please feel free to comment with details.
**Happy learning :)