2. Gas Pump Program
Problem Statement
The required program will calculate charges incurred when a motorist uses an automated gas
pump. The system will need to take input from the user as to what type of gas they want. The have
options of regular and premium; charges per gallon should be calculated based on the user‟s selection.
The user should also be prompted for „Gas and go‟ or „Full Service‟. If the user selects „Full Service‟ or
„Gas and Go‟, a service charge is to be added for the attendant to pump the gas for the user. The user
must also have the option to pump the gas themselves without requesting additional service.
Top Level Algorithm
Input Data Module Processing Module Output Result
Module
Prompt User For:
SelectedGasType
SelectedServiceType
GasTypePremium
GasTypeRegularServiceChargeGasNGo
ServiceChargeFull
1. If
(SelectedGasType=”Premium”
and SelectedServiceType=”Full”)
Than
Set PurchaseAmt=GasTypePremium
+ ServiceChargeFull
Else If
(SelectedGasType=”Premium” and
SelectedServiceType=”GasNGo”)
Than
PurchaseAmt=GasTypePremium +
ServiceChargeGasNGo
Else If (SelectedGasType=”Regular”
and SelectedServiceType=”Full”)
Than
PurchaseAmt=GasTypeRegular +
ServiceChargeFull
Else If (SelectedGasType=”Regular”
and
SelectedServiceType=”GasNGo”)
Than
PurchaseAmt=GasTypeRegular +
ServiceChargeGasNGo
Else If
(SelectedGasType=”Premium” and
Write out:
GallonsPumped
PurchaseAmt
TotalPrice
3. SelectedServiceType=”None”) Than
PurchaseAmt=GasTypePremium
Else If
(SelectedGasType=”Regular” and
SelectedServiceType=”None”) Than
PurchaseAmt = GasTypeRegular
Else
Print “User input error. Please see
attendant”
2. Set SubTotal=PurchaseAmt *
StateSalesTax
3. Set TotalPrice=SubTotal +
(FedGasTax * PurchaseAmt)
Module Functions and Internal Structure
Service Selection
The main screen if not being used displays “Welcome to your neighborhood gas station!” The
system displays “Please select from the following: 1 – Gas and Go, 2 – Full Service, 3 – Self Service.”
If the user selects „gas and go‟ or „full service‟, the program will alert the station attendant and the pump
display reads “Please wait for station attendant” and the attendant will then finish fueling and making
selections.
Gas Selection
For service from attendant or if the user selects self-service, the display will read “Please select
gas type. 1-Premium or 2-Regular”. The program will store the user selection for use in later
calculations.
Pump Processing
The program will now display “Please remove nozzle and begin fueling.” Once calculations are
complete, the program adds the selected service charges for Full service or Gas and Go. Sales tax is
then calculated and added to this total. Finally, the system adds the untaxed federal gas tax based on the
4. type and amount of gasoline. Total is then calculated and displayed on the screen, along with “Have a
nice day!”
Program Pseudocode
1 //This program is designed to walk a customer through the purchase of service type and gasoline type
2 //then allowing the program to calculate the total based on those selections along with the federal
3 //and state taxes added in. (1.)
4 //Begin Main_Module (2.)
5 //This module declares all variables, sets prices, and calls all sub-modules.
6 Declare perGallonPriceRegular as integer
7 Declare perGallonPricePremium as integer
8 Declare serviceChargeFull as integer
9 Declare serviceChargeGasNGo as integer
10 Declare fedGasTax as integer
11 Declare salesTax as integer
12 Declare gallonsPumped as integer
13 Declare userSelection as string
14 Declare selectedServiceType as string
15 Declare selectedFuelType as string
16 Declare transactionTotal as string
17 Declare salesTaxSubtotal as string
18 Declare gasSubTotal as string
19 Declare selectedServiceType
20 Set perGallonPriceRegular=3.00
21 Set perGallonPricePremium=3.20
22 Set serviceChargeFull=2.00
23 Set serviceChargeGasNGo=1.00
24 Set fedGasTax=.10
25 Set salesTax=.05
26 Call Welcome_Message_Module
27 Call Service_Selection_Module
28 Call Fuel_Selection_Module
29 Call Calculations_Module
30 Begin Welcome_Message_Module (3.)
31 //Displays a short greeting for the customer at the chosen pump.
32 Write "Welcome to your neighborhood gas station."
33 End Welcome_Message_Module
34 Begin Service_Selection_Module (4.)
35 Write "Please select level of service."
36 Write "1-Full service, 2-Gas-n-Go, or 3-Self-service."
37 Input userSelection
38 If userSelection=1 Then
39 selectedServiceType="Full Service"
40 Write "The station attendant has been notified of your service request,
41 please stand by."
42 Else If userSelection=2 Then
5. 43 selectedServiceType="Gas N' Go"
44 Write "The station attendant has been notified of your service request, please
45 stand by."
46 Else
47 selectedServiceType="Self Service"
48 End If
49 End Service_Selection_Module
50 Begin Fuel_Selection_Module (5.)
51 Write "Please select gas type: 1-Premium or 2-Regular"
52 Input selectedGasType
53 If selectedGasType=1 Then
54 Set dispGasType="Premium"
55 Set perGallonPrice=perGallonPricePremium
56 Else
57 Set dispGasType="Regular" And
58 Set perGallonPrice=perGallonPriceRegular
59 End If
60 Write "Please remove the pump and begin fueling."
61 Set gallonsPumped = 10
62 Write “Service Complete.”
63 End Fuel_Selection_Module
64 Begin Calculations_Module (6.)
65 Write "Your charges are as follows."
66 Set gasSubTotal=gallonsPumped * perGallonPrice //Calculate gas subtotal.
67 Write "Total charged for pumped gas:$" & gasSubTotal
68 Set fedTaxSubtotal=gallonsPumped * fedGasTax //Calculate gas tax before sales tax is applied.
69 Write "Federal gas tax:$" & fedTaxSubtotal
70 //Begin calculating transition total by starting with the service charge.
71 If selectedServiceType="Full Service" Then
72 Write selectedServiceType&":$"&serviceChargeFull
73 Set transactionTotal=serviceChargeFull
74 Else
75 Write selectedServiceType&":$"&serviceChargeGasNGo
76 Set transactionTotal=serviceChargeGasNGo
77 End If
78 Set transactionTotal=transactionTotal+gasSubTotal //Add gas subtotal to service charge. (7.)
79 Set salesTaxSubtotal = transactionTotal * salesTax //Calculate sales tax for gas and service.
80 Write "Sales Tax: $" & salesTaxSubtotal
81 Set transactionTotal=transactionTotal+salesTaxSubtotal+fedTaxSubtotal
82 //Add sales tax and fed tax to running total.
83 Write "Total Charges:$" &transactionTotal
84 Write "Have a nice day!"
6. Documentation of Tasks and Subtasks
Sequential numbers in the pseudo-code will correspond to this list.
1. Statement to give a quick overview of what the program sets out to accomplish.
2. This is the beginning of the main module where we declare our integers, floats, and strings. This puts in our
“Write” statements, “Sets” our figures with pricing and taxes to be added, and “Calls” the modules.
3. This quick message module will display at the pump when a customer initiates a fuel purchase.
4. This is the service selection module. It starts out with prompting the user on their service selection for either
full, gas n‟ go or self-service. Next, an If-Then-Else statement will walk the program through those selections to
make sure they are stored for the calculations module.
5. The user now chooses between premium and regular. Another If-Then-Else statement will walk the program
through the choices again and store them for later use in the calculations module.
6. The beginning of the calculations module will start with showing the customer their charges. The inputs the
program will take into consideration are Premium=$3.20/gal., Regular=$3.00/gal., Full service charge=$2.00, Gas
n‟ Go charge=$1.00, Federal gas tax= .10 cents/gal., and State tax charge= 5% or .05 for the purposes of the
pseudocode.
7. All the calculations are processed within this module to give the user their final value base on their previous
choices through a series of If-Then-Else statements and Set statements that involve the mathematical portion.
9. 9
References
Bohl, M., & Ryann, M. (2008). Tools for structured and object-oriented design: An introduction to programming
logic (7th ed.). Upper Saddle River, NJ: Pearson Prentice Hall
Crews, T., & Murphy, C. (2009). A guide to working with Visual Logic. Boston, MA: Cengage Learning.
Drake, E., & Venit, S. (2011). Prelude to programming: Concepts and design (5th ed.). Boston, MA: Addison-
Wesley.
Gaddis, T. (2013). Starting out with programming logic and design (3rd ed.). Boston, MA: Addison-Wesley.