How find out the rate of ETH in USD in the contract?
To automatically get this data, rather than manually feeding it in by calling a function in the contract, you would need to use an oracle to get the real-world information into your contract. See these previous threads for an idea:
First interpretation: This is
Second interpretation: This can be done in Solidity?
Yes, see the threads I link to. Note that using an oracle isn't free. You will need to pay for the service.