DevelopingCode - Designing and Developing Programs with...

Info icon This 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.
Image of page 1

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

View Full Document Right 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.
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
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern