DougT
06-28-2006, 02:01 AM
The purpose of this Tutorial is to introduce the art of Problem Analysis which is simply the process that you use to work out the steps (logic) required to solve a programming problem.
It’s a fact that many people starting off in programming are given a task and the first cry is “Help - I don’t know where to start”. Hopefully, if you’re one of those people, then by the time you’ve read this you will know the answer.
There are many different ways of analysing problems and I’ll be going through the method I use, it’s not a formal method that you could read in a textbook but one that I have used over many years and it works for me. (It’s very, very loosely based on Jackson)
The process is best described using an example, for this tutorial I’ll take the problem as:
Write a Billing System for a Mobile Telephone company that processes information from a database on a monthly basis and calculates the total cost per Customer on the following basis:
Monthly Rental is 25.00. The call times are measured by hundredths of Seconds. Calls are charged by the Second. The first 100 minutes used are free (except for International calls which are charged at 0.50 per minute). After the customer has used 100 minutes, calls are charged at a rate of 0.15 per minute. The first 50 Text Messages are free and after the 50 have been sent they cost 0.10 per message.
The output required is the Period, Customer Details (Name, Address, Account Number, Mobile Number), Total number of International call minutes used and cost, Total number of other call minutes and cost, Total number of text messages sent and cost, total cost, VAT (Value Added Tax) and amount to pay.
The Database contains the following validated data in a series of Tables
Table Customer:
Customer Name
Customer Address
Customer Mobile Number
Customer Account Number
Table Calls:
Customer Account Number
Date and Time Call started
Date and Time Call ended
Type of Call (“I” for International, “N” for In Country)
Table Messages:
Customer Account Number
Date and Time Message Sent
Where to start?
It may seem a bit silly, but I start with the output required. What does the program have to produce? In our example it’s fairly straightforward,
The Period of the Charges
Some information about the Customer
The Total number of Call Minutes used and cost (International and Others)
The Total number of Text messages sent and cost
The Total cost
The VAT
The Grand Total the Customer has to pay
In order to create the output, we have to have some input, so the next thing to do is to look at that. The first thing to notice is that we have been given validated data in the Database. This means that it is not our responsibility to make sure that the data is valid – something else has already done that.
What Input do we need?
Customer Information – on the Database (Table Customer)
Call Information – on the Database (Table Calls)
Call type Information – on the Database (Table Calls)
Message Information – on the Database (Table Messages)
Most of the information we need is already on the Database, but in addition we need some input from the end user:
Date Range that represents the Period for charging
a rate for VAT
Now for the clever part:
What do we have to do to the input to create the output?
At this point, we look at the constraints (or ‘Rules’) that have to be applied. To the data (Including the very obvious)
We are interested in all customers on the Database
What do we have to do with this data? – Input it and Output it, nothing else.
We are only interested in data within the Period in question
We have to compare the Date and Time of the Calls to the Date& Time range the end user inputs and only process data within that range.
We have to round up the call times to the nearest second and report totals in Minutes
Each call is recorded to the nearest .01 of a second; we have to round it to the nearest second and divide by 60
We have to count the messages sent
When we read a message record we have to add one to a count and when all messages have been counted, multiply by a rate
We have to apply the appropriate Cost calculations to the call times / messages as defined in the requirements i.e.
Rental: Fixed at 25.00 per Month
Call Costs:
Non International =First 100 minutes Free, subsequent minutes cost 0,15 per minute
International = 0.50 per minute
Message Costs: First 50 are free, subsequent messages cost 0.10 each
In order to create the totals we will have to apply a formula to the data:
Total Cost of Calls = the sum of the Cost of each Call
The Cost of each Call = the duration of the Call, rounded up to the nearest second, Multiplied by the appropriate rate (Zero if the current total number of minutes is less than or equal to 50, otherwise 0.10)
The current total number of minutes = the sum of the minutes used so far.
Now, just stop and think for a second or two about the nature of the data and how things work in the real world. What if we get to the stage where the Customer has used 98 minutes so far and makes a call lasting 5 minutes? We will need to charge only for 3 minutes, as the first 2 minutes of the 5-minute call will be free.
So we have derived an additional constraint that our program will have to take care of..We will need to check if the minutes used so far plus the duration of this call is greater than 100 and if so, only charge for the difference between the two for that call.
Understanding the nature of the Data and considering all possible combinations of conditions that can happen is one of the keys to good analysis. We’ll see another example later.
Total Cost of Messages = the number of messages Multiplied by the appropriate rate (Zero if the current number of messages is less than or equal to 50, otherwise 0.10
We have to calculate the VAT
VAT = (Monthly Rental + Total Cost of Calls + Total Cost Of Messages) Multiplied by the Rate
We have to calculate the Total the Customer has to pay
Total = Total Cost of Calls + Total Cost of Messages + Monthly Rental + VATContinued in next Post.........
It’s a fact that many people starting off in programming are given a task and the first cry is “Help - I don’t know where to start”. Hopefully, if you’re one of those people, then by the time you’ve read this you will know the answer.
There are many different ways of analysing problems and I’ll be going through the method I use, it’s not a formal method that you could read in a textbook but one that I have used over many years and it works for me. (It’s very, very loosely based on Jackson)
The process is best described using an example, for this tutorial I’ll take the problem as:
Write a Billing System for a Mobile Telephone company that processes information from a database on a monthly basis and calculates the total cost per Customer on the following basis:
Monthly Rental is 25.00. The call times are measured by hundredths of Seconds. Calls are charged by the Second. The first 100 minutes used are free (except for International calls which are charged at 0.50 per minute). After the customer has used 100 minutes, calls are charged at a rate of 0.15 per minute. The first 50 Text Messages are free and after the 50 have been sent they cost 0.10 per message.
The output required is the Period, Customer Details (Name, Address, Account Number, Mobile Number), Total number of International call minutes used and cost, Total number of other call minutes and cost, Total number of text messages sent and cost, total cost, VAT (Value Added Tax) and amount to pay.
The Database contains the following validated data in a series of Tables
Table Customer:
Customer Name
Customer Address
Customer Mobile Number
Customer Account Number
Table Calls:
Customer Account Number
Date and Time Call started
Date and Time Call ended
Type of Call (“I” for International, “N” for In Country)
Table Messages:
Customer Account Number
Date and Time Message Sent
Where to start?
It may seem a bit silly, but I start with the output required. What does the program have to produce? In our example it’s fairly straightforward,
The Period of the Charges
Some information about the Customer
The Total number of Call Minutes used and cost (International and Others)
The Total number of Text messages sent and cost
The Total cost
The VAT
The Grand Total the Customer has to pay
In order to create the output, we have to have some input, so the next thing to do is to look at that. The first thing to notice is that we have been given validated data in the Database. This means that it is not our responsibility to make sure that the data is valid – something else has already done that.
What Input do we need?
Customer Information – on the Database (Table Customer)
Call Information – on the Database (Table Calls)
Call type Information – on the Database (Table Calls)
Message Information – on the Database (Table Messages)
Most of the information we need is already on the Database, but in addition we need some input from the end user:
Date Range that represents the Period for charging
a rate for VAT
Now for the clever part:
What do we have to do to the input to create the output?
At this point, we look at the constraints (or ‘Rules’) that have to be applied. To the data (Including the very obvious)
We are interested in all customers on the Database
What do we have to do with this data? – Input it and Output it, nothing else.
We are only interested in data within the Period in question
We have to compare the Date and Time of the Calls to the Date& Time range the end user inputs and only process data within that range.
We have to round up the call times to the nearest second and report totals in Minutes
Each call is recorded to the nearest .01 of a second; we have to round it to the nearest second and divide by 60
We have to count the messages sent
When we read a message record we have to add one to a count and when all messages have been counted, multiply by a rate
We have to apply the appropriate Cost calculations to the call times / messages as defined in the requirements i.e.
Rental: Fixed at 25.00 per Month
Call Costs:
Non International =First 100 minutes Free, subsequent minutes cost 0,15 per minute
International = 0.50 per minute
Message Costs: First 50 are free, subsequent messages cost 0.10 each
In order to create the totals we will have to apply a formula to the data:
Total Cost of Calls = the sum of the Cost of each Call
The Cost of each Call = the duration of the Call, rounded up to the nearest second, Multiplied by the appropriate rate (Zero if the current total number of minutes is less than or equal to 50, otherwise 0.10)
The current total number of minutes = the sum of the minutes used so far.
Now, just stop and think for a second or two about the nature of the data and how things work in the real world. What if we get to the stage where the Customer has used 98 minutes so far and makes a call lasting 5 minutes? We will need to charge only for 3 minutes, as the first 2 minutes of the 5-minute call will be free.
So we have derived an additional constraint that our program will have to take care of..We will need to check if the minutes used so far plus the duration of this call is greater than 100 and if so, only charge for the difference between the two for that call.
Understanding the nature of the Data and considering all possible combinations of conditions that can happen is one of the keys to good analysis. We’ll see another example later.
Total Cost of Messages = the number of messages Multiplied by the appropriate rate (Zero if the current number of messages is less than or equal to 50, otherwise 0.10
We have to calculate the VAT
VAT = (Monthly Rental + Total Cost of Calls + Total Cost Of Messages) Multiplied by the Rate
We have to calculate the Total the Customer has to pay
Total = Total Cost of Calls + Total Cost of Messages + Monthly Rental + VATContinued in next Post.........