Can my iPhone 4 get a virus?

My iPhone seems to delete contacts by random, but more so the recently added ones. Can this be the effect of a virus? The Mac that I sync it to is extremely slow and we suspect it may have various viruses. If my phone does happen to have a virus, could it have come from the Mac?

Very unlikely. Its runs IOS which is based on Linux.

Every device that can access email and internet are vulnerable. There have been a few viruses or malicious apps written for iOS that have gotten through the Apple Store filters but it's pretty rare. If you believe your Mac is infected, the issue MIGHT lie there, although without knowing the specifics of the infection, I can't say that for sure. The issue may be a simple sync corruption with the iTunes software or whatever software you use to sync your phone. Again if the issue happens just on the phone, regardless of whether or not you've recently synced to your Mac, it may also be a software issue with your contacts list.It'd be worth a call to Apple Support for help with this.

No! Apple's products are safe from viruses because no one writes viruses for OS X and iOS

The iOS is a very secure platform, so the chances of downloading or getting infected by malware are slim to none, at least on a non-jailbroken iPhone. However, if your iPhone is jailbroken, then the possibility of getting a virus is much higher, because you are removing Apple's limitations, which basically prevent bad files from hijacking/monitoring your phone.
It might've been something you downloaded, like an app, or it could be an issue with your phone.