Programming Fundamentals Assignment 4
Planning Document
You will have 5 parts to your planning document that must be completed:
Actions
Data Items
Prototype/Mock/Sample Output
Test Data
Process Design (Pseudocode/Flowchart)
Assignment Goal:
In this chapter you learned about loops. Loops allow processing on large sets of data.
Problem Statement:
Write a program called CalculateInvoice that allows a user to enter multiple invoice
items for multiple customers and calculates a total invoice amount. For each
customer, enter a customer number and customer name. Then, for each customer
allow the user to enter any number of items. Data to be entered for each item is the
description, quantity, and price. For each item calculate the extended amount by
multiplying the quantity times the price. Add each extended amount to a subtotal for
the customer. If the subtotal is over $500, the customer gets a 5% discount. After
the discount has been calculated, calculate a sales tax of 8.25%. Display the
customer number and name on the first line, followed by the subtotal, the amount of
discount, amount of sales tax, and total invoice amount. You are not to list the
individual items.
Hint: You will need two loops for this assignment, an outer loop for multiple
customers and an inner loop for multiple items. Because you have multiple
customers, you need to clear (set to zero) all fields used to store customer level
totals) in order to prevent values from carrying over to the next customer.
For your test data, you should have at least two customers. Each customer should
have at least two items. One of the customers should have an invoice subtotal over
$500 to test your discount.
Deliverables (what you are to submit):
Planning Document
List of actions your program is to do.
List of data items.
A prototype/mock screen showing the output of your program.
A set of test data with expected results.
Your solution algorithm using pseudocode and a flowchart.
Name: ____Aaron Villalobos____________________________________
Assignment: Chapter 4
Program
Actions (2 points):
Start Program
Ask for amount of customers
Set that number as outer loop
{
Ask for customer number
Store customer number
Ask for customer name
Store customer name
Ask how many items to be entered
Store amount as inner loop number
{ Enter description of item.
Enter quantity of item.
Enter price of item.
Price * quantity = itemsum
subtotal += itemsum}
Loop for item number entered before.
if subtotal > 500 then subtotal * .05 = discount
subtotal - discount = total
total * 0.825 = tax
total + tax = taxtotal
Print customer number and name, endl.
print subtotal, discount, tax, taxtotal
Set all variables to 0.
Add 1 to customer amount loop
} loop based on how many customers input at the beginning.
End if loop = customers
Data Items (3 points):
objects you will need >
< This is a list of fields (variables, constants, and
Data Item
subtotal
discount
Source (1)
calculated
calculated
Type (2)
double
double
Identifier
subTotal
discount
total
calculated
double
total
tax
calculated
double
tax
taxTotal
calculated
double
taxTotal
loopCustomers
input
double
loopCustomers
loopItems
input
double
loopItems
customerName
input
string
customerName
Notes
customerID
input
double
customerID
itemDescription
input
string
itemDescription
itemNumber
input
double
itemNumber
itemPrice
input
double
itemPrice
1. Source: calculated, input, constant
2. Type: string, char, byte, short, integer, long, double, float, etc.
Sample Output (5 Points):
Please enter amount of customers to be processed : 1
Please enter your customer ID: 1234
Please enter customer name: John Smith
Please enter the amount of items to be processed: 2
Enter description of item (loop number): Chips
Enter quantity of item (loop number): 3
Enter price of item(loop number): $ 2 // The dollar sign is part of the program
output, not the input
//(This loops depending on amount of
items and customers)
Customer 1234
John Smith
Subtotal: 6.00 Discount: 0 Tax: .49
Test Data (5 points):
Identifier
itemPrice
itemNumber
subtotal
tax
taxTotal
Value 1
5.00
10
50.00
4.13
54.13
Total: 6.49
< How will you prove your program works >
Value 2
40.00
2
80.00
6.60
86.60
Value 3
1.50
20
30.00
2.48
32.48
Value 4
15.00
17
255.00
21.04
276.04
Note: You made more or fewer test cases depending on your application.
Process Design (10 points):
flowchart) >
< What is the solution (pseudocode, IPO diagram,
NOTE: Please see the syntax summary document for guidelines.
You will define your process using both psuedocode and a flowchart.
class CalculateInvoice
void main()
double subtotal;
double discount;
double total;
double tax;
double taxTotal;
double loopCustomers;
double customerCheck;
double loopItems;
string customerName;
double customerID;
string itemDescription;
double itemNumber;
double itemPrice;
double itemSum;
double itemCheck = 0;
display Please enter amount of customers to be processed :
read loopCustomers
do
display Please enter your customer ID:
read customerID
display Please enter customer name:
read customerName
display Please enter the amount of items to be processed:
read loopItems
do
display Enter description of item (loop number):
read itemDescription
display Enter quantity of item (loop number):
read itemNumber
display Enter price of item(loop number): $
read itemPrice
itemPrice * itemNumber = itemSum
subtotal += itemSum
itemCheck += 1
itemPrice = 0
itemNumber = 0
itemSum = 0
while itemCheck < loopItems
if subtotal > 500 {
discount = subtotal * .05 }
else discount = 0
total = subtotal - discount
tax = total * 0.825
taxTotal = total + tax
display customer number, display customer name; endl;
display subtotal, discount, tax, taxtotal
customerID = 0
customerName = null
customerCheck += 1
while customerCheck < loopCustomers
return
end class
AND
Flowchart: (Graphic representation of a process)