Introductory Programming Tutorial Project 1: Program Development Techniques

 

The recommended method for developing programs is to use the techniques called top-down design and stepwise refinement. Top-down design in the simplest sense refers to starting with a very broad, general solution such as simply having a program that will load and run without errors. For example, I recommend that you start your coding of every project with the following minimal working code:    
      #include <iostream>

      int main()
      {
          return 0;
      }

Enter this minimal code then  compile, build and execute with NO errors or warnings before continuing to develop your project. This initial program has no output, but when it runs, you know you have a working, error-free program from the very beginning. It is considered to be best practice to create a written program design using some form of pseudocode format. The pseudocode design can also be developed using top-down design and stepwise refinement.

 

Stepwise refinement refers to building functionality into a program in steps (incrementally). After each small step is added you should build and execute the program in order to catch and fix errors as soon as they are introduced. If you have errors you need to fix them and build and execute again before continuing development.  If you do not use these techniques you will most likely experience many frustrating and wasted hours sitting at the computer trying to write programs. 

As an example, if the program requirements specify that the program will prompt the user to enter two integer numbers, then add the two numbers together, and then display the results, you might build the program incrementally using these steps:

 

1.
#include <iostream>
int main()
{
    return 0;
}
Compile - Build - Execute

4.
#include <iostream>
using std::cout;
int main()
{
    int num1=2, num2=5;
    cout << "num1 + num2 = " << num1 + num2;
    return 0;
}

 
Compile - Build - Execute

2.
#include <iostream>    
int main()
{
    int num1, num2;
    return 0;
}
Compile - Build - Execute

5.
#include <iostream>
using std::cout;
int main()
{
    int num1=2, num2=5;
    cout << "Enter two integers: ");
    cout << "num1 + num2 = " << num1 + num2 << '\n';
    return 0;
}
Compile - Build - Execute

3.
#include <iostream>
using std::cout;
int main()
{
    int num1 = 2, num2 = 5;
    cout << "num1 + num2 = 7\n";
    return 0;
}
Compile - Build - Execute

6.
#include <iostream>
using std::cout;
using std::cin;

int main()
{
    int num1=2, num2=5;
    cout << "Enter two integers: ";
    cin >> num1 >> num2;
    cout << "num1 + num2 = " << num1 + num2 << '\n';
    return 0;
}
Compile - Build - Execute