How to write a program in C++ such that it will delete itself after execution ?
It's a legitimate enough question but it seems you don't understand how executables work. Execution places the program in memory so deleting the disk file is trivial (provided you don't also delete run-time dependencies).