In C++, Write a function maxmin(float x, float * pmax, float * pmin) where x is
ID: 3742155 • Letter: I
Question
In C++, Write a 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 #include using namespace std; void maxmin(float x, float * pmax, float * pmin) { if(x > *pmax) { *pmax = x; } if(x < *pmin) { *pmin = x; } } int main() { string filename; cout > filename; ifstream in(filename.c_str()); if(in.is_open()) { float num; in >> num; float min = num, max = num; while(in >> 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.