![]() |
![]() |
![]() |
||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Object Orientated programming (OOPS)
|
DOING WELL !! AIM - To Understand How to Plan a program |
|||||||||||||||||||||||
|
The variable declaration to store the name of a book would be Dim bookName as String Any suitable name for the variable could be used instead of bookName.
Close any existing work and open a new Visual Basic (VB) Programming Environment. Start >> Programs>> Visual Basic 6. Open a new Standard EXE file and remove the form. Now add a module. If your unsure how to do this click on the 'Getting Started with VB Link' on the left. You will also need a Word document to make some notes. There are Three important stages to planning a program. Planning, Structure and testing or PST for short. If you follow these stages I guarantee you will create great programs. 1. Purpose - Define why you are making the program i.e. what does the program have to do. No matter how simple the program, it ALWAYS pays to complete this stage. Many 'rookie' programmers jump in with both feet after reading the brief once and spend days creating a program only to find when they re-read the brief it is not quite what was asked for and all that time was wasted. FIVE MINUTES MORE IN THE PLANNING STAGE CAN SAVE DAYS OR WEEKS in the construction stage. You should be clear on what the program needs to do with no room for error or doubt. If unsure get more information. 2. Structure - This is further broken down into 3 more stages. Input, Process and Output. A computer gets information, does something with that information and then relays information (data) back to the user. Your program should be no different.
3. Testing - What goes wrong with your program and how will you fix it. Does it work? Does it display the correct information? Does the user know what to do? We will use a testing table once you have constructed a few programs. Moving On - Planning Your First Program. area = radius * radius * pi Pi is to be used to six decimal places and the value will be taken as pi = 3.14158 Firstly, list the plan structure as below. We suggest you download a copy of this structure and keep for future reference. It is the KEY to good planning. Remember PST (and structure has the three computing stages of input process and output). Click here to get a copy of this structure. Programming - Planning Purpose (What the program does) Structure (How the program will do it) Testing (Corrections and improvements) Save the downloaded document as PlanningStructure to your Programming folder. Then re-save (F12) as AreaOfCirclePlan. Now we need to flesh the skeleton structure out. We have included 'constraints' in our Purpose part of the plan. A constraint is something that must be done you don't have to use the term if you are not familiar with it, just make sure you have listed any limitations or specific criteria (things) your program needs to do. The title should reflect the nature of the program. Try to write your own plan from the brief and then check back with ours below. Planning - Program To Find Area Of Circle Purpose (What the program does) The program needs to get the radius of a circle and display the area of the circle for that given radius. Formula: area = radius * radius * pi CONSTRAINTS: 1.The user must be able to enter any type of data and the program will give the area back in that measurement type. 2. The program should be self explanatory. The user must know what to do without asking for help. 3. pi = 3.14158. Structure (How the program will do it) Input - What does the program need to get The program needs to get the radius of the circle The program needs to get the unit of measurement of the circle Process - What will it do with that information The program needs to multiply the radius by its self and then by pi, given formula below area = radius * radius * pi Output - What will the program give back to the user The program needs to display the area of the circle and the unit of measurement. Testing (Corrections and improvements) You should have a completed program plan. We will now move on to the code. Below the structure in you planning document we are going to write a draft or pseudocode. This just means that we are going to start to write an order to our program in a language somewhere between English and code. There are NO written laws about the language of pseudocode whatever makes sense to you is fine. The goal is to organise the program into a logical order for things to happen. I use a numbered list, I find this helps to set the order. The code comes from the structure part of the plan. We also need to start and end the program. Skeleton Plan Copy the pseudocode below to the bottom of your plan - save and read through. 'Fleshed Out' Plan Pseudocode If we entered the pseudocode into the the code window it would NOT work, it is false code a half way step between your plan and the full code. The full code is listed below. Copy the code to your new module window - run it and save. Now indent the code and put the REMs in as per the picture below. Run the program and check calculations with a calculator. CODE Option Explicit Make you code look as below. Note we have used 'Double' as our variable type for the radius and the area. We want no restrictions on the size of the number our user can safely enter. The unit of measurement is a string since no mathematical functions will need to be applied to this. It is just a list of characters we will reproduce. We have also added the string '^3' to the end of the last message box since the final measurement will be cubed. Check you program runs, If not it will be a typing error. Visual Basic is NOT case sensitive but it does need the correct spellings and all REM comments must have the ' before them. If you are having problems - Check the following Using Shapes to Plan As well as using a numbered list and pseudocode you can also use shapes to plan. The advantage of using shapes is it is quicker and easier to see errors in your logic. There are 3 basic shapes we use. It is a good idea to try to learn what the shapes represent and they are pictured below A construct shape diagram - a shape plan for this program is shown below. What the program does is shown in a rectangle at the top. Then the program shows what happens by moving through the shapes form left to right. So this program Once you are happy with your progress click the QUIZ button. |
||||||||||||||||||||||||