If the main problems of Bitcoin are the speed and the cost of transactions, how can it continue to be the dominant cryptocurrency as popularity and demand increase? Can its source code be modified?

First, bitcoin has been one of the most vetted cryptocurrencies. Whenever bitcoin gets "hacked" it is virtually always due to human error in not keeping a private key secure. When other cryptocurrencies try to use their own code there are sometimes vulnerabilities that allow a direct attack. This gives bitcoin the perceived value of being extremely secure.

It's also a combination of basic brand recognition and scarcity. Bitcoin and cryptocurrency are synonymous in most people's minds. It's also a status symbol to own at least one bitcoin. Most countries have a population over 21 million therefore if, as an example, everyone in Canada wanted to own one bitcoin each even after the last bitcoin had been mined that wouldn't be possible.

Of course, if the world switched over to bitcoin the source code would have to be modified so that there would be more decimal places and transactions could be made with less than  0.00000001 BTC.