Name _________________________

CSC001- Worksheet 4: Good Programming

ublkline620.GIF (83 bytes)

D. Joseph
Fall 1998

Due: Monday, November 30
Total Points: 10

 

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

  1. Why should you use remark statements in your programs?




  2. Do remark statements have any effect on the execution speed of your program?




Labeling Output

  1. Why should you label your output?





  2. What is the difference between a PRINT statement and an LPRINT statement?






Variable Names

  1. 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.

  1. avg   _________________________________________________________

  2. Week Day _________________________________________________________

  3. Name$ _________________________________________________________


Examine the Code

  1. 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

 

 

  1. 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


 

 

ublkline620.GIF (83 bytes)

Return to:  CSUS | Computer Science

November 17, 1998
Comments to:  josephd@csus.edu