Section 8f

Step Five - Designing the Supporting Functions


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Systematic and Structured Programming, Part 2

Step Five - Creating Smaller Solutions

Step four probably took a little longer then step three because you were writing code and fixing little syntax errors as you worked through it. However, it should still have been straightforward because you had specific instructions to follow from your prior steps. You will now be reusing that process on a smaller scale.

Just as you did for the main program and function, you will now be creating the solution pseudocode for your individual functions. Here in the fifth step of the process, you will actually go back and use steps one, two, and three on each of the functions. As mentioned previously, this is a recursive process because your original six step process is now incorporating three parts of the same six step process into one of the steps. Recursion will be discussed later in this course, but you will find it handy sometimes to repeatedly reuse processes you have already created rather than having to create new ones

As a note of review here, when you have finished step four you should have a fully working main function. You should not have to go back and mess with the main function any more. One of the many benefits of this system is that you don't have to retrace any steps - you can keep moving forward. With forward motion in mind, your next step now is to design (i.e., write the pseudocode for) your supporting functions.

If you are working through this with the web page, you should change your program file name from QuadProg_StepFour.c to QuadProg_StepFive.c now so that you don't overwrite your fourth step. You will be reminded again to make this change at the end of this web page. Note that the version numbers are not added to the file names in this text since you will be in charge of knowing when you update your files.

Your nearly final iterative pass will not be through the program as it has been before. Now you will work your way through the stub functions, creating pseudocode solutions as steps one, two, and three as you go.

It should also be noted here that to make this tutorial reasonable in length, the functions are pretty simple. Thus, the step one and step two statements will not be very different. However, you should recognize as your programs become more complex, there will be more need to create the simple solution (i.e., step one), and then expand on it to a full pseudocode solution (i.e., step two). Step three will also be brief here because very few functions need to be called by these functions.

Start here

At this point, you should find all your functions in alphabetical order, both up at the top in the prototypes area and down below in the implementation area. And normally you would work through them in that order. It doesn't really matter but it is easier to just do one after the other. However, for this tutorial, you will be working your way through the functions in the order they were created, just to keep things consistent.

printTitle

Here is the “process” specification for this function:

Process: display the program title on the monitor

Prior to input for the printTitle stub, step one will identify the main steps. Note that you should always have an initialize function/variables comment line at the beginning of every function, even if some functions do not actually need variables:

void printTitle()
{
// initialize function/variables
// none

// print title complete
}

Step two adds a couple of lines

void printTitle()
{
// initialize function/variables
// none

// print title complete

// print title, with endline

// print underline, with two endlines
}

And step three identifies any functions needed by this function, which in this case includes use of both Console I/O Utility output and input operations:

void printTitle()
{
// initialize function/variables
// none

// print title complete

// print title, with endline
// function: printString, printEndline

// print underline, with two endlines
// function: printString, printEndlines
}

promptForCoefficient

Here is the "process" specification for this function:

Process: prompt user for appropriate coefficient, get coefficient, return coefficient

For the promptForCoefficient stub, here is step one:

int promptForCoefficient( char coefLetter )
{
// initialize function/variables

// prompt user for coefficient

// get the input from the user

// return the user input to the calling function
return 0; // temporary stub return
}

Step three identifies any functions needed by this function, which in this case includes use of iostream output and input operations:

int promptForCoefficient( char coefLetter )
{
// initialize function/variables

// prompt user for coefficient
// function: printString, printCharacter

// get the input from the user
// function: promptForInteger

// return the user input to the calling function
return 0; // temporary stub return
}

calcDiscriminant

Here is the function "process" specification:

Process: calculate discriminant with three coefficients and return

Here are the step one statements

int calcDiscriminant( int cof_A, int cof_B, int cof_C )
{
// initialize function/variables

// calculate discriminant

// return discriminant
return 0; // temporary stub return
}

In this function, there is no more needed beyond what was stated as step one statements, so there is no need to add step two statements to this function

As it turns out, step three for this function will also be the same since no functions are called by this function; thus the function is complete with its step one statements, as shown:

int calcDiscriminant( int cof_A, int cof_B, int cof_C )
{
// initialize function/variables

// calculate discriminant

// return discriminant
return 0; // temporary stub return
}

calcDenominator

Here is the "process" specification for the calcDenominator function:

Process: calculate denominator with coefficient A and return

Again because of the simplicity of this function, steps one, two and three are all the same. Functions that are well developed and concise such as this one will always be easy to write

int calcDenominator( int cof_A )
{
// initialize function/variables

// calculate denominator

// return denominator
return 0; // temporary stub return
}

calcRoot

You must now create the pseudocode for the calcRoot function. Here is the "process" specification for the function:

Process: calculate single root solution with previously processed equation components, and return

Here are steps one, two, and three for this simple function:

double calcRoot( int cof_B, int denom, double discSqrRoot )
{
// initialize function/variables

// calculate the numerator

// calculate the root

// return root
return 0.0; // temporary stub return
}

displayInputValues

Next, you must implement the displayInputValues function, with the following "process" specification:

Process: displays three user input values

Here is step one of the development process for this stub function:

void displayInputValues( int coefA, int coefB, int coefC )
{
// initialize function/variables

// show data display
}

Here is step two of the development process:

void displayInputValues( int coefA, int coefB, int coefC )
{
// initialize function/variables

// show data display

// display the leader text

// display coefficent A with comma and space

// display coefficient B with comma, space, and "and"

// display coefficient C with comma

// display end line
}

And here is step three of the development process:

void displayInputValues( int coefA, int coefB, int coefC )
{
// initialize function/variables

// show data display

// display the leader text
// function: printEndline, printString

// display coefficent A with comma and space
// function: printString, printInteger

// display coefficient B with comma, space, and "and"
// function: printString, printInteger

// display coefficient C with comma
// function: printInteger, printCharacter

// display end line
// function: printEndline
}

displayRoot

Finally, you must implement the displayRoot function, with the following "process" specification:

Process: display root number and root solution

Here is step one of the development process for this stub function:

void displayRoot( int rootNum, double rootSolution )
{
// initialize function/variables
// none

// show root display
}

Here is step two of the development process:

void displayRoot( int rootNum, double rootSolution )
{
// initialize function/variables
// none

// show root display

// display the root number with leader

// display colon with space

// display root value

// end the line
}

And here is step three of the development process:

void displayRoot( int rootNum, double rootSolution )
{
// initialize function/variables
// none

// show root display

// display the root number with leader
// function: printString, printInteger

// display colon with space
// function: printString

// display root value
// function: printDouble

// end the line
// function: printEndline
}

As you can see, your steps 1, 2, and 3 should never be very complicated with supporting functions, but again it should be noted that this is a pretty simple program. As your programs grow in complexity and size, you will have many opportunities to apply all three steps to this part of the programming process. However, you must also note that because you broke the larger program down into smaller sub-programs, it should never be particularly difficult to develop any of the functions

Wrapping Up the Final Design Component


To see the step five process in action, watch this video; then develop your step five code with or without the video, as needed