When writing a computer program there are
certain steps that a programmer should followin to make a program easier to read. What
follows are questions regarding good programming skills. Remember to use these in your
programs!
Remark Statements
- Why should you use remark statements in your
programs?
- Do remark statements have any effect on the execution speed
of your program?
Labeling Output
- Why should you label your output?
- What is the difference between a PRINT statement and an
LPRINT statement?
Variable Names
- Why should you use meaningful variable names in
programs?
Are the following variable names acceptable? If not,
explain why and rewrite them so that they are valid.
- avg
_________________________________________________________
- Week Day
_________________________________________________________
- Name$
_________________________________________________________
Examine the Code
- What makes the following program well written?
cls
Rem This is a program to calculate and print the average of 3 numbers
Rem using input from the user.
Rem *******************************************************************
Rem Programmed by Patty Madueno
Rem November 17, 1998
Rem *******************************************************************
Rem Variables Used in the Program
Rem Number1, Number 2 and Number3: Used to store three numbers
Rem Sum: Used to store the sum of hte three numbers
Rem Average: Used to store the Average of the three numbers
Rem *******************************************************************
Rem Start of Program
Rem *** Get input from user ***
Print "Please provide data, and press return after each response."
Input "Please enter number one "; Number1
Input "Please enter number two "; Number2
Input "Please enter number three "; Number3
Print "Debug output to check values"; Number1,Number2,Number3
Rem *** Calculate Answers ***
Sum = Number1 + Number2 + Number3
Average = Sum/3
Rem *** Print Report ***
Print "The numbers used were "; Number1; Number2; Number3
Print "The sum of the numbers is "; Sum
Print "The average of the numbers is "; Average
- What makes the follow program poorly written?
Would this program work?
Does this program accomplish the same thing as the "well written" program?
*****************************************************************************
Example of a poorly written program
_________________________________________________
Input n,sum,average
N1 = (n+sum+average)/3
print n,sum,average,N1
|