Look Up a Seat Safely with at()
Look Up a Seat Safely with at()
A std::vector has two ways to read an element: seats[index] does no checking, while seats.at(index) throws a std::out_of_range when the index is not valid. Write printSeat(const std::vector<std::string>& seats, int index), which reads the name with at into a variable inside a try, then prints Seat , the index, : and the name on one line. When at throws, catch the std::out_of_range and print No seat at index followed by the index. Do not print the library's own message from what(); its wording differs between compilers. Read the name BEFORE printing the label, so a failed lookup does not leave half a line behind.
The tests call printSeat for several indexes, valid and not.
Do NOT write a main function.
Expected Output:
Seat 1: Bo No seat at index 3 Seat 0: Ana
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...