(Top-Down
Approach, Strings, Constants, Variables, Expressions)
Assume you’d like to paint
your room at home. Your parents say
that they’re willing to pay for the paint as long as you don’t waste too
much. So, you visit a paint store to ask
how much paint you’ll need.
The clerk says that it
depends on how much painting you’ll be doing.
One gallon of paint costs
$19.99 and covers about 500 square feet of surface. A quart of paint costs
$9.99 and covers about 200 square feet of surface.
Assignment: Create program that will allow the user to
enter the dimensions of a room. The
program will compute the cost to paint the room based on the information
above. The program should show two
costs; one that includes the ceiling and one that includes only four walls.
Specifics:
Have an intro screen that
shows your name, program name, and class information. This screen should show for a couple of seconds and clear for the
second screen.
Have a purpose/directions
screen that explains the purpose of the program and gives the user directions
on how to use the program
The third screen should be
a data entry screen where the user enters room dimensions.
The final screen should
report the output. Give as much detail
as you can in regard to figures such as dimensions, square footage and such.
Instead of a linear
approach, create this as a Top-Down program.
Remember, in Top-Down Programming, we divide a program in to distinct
tasks or steps and use the MAIN program to control these steps.
In the paint program, the tasks
are essentially as follows:
ü
Introduction Screen –
Shows program title, your name, and class information.
ü
Directions &
Purpose – Second screen that tells the user what the program is supposed to do
and what the user needs to do.
ü
Enter Measurements –
User supplies dimensions of the room.
ü Calculations & Processing– Program uses the information supplied by the user to calculate how much paint is needed and what costs will be.
ü
Report Information –
Show all information in an attractive format.
The original fast food
program appears below. Modify the program to
Original Problem:
A fast food restaurant
charges $1.49 for burgers, $0.89 for fries, and 0.99 for sodas.
Write a program that allows
an employee to enter an order (the number of burgers, fries, and sodas), and
then display a total, the tax (at 6%), and the final cost. The program should look similar to:
Enter the number of
burgers: 3
Enter the number of
fries: 2
Enter the number of sodas:
5
The total before tax
is: $11.20
The tax is $0.67
The grand total is $11.87.
Enter the amount
tendered: 20.00
The change is: $8.13
Overview: This
program will calculate the transportation cost of a field trip based on the
number of students attending and the distance of the field trip. You understand the following facts about
field trips.
Facts:
You can fit 25 students on
a bus. All extra students have to be
taken in cars, which can fit up to 4 students.
The school would rather send students in a bus than a car, so they fill
the busses first. However, busses can
only be used if they are full.
Busses use diesel, but cars
use regular unleaded gas. Diesel costs
$2.19 per gallon right now, while regular unleaded gas costs $2.09.
Busses average about 20
miles per gallon and cars average about 30.
Specifics:
First, you should have an
intro subroutine that greets the user and explains the purpose of the program.
Your program should gather
some information from the user. This
should be done in it’s own subroutine.
You’ll need the following information:
Your program should have a
subroutine that calculates the number of busses and cars needed. These should be whole numbers. (You can’t take 3 busses and 2.6 cars on a
trip). Always take one extra car for
the teacher and any extra students that don’t fit into the other busses or
cars.
Example: You have 86 students. You’ll take 3 busses, which account for 75
kids. Then, you’d have 11 leftover
students. This would create a need for
2 full cars (because 4 goes into 11 twice), but you need to add 1 more car for
the teacher and extra students.
Your program should have a
subroutine that calculates gas costs associated with the trip. You should be able to do this if you know
how many busses and cars you’re taking along with gas prices and mile per
gallon figures.
Finally, your program
should have a subroutine that reports the costs on the screen. This report should be attractive and should
show the following information:
q Name of Field Trip
q Teachers Name
q Busses Needed
q Cars Needed
q Total Cost of Trip
Your program should use
constants. These are numbers that do
not change during the program, but may change over the course of time. Constants should be declared at the top of
the main program, underneath your REM statements.
Structure of MAIN program:
REM
REM
REM
CONSTANT(s) DECLARATIONS
GOSUB intro
GOSUB gather.info
GOSUB calculate.vehicles
GOSUB calculate.costs
GOSUB report
END
Overview: You run a
company that employs salespeople to travel around the country, selling
guitars. Each salesperson travels to
four geographic regions: North, South,
East, and West. You’d like to create a
program that reports the percentage of sales that come from each region.
Specifics:
The program should have an
intro subroutine that greets the user and tells the purpose of the
program.
The main program should ask
the salesperson’s name (string variable) and how many guitars they sold in each
region.
After the user has entered these 5 pieces of information, the screen should clear and a new screen will come up showing the sales report.
Guitar Sales Program
Welcome
to the Guitar Sales Program. This
program creates a report to show the percentage of guitar sales in each region
for a salesperson.
Enter
the salesperson’s name? Matt
Offenbecker
Guitar
Sales in the North? 500
Guitar
Sales in the South? 1200
Guitar
Sales in the East? 800
Guitar
Sales in the West? 2500
(Clears
Screen)
Guitar Sales Report
Salesperson: Matt Offenbecker
Actual
Sales Figures:
North 500
South 1200
East 800
West 2500
Total
Sales 5000
Percent
of Sales by Region:
North 10%
South 24%
East 16%
West 50%
Thank
You.
Specifics:
Make sure your
program has an END between the end of the main program and the introduction
subroutine.
Use REM
statements to document your name, course info, and program name.
Use descriptive
variable names.
Save the program
as GUITAR when complete.
Math Notes:
The percentage
sold in each region is found by dividing the number sold in that region by the
total sold. For example:
1200 guitars sold
in the North
6000 guitars sold
total.
1200 / 6000 = .2 (Percentage as a decimal is .2)
Multiple
percentage as decimal (.2) by 100 to show percent.
.2 * 100 = 20%