ALL grades can benefit from these basic rules
NOTE: These are my own rules that I found help learners.
Always start your variable name with the first letter of its data type. sName :String; cInitial :char; iLearners :integer; rAve :real; bFound :boolean; This will prevent learners from using reserved words as variable names. If you follow this rule many of the other rules of variable naming become irrelevant. The learners need to know the rules of variable names for theory.
Keep your variable names descriptive and short to save time typing.
Numbers that start with a zero needs to be declared as strings. These are numbers in which we are not interested in the decimal value of the number. Examples:
Cell numbers
ID numbers
Barcode numbers
ISBN numbers
CompanyID
Employee numbers etc.
Always match the data type of input with the screenshots. This is especially important when you have to use the variable in a structure, function or procedure that needs an ordinal data type like IN, CASE, FOR, INC and DEC. There are also marks allocated in final papers for using the correct function to convert the number to real or integer for input and output.
When displaying real output ALWAYS use FloatToStrF(rNum, ffFixed / ffCurrency,10,2).
In the final paper there are often marks allocated for the formatting of the number and to avoid losing this mark you always need to use FloatToStrF.
You can also use FloatToStrF with integer numbers as arguments, which come in handy if you have to display the number as a currency.
Try to keep Input, Processing and Output separate. Do not use your Edit box in processing like this:
iAns := StrToInt(edtNum.Text)*2;
Do not do processing in the label or RichEdit like this:
lblOut.Caption := 'Total '+FloatToStrF(iNum*rPrice,ffCurrency,10,2);
Coding this way makes it very difficult to mark as there might be marks allocated for input, processing and output and now all is done in the same line of code.
The following always has real output:
Divide (/)
sqrt()
Power() Reason: if power(5,-2) is calculated it will produce real even though the input is integer numbers.
MOD and DIV both need integers on both sides. The are operators and will be used on the right of the := like a + or a * between integer numbers. They can also be used in conditions of If-statements and loops.
Ordinal values (integer and char) necessary to use the following:
CASE of
for loop
inc
dec
If you declared a global variable you may not re-declare it as a local variable. If you do the global variable will lose its value.
Always store the output of a function in a variable with the data type that matches the function's result. If you are using one of the rounding functions (round, floor, ceil etc.) the answer might be needed as an integer to use in a structure (CASE, IN and FOR) or operator (MOD and DIV) that needs an integer data type.
Constants will assume the data type according to the value that you assign to it. You do not get extra marks for declaring a constant. Constants are usually given in a paper and mark is allocated to use the constant.
Price = 12.35; //Price will be used as a real variable
Total = 100; //Total will be used as an integer
Constants cannot receive new values. It can be used anywhere in your program but never on the left of the :=. Therefor this is not allowed Price := rNew;
#9 is used to create a tab space.
#10 or #13 is used for an enter in a label or ShowMessage. Do NOT use #10 or #13 in a RichEdit - it becomes a really long string to find errors.
Indent your code between every begin / end / structure like If, case and loops to make it easier to find errors.
Place a short comment next to each end to indicate what it belongs to. This helps learners to find logical errors. For example: end;//if
Use a for-loop when you know how many times something needs to repeat. Even it is through a function like length(sName).
Conditional loops are used when you are unsure how many times it needs to repeat.
While loops when you are unsure if it should repeat at all.
Repeat loops when you have to loop at least once. The question usually says repeatedly ask the user for input until it meets a certain condition.
Up to know there have not been specific marks allocated in final examinations to select the correct conditional loop, but by selecting the correct loop you will have a simpler solution and we never know when a mark might be allocated to choose the correct one.
If you need to get input from the user using a loop you will ALWAYS use an Input Box since the user cannot access an Edit Box or other objects while the loop executes.