Homework advice #2

Hello, I was reading how to properly use constants better by the management team at my school.

Though, I didn't understand some of their wording, so I was hoping someone could explain some parts. I have very poor processing issues, so sometimes words just don't sit well with me. Thank you!

1) What are ifs and loops and can you give an example of them serving as blocks? How are blocks methods (what do they mean by this)?

2) Why are unamed numeric constants wrong and what's an example of an unamed string constant?

3) "The use of a CONSTANT can save a lot of work in the future,...
For example, if PI is used 'n' places in the code and the user wanted to change it to 6 places of precision, with the CONSTANT, the change will be made in only one place rather than have to find and change 'n' places (and possibly miss one or more)."

Would someone word this differently?

4) "class ClassName // by convention, class names always start with a CAPITAL letter"

What does the "class" stand for here? Also, since class names are always capitalized, something like "biology" would be wrong? It would need to be Biology?

Proper use of CONSTANTS is part of the grading criteria for code in this class. Here are some suggestions additional to the reading:


main()
{
// CONSTANTS (and variables) are only visible to the block they are defined in.

// A code block is between a pair of curlys - {...}.

// In this case, the block is a method. if's and loop's are blocks too.

const int MIN_INT = 5;

const double RATIO = 9.0/5.0;

const string COMPARE = "rock";


// Unnamed numeric (and String) constants include any values like the example values above that are found in the body of the code. For example:

circumference = 3.14 * diameter;

// It will be better to use the CONSTANT

circumference = PI * diameter;

// The use of a CONSTANT can save a lot of work in the future,...

// For example, if PI is used 'n' places in the code and the user wanted to change it to 6 places of precision, with the CONSTANT, the change will be made in only one place rather than have to find and change 'n' places (and possibly miss one or more).

// CONSTANTS provide an opportunity to add clarity. For example, if there is an unnamed constant in the code - 5. 5 what? What are the units? Why is it 5? Can it be anything else? Is this 5 the same as the other 5 found elsewhere in the code? If 5 was replaced with MINIMUM_ACCEPTABLE_FUEL_MILEAGE or MAX_SPACECRAFT_PSI, certainly, things will be much clearer. In addition, comments on the CONSTANT declaration may help us further understand that the fuel mileage is for motorhome RVs and the max psi is for pure oxygen atmospheres.

} // end main()

class ClassName // by convention, class names always start with a CAPITAL letter
{
private:

const int MAX_INT = 24; // used for loop limits, ranges or computing

const double PI = 3.14; // excellent for math

const string QUIT = "q"; // sentinal value for loops

} // end class
Sorry, but that didn't help too much really. Thank you for responding!
closed account (48T7M4Gy)
It looks like your homework has 4 questions. If so have a go at q1, show us what you have come up with for an answer and see if anybody wants to comment or help. Perhaps pick key words out and then you'll see that keskiverto's hints are eminently suitable.
I don't know have anything. This is just grading criteria notes. : )
closed account (48T7M4Gy)
So which line/sentence/paragraph doesn't make sense? Surely it's not totally incomprehensible even though it does read as a somewhat disjointed set of notes. What did Ray explain in the lecture?
Oh, did my questions not make sense? I told everyone, but perhaps you didn't understand.

This is online, so he doesn't actually do lectures. He just leaves notes. : )
closed account (48T7M4Gy)
did my questions not make sense?

Not really but I'm beginning to see. :)

Perhaps it goes like this?

Q. What are ifs, loops and blocks and methods?
A. http://www.cplusplus.com/doc/tutorial/control/
// A code block is between a pair of curlys - {...}.
//In this case, the block is a method. if's and loop's are blocks too.

Methods http://www.cplusplus.com/forum/beginner/20406/

etc
Topic archived. No new replies allowed.