Section 2f

Step Four


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finishing the Program with Four Steps


Once again, step three was not difficult. In fact, between writing steps one, two, and three, you probably still don't have a whole 30 minutes invested in this process. Again, that's just one of the benefits.

During most of an introductory programming course, you will be using functions to develop your programs. However, for the first few weeks before you learn about creating functions, the Six Step Programming Process will essentially end at this step (four); without further function development, steps five and six are not necessary. So, for a program development process that does not involve creating functions, this ends here for the time being.

If you are working through this with the web page, you must create a new program file named in your Project_1 structure. This program file will be named QuadProg_StepFour. You must then copy the contents of the main function in QuadProg_StepThree into the main function of your QuadProg_StepFour. At this point, you want to save what was stored as step three for your future review. Now you must again work your way through the program from top to bottom in the iterative refinement process. This time, and under the circumstances that you will not be creating functions, you will simply be following your previous instructions to write the code for your program.

Initialize the program

// initialize program

// initialize variables

// show title
// function: printf

    

// initialize program

// initialize variables

// show title
// function: printf
printf( "QUADRATIC ROOTS PROGRAM\n" ); printf( "=======================\n\n" );

Get the coefficients from the user

// get coefficients from user

// get coefficient A
// function: printf, scanf

// get coefficient B
// function: printf, scanf

// get coefficient C
// function: printf, scanf

// initialize program

// initialize variables
double coef_A, coef_B, coef_C;

// get coefficients from user

// get coefficient A
// function: printf, scanf
printf( "Enter coefficient A: " );
scanf( "%lf", &coef_A );

// get coefficient B
// function: printf, scanf
printf( "Enter coefficient B: " );
scanf( "%lf", &coef_B );

// get coefficient A
// function: printf, scanf
printf( "Enter coefficient C: " );
scanf( "%lf", &coef_C );

Process the quadratic roots

// Process the quadratic roots

// calculate the discriminant

// calculate the square root of the discriminant // function: Math.sqrt

// calculate the denominator

// calculate root one
// calculate root two


Update the variables

// initialize program

// initialize variables
double coef_A, coef_B, coef_C;
double discriminant;

// Process the quadratic roots

// calculate the discriminant
discriminant = coef_B * coef_B - ( 4 * coef_A * coef_C );

// initialize program

// initialize variables
double coef_A, coef_B, coef_C;
double discriminant, sqrtOfDisc;

// calculate the square root of the discriminant
// function: sqrt
sqrtOfDisc = sqrt( discriminant );

// initialize program

// initialize variables
double coef_A, coef_B, coef_C;
double discriminant, sqrtOfDisc, denominator;

// calculate the denominator
denominator = 2 * coef_A;

// initialize program

// initialize variables
double coef_A, coef_B, coef_C;
double discriminant, sqrtOfDisc, denominator;
double rootOne, rootTwo;

// calculate root one
rootOne = ( -coef_B + sqrtOfDisc ) / denominator;

// calculate root two
rootTwo = ( -coef_B - sqrtOfDisc ) / denominator;

Display the roots

// display user input
// function: printf

// display root one
// function: printf

// display root two
// function: printf

// display user input
// function: printf
printf( "For coefficients of %4.2f", %4.2f", and %4.2f\n",
coef_A, coef_B, coef_C );

// display root one
// function: printf
printf( "root one is: %4.2f", rootOne );

// display root two
// function: printf
printf( "and root two is: %4.2f"\n, rootTwo );


End the program

// end program
// display program end
// function: printf

// return function success

// end program
// display program end
// function: printf
printf( "\nEnd Program" );

// return function success
return 0;

Some more notes:


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