given a code //file: q2P2.cpp #include <iostream> #include <cstdlib> /* for rand
ID: 3542504 • Letter: G
Question
given a code
//file: q2P2.cpp
#include <iostream>
#include <cstdlib> /* for rand() */
using namespace std;
//----- function prototype here ----------
void f(float x,float y,float z, float*avg, float* min, float*max);
int main (int argc, char** argv){
float x, y, z;
x = static_cast<float>(rand()) / static_cast<float>( RAND_MAX );
Y = static_cast<float>(rand()) / static_cast<float>( RAND_MAX );
z = static_cast<float>(rand()) / static_cast<float>( RAND_MAX );
float avg, min, max;
How can i call a function f that will return avg, min, and max. Values are returned by referance through the parameter list using pointers.
Explanation / Answer
int main (int argc, char** argv){
float x, y, z;
x = static_cast<float>(rand()) / static_cast<float>( RAND_MAX );
Y = static_cast<float>(rand()) / static_cast<float>( RAND_MAX );
z = static_cast<float>(rand()) / static_cast<float>( RAND_MAX );
float avg, min, max;
avg = average(&x,&y,&z);
min=minimum(&x,&y,&z);
max=maximum(&x,&y,&z);
}
float average(int *x,in *y,int *z){
return (x+y+z)/3;
}
float minimum(int *x,in *y,int *z){
float min;
if(x<y){
min=x;
}
else
min=y;
if(min>z)
min=z;
return min;
}
loat maximum(int *x,in *y,int *z){
float max;
if(x>y){
max=x;
}
else
max=y;
if(max<z)
max=z;
return max;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.