Downgrading your compiler can be a mess. I wouldn't recommend it. I also wouldn't recommend teaching with such an outdated compiler.
Personally, I would go for one out of 2 approaches: install an old Linux version that comes with this Gcc version in a virtual machine or if it's a handful of files, use compiler explorer.
For virtualization, I only have experience with virtualbox, however other good alternatives exist. You search for a Linux distro that has that version of Gcc and install a temporary computer that way. Once the course is finished, you throw the machine out and your current system ain't affected.
The easier alternative is to simply plug your files in compiler explorer, it has a lot of different compiler versions including the compiler you need.
It does require you to enter file by file, so I would recommend writing a script to (recursively) resolve your local includes and create a simple preprocessed file that you can plug in the site.
For sure, write your code with a supported version of c++, don't use c++2a features when coding.