Q1. List out all the local variable(s) and parameters in functions main() and po
ID: 3660060 • Letter: Q
Question
Q1. List out all the local variable(s) and parameters in functions main() and power(), respectively.
==========pow.cpp=============
#include <iostream>
#include <iomanip>
using namespace std;
// Q2. Add one statement here to make the program compile.
int main(){
double result=0;
power(10, 6, result);
cout<<fixed;
cout<<"10 to the power of 6 yields "<<setprecision(0)<<result<<endl;
return 0;
}
// Q3. Modify function power() such that the program outputs 1,000,000 rather than 0.
void power(double base, int exponent, double result){
result = 1;
while (exponent>0){
result = base * result;
exponent = exponent-1;
}
}
==========pow.cpp=============
Q4. Change power() to a value-returning function that returns the result of raising base to the power of exponent. Rewrite the whole program so that it works correctly with the new power().
Explanation / Answer
Q1. main: parameters: none local variables: result power: parameters: base(type double), exponent(type int), result(type double) local variables: none Q2. void power(double , int, double); Q3. //??? what does this mean by 1000000 instead of 0? Q4. _____________________________________________________ #include #include using namespace std; double power(double, int); int main(){ double result=power(10, 6); coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.