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. You could use:
Check out this blog post for a more thorough explanation and example of how to fetch ETH/USD price data using Chainlink Price Feeds
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.