How to know whether the ebooks which my friend gave to me is pirated or legal?

Smajdalf and sterretje may have points of view or opinions, and that is great! However, the point of view of the publisher and copyright laws determine whether a book/music/movie is pirated.

An ebook could be considered more valuable than a printed book because it doesn't take up physical space, doesn't wear out, is easy to enlarge/reduce/change the font, easy to bookmark, highlight, and copy short passages from, and cloud storage/backup of the book is free. Perhaps an ebook should be more expensive than a printed book. In my experience, ebooks are less expensive than the same title in print, in most cases. Does that make ebooks better and cheaper?

A publisher would not have a problem with somebody deleting an ebook from their computer or e-reader. You would have to check with the publisher regarding whether it is OK to then give the e-book to somebody else when you delete it from your own device, because the license agreement may disallow that.