First, don't do this. No matter how much you think you want to do it, you don't. Seriously. You're messing around with system security in a major way by doing this. These systems are difficult to get correct, even by people who know them really well. So, don't do it. If you need to give someone permission to shut down your system, figure out how to configure sudo
to allow it. Don't go down the path you're going down.
If you absolutely insist on doing this, or you're just playing around on a test VM that you intend to wipe after you finish playing, learn how to set the 'setuid' bit on an executable.
Do these three commands:
$ chmod a-w name_of_executable
$ sudo chown root name_of_executable
$ sudo chmod u+s name_of_executable
that will set it up so that the program has permission to become root no matter who runs it. Needless to say, that's a very dangerous situation to create, and many things can go wrong. There are executables on your system right now that are set up this way, but they are hardened, very carefully written executables that have been extensively scoured for bugs and get fixed quickly if someone notices something wrong with them. Don't create one yourself.
Also, to solve the problem you stated in your question, the other answer is much better. I'm giving you the answer of how to make the program you posted work. You shouldn't use that program though. You should do what that other answer says.