Skip to content
Physics and Astronomy
Home Our Teaching Resources C programming PHY3134 ex2.html
Back to top

Computational Physics Week 2: Course work

Use of Comments

[30%] Do this part in pairs, hand in one piece of work per pair.

First ask yourselves:

  1. Imagine you are writing a reasonably sized program. What sorts of comments would you find useful to help you complete (and debug!) the program as quickly as possible? What sorts of comments would actually make your job harder?

    Other ways to look at this: what sorts of mistakes are you likely to make that could be reduced by comments? How could comments help you reduce the number of things you have to hold in your head? How could poor comments slow you down? Are there situations where there are better solutions than writing comments? Where is the best place to have comments?

  2. How is the above changed if you know you may need to come back to your program in a year's time?

Now write

A brief answer (bullet points, etc. are fine) to the question: how are comments going to help you program, not hinder you?

Remember: if you use sources, reference them.

Quadratic equations

[70%] Do this on your own.

Define a suitable structure to hold the coefficients of a quadratic equation and write a simple program to read in theses values and to call a function to calculate the solutions(s) and print them out. Allow for all possible cases, including where it's not really a quadratic at all.

                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Privacy & cookies Share
Back to top