To put it in the simplest terms possible:
Your grade does not depend on anyone else's grade!
You are required to demonstrate that you have meet certain standards of competence; everyone who does so passes. It is thus quite possible for everyone in the class to get A's (or conversely, for everyone in the class to get F's!)
Your grade concerns only you.
Grades are an indication of your current knowledge and ability. They may not be entirely accurate, you may have had a bad day, or two! There need be no shame associated with getting a low grade or being unsuccessful in a course. Provided you have done your best, no one can ask for or expect more, and you can be content in yourself. You know if you haven't done your best and the only person who loses out is you!
Your GPA doesn't really matter.
Everyone is different; they have different backgrounds and interests, and so
naturally learn at different rates. If you are motivated enough you will
succeed.
A lot of students see any grade below B as unacceptable. They seem to think that repeating a course to improve their GPA will help them in their careers. Ok, you need a reasonable GPA to get into graduate studies, but that's "putting the cart before the horse." If you learn the subject properly, a good GPA follows!
The GPA is an indication of your past performance and future promise. No employer worth working with will be overly concerned with minute differences in such -approximate- measures, so artificially trying to increase such numbers is pointless (even more so, given that the evidence will appear on your transcript!)
Note that changing a (minimum) D grade to an A grade in a four credit course will make a difference of only 0.09 in your CGPA at the end of your studies. You have to weigh this minor improvement against the time you will undoubtedly spend attending lectures and doing assignments (a minimum of say 6 hours per week), time you could have used more effiicently.
What matters is what else you have done.
Everyone who graduates does roughly the same courses. What distinguishes them is not so much their GPA as what else they have done during their time at university. Have you been involved in student clubs, in research groups, in community projects? Have you followed technological developments? That is what will make you stand out from all the other "also graduated" students when it comes to applying for graduate studies or landing that dream job.
The "secret" of success?
Is no secret... do what interests you, do your best and take pride in it.
Interest breeds motivation allowing you to overcome difficulties and so gain
confidence and be successful. It's that simple!