Module 2 - Game Skills 2
Assignment 2.07

Objectives: After studying the Module 2 Game Skills 2, you will be able to:

  1. Use assignment statements to store numeric and alphanumeric data in variables.
  2. Create a flowchart to represent an algorithm.
  3. Use a five step process to develop a program.
  4. Assign multiple "sets" of data to unique variables.


YOUR LESSON

Introduction

You have used variables in several programs now with assignment statements. The use of variables is one of the things that makes computer programming so powerful. Numeric and alphanumeric data can be stored in the computer's memory, processed in a wide variety of ways, and then displayed on a computer screen or printed as a document.

The simple programs you have written up to this point have generally only dealt with one "set" of data. For example, calculating the wages for one employee or determining the area of one triangle. Part of the power of the computer is that it can process large amounts of data - such as the entire payroll of all employees of any business. It is all done by storing data in the computer's memory in variables, processing the data, and displaying it.

Adding More Data to Programs

flow chart displaying the code

In an earlier program, you calculated the wages for Mr. Blue and Mrs. Greene separately. The following program shows how to include the information for both employees in the same program. The corresponding flowchart is shown to the right.

REMWage Calculator II - The Sequel
REM Programmer: J. Presper Eckert
REM 01/02/01
'
COLOR 15,1
CLS
REM INPUT
LET name1$ = "Mr. Blue"
LET hours1 = 23.0
LET rate1 = 5.25
LET name2$ = "Mrs. Greene"
LET hours2 = 34.25
LET rate2 = 6.00
'
REM PROCESSING
LET wage1 = hours1 * rate1
LET wage2 = hours2 * rate2
'
REM OUTPUT
PRINT "Wage Calculation Display"
PRINT
PRINT "The wage for "; name1$ ;" is $"; wage1 ;"."
PRINT "The wage for "; name2$ ;" is $"; wage2 ;"."
'
END

Reload your wage.bas program and save it as wage2.bas. Now modify it as shown above.

Notice that there are now two sets of variables: name1$, wage1, hours1, rate1 and name2$, wage2, hours2, rate2. Just by adding the "1" and the "2" to the variable names, we have created two sets of unique variables to hold the alphanumeric and numeric data about Mr. Blue and Mrs. Greene. The variable names used have meaning and are related to the set of data. For instance instead of using BlueHours and GreenHours, the variables hours1 and hours2 were used.

Be sure to save your program. Now try to run it. Can you predict what the output will be? Study the flowchart and the program until you clearly understand how the new output was obtained. Once you understand the program, try adding a third or fourth employee. As long as you keep the numbers in the variable names unique, you could theoretically add as many employees as you want!

Extra Practice with Naming Variables

Numeric and string variables will be instrumental to your programs as you work through the course. Choosing meaningful variable names and variables of the correct type are important. Tests your knowledge of numeric and string variables.

Practice Icon

A text version is also available.

YOUR ASSIGNMENT

Time to write your own program using "sets" of numeric and string variables. Be sure to read the directions carefully and follow the 5 Step Design process for writing programs.

Program Definition Write a program that calculates the perimeter and area of two different rectangles. The first rectangle is a football field which has a length of 360 feet (including the end zone) and a width of 160 feet. The second rectangle is a basketball court which has a length of 94 feet and a width of 50 feet..

Special Considerations:

Be sure to use numeric and string variables. The strings "football" and "basketball" must be assigned to string variables in the INPUT Section.

Since both "football" and "basketball" are sports, does that give you a clue what their Meaningful variable names should be?

The formula for the perimeter of a rectangle is 2 * length + 2 * width.
The formula for the area of a rectangle is length * width.

Output notes: The numeric values are not shown in our sample output below. In your output statements, be sure to use the string and numeric variables for the values you want to display. Do not include the name of the sport in your literals. The name of sports should be inserted using the string variable names. The sample PRINT statements in the above lesson show you how.

Example of output:

The length (feet) of a football field is:
The width (feet) of a football field is:
The perimeter (feet) of a football field is:
The area (square feet) of a football field is:

The length (feet) of a basketball court is:
The width (feet) of a basketball court is:
The perimeter (feet) of a basketball court is:
The area (square feet) of a basketball court is:

Notice there is a blank line of space between the two sets. You may want to review how that was done in the Lesson.

Develop the Algorithm You are required to develop an algorithm for this assignment. You may choose to write pseudocode or draw a flowchart. (It is preferred that you write pseudocode.) Use a text editor (such as NotePad) to write your pseudocode. Save the algorithm as BOXES.xxx. (The extension will vary depending on the application used.)

Coding the Program Now that your algorithm is written, it is time to code the program in QBASIC. Be sure to use all of the "good programming practices". Save the file as BOXES.BAS.

Test and Debug Run your program. Did it work? If not, debug the program. Did the output look similar to the output above? It should. Of course your output will display the number values. Are the calculations correct? Double check by doing the math yourself. Can you read the output statements? Do they make sense and is everything spelled correctly? Do you need to add any punctuation? Be sure to save your program after you've made changes.

Documentation Now that your program is working properly, go back and make sure the documentation is complete and meaningful. Is your heading complete? Did you include the name of the program, your full name, and the date? Did you divide the program into sections and label them? Are there any additional notes you feel will be beneficial to future programmers who may need to read your code and make updates?

Check Your Understanding Use "good programming practices." This includes starting the program with a title, your name, and the date. Break up the program into sections that are clearly identified. Use meaningful variable names. It is also helpful to use color to make the output more attractive. Use the example above as your guide when writing this program. Use assignment statements to do the calculations for perimeter and area. This program should include numeric and string variables. Did you successfully use both in the PRINT statements?

Submission Instructions Make sure both files have been saved with the file name BOXES. The pseudocode algorithm will have an extension of .TXT and the program file will have a .BAS extension.

Click the ASSESSMENTS (or GRADEBOOK) tab. Click Assessment 2.07.

Open your pseudocode file and copy the text. Go back to the Assessment. Click in the STUDENT COMMENT section and paste the text.

Now upload the .BAS file to attach it to the Assessment. In the OPTIONAL FILE UPLOAD section, click CHOOSE and pick the BOXES.BAS file

At the bottom of the screen, check the box "Submit for Grading" then click SUBMIT. When the assignment is submitted, your instructor will view the pseudocode and download the program file.

Grading Rubric This assignment is worth 10 points and will be graded according to the following rubric.

Required statements used: 2 out of 2 points
Algorithm used: 2 out of 2 points
Documentation included: 2 out of 2 points
Program ran properly: 2 out of 2 points
Proper output: 2 out of 2 points

If you are dissatisfied with your grade, you may redo and resubmit the assignment.

A QBasic Review

Before moving on to the next assignment, be sure that you can do the following:

  1. Use assignment statements to store numeric and alphanumeric data in variables.
  2. Create a flowchart OR Pseudocode to represent an algorithm.
  3. Use a five step process to develop a program.
  4. Assign multiple "sets" of data to unique variables.

At this point, you should be comfortable with assigning numeric and alphanumeric data to numeric and string variables, using variables to do calculations, and printing out both numeric and alphanumeric information.


Submit the program and the algorithm to Assignment 2.07 Game Skill 2 in the Dropbox area.
After the assignment has been graded, please move on to the next assignment.


previousnext