In the Mac terminal Write c++ function maxmin(float x, float * pmax, float * pmi
ID: 3743811 • Letter: I
Question
In the Mac terminal Write c++ function maxmin(float x, float * pmax, float * pmin) where x is a new value which is to be compared with the largest and the smallest values pointed to by pmax and pmin, respectively. The function should indirectly update the largest and the smallest values appropriately. Write a program that reads a sequence of numbers and uses the above function to update the maximum and the minimum until end of file, when the maximum and the minimum should be printed.
Explanation / Answer
#include #include using namespace std; void maxmin(float x, float * pmax, float * pmin) { if(x > *pmax) { *pmax = x; } if(x < *pmin) { *pmin = x; } } int main() { float num; cin >> num; float min = num, max = num; while(cin >> num) { maxmin(num, &max, &min); } coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.