CSE 333 24su Exercise 11

Due: Wednesday, July 17th, 2024 by 10:00 am; No late exercises accepted
Goals: Learn to use the C++ STL container vector and some algorithms associated with it, create and use a function template, and learn how to check for errors when reading data from an input stream.

Description: Write a C++ program that prompts the user to type in 6 doubles, reads those doubles from stdin into a std::vector of doubles, sorts the vector using std::sort, and then prints out the sorted vector. To gain additional practice with templates, you should create and use a helper function called ReadValue to read each input value. This function should use templates to abstract away the type returned; i.e., it should have the following function prototype:

template <class T> T ReadValue(istream& in);

As well, ReadValue should detect conversion and unexpected EOF conditions, and, in such cases, exit(EXIT_FAILURE) after printing out a helpful error message. Member functions of istream like .good can be useful for this. See the istream documentation.

Altogether, your program should match the following transcript as closely as you can:

bash$ g++ -Wall -g -std=c++17 -o ex11 ex11.cc
bash$ ./ex11
Enter 6 doubles:
6.0
3.33
10.1
-10.5
6
1.441
Your sorted doubles are:
-10.5
1.441
3.33
6
6
10.1
bash$


As usual, your code must:

You should submit your exercise to the course Gradescope.