DevelopingCode - Designing and Developing Programs with...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Designing and Developing Programs with Functions Here is a list of guidelines to which to adhere: 1) Do NOT start coding immediately. Instead plan out the following: A) How you will store your data B) What functions you will have C) What they will do D) The parameters they take in E) What they return F) The overall flow and design of main When planning, you don't necessarily have to plan these in a specific order. It's likely that you'll go back and forth, planning a function, then looking at main, and then realizing you need another function, etc. This part of the process isn't easy. It's something that gets better with practice, like everything else. 2) Once you have your plan, incrementally write code, test code and debug code. Do NOT write the whole program before you try to compile it!!! The order in which you do things here is also variable. Some people like coding a skeleton for their main function first. Others like trying to write a full function without touching main first. Either approach can work. The key is not writing too much before you stop to test.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
If you choose to write main first, then just write a very scaled down skeleton that simply runs the overall flow of the program and leave tasks to be completed by functions blank. (Use the empty statement if you want to leave a placeholder.) Then compile this skeleton and print out statements in place of functions so you can see that the general structure is working properly. If you choose to write a function first, write the function, and then test that function by making calls to the function from main. In essence, your main won't be functioning for the program, it's temporary purpose will be to set up variables so that a proper function call can be made, and then checking to see whether the desired result occurred. 3) Basic debugging technique: Inserting printf statements at various points in the code so that you can see the value of variables at different points in time. A better technique is to use a debugger, but until you learn how to do that, printfs will do. 4) Black-box testing of functions: Once a function is written, design test cases based on the input and output specifications of the function and WITHOUT looking at the actual code of the function. Try out all cases that seem to be different based on the specifications. 5) White-box testing of code: Look at the code and create test cases that specifically run each line of code that is written. Basically, you must look at each if statement you have, and each loop, and make sure at least one of your test cases enters each possible branch of that construct.
Background image of page 2
Fruit Stand Example Consider creating a program that allows the user to buy fruit from a fruit stand. The user can continually choose to buy fruit until they quit. The two fruits sold at the fruit stand are apples
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2011 for the course COP 3223 taught by Professor Guha during the Spring '08 term at University of Central Florida.

Page1 / 11

DevelopingCode - Designing and Developing Programs with...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online