An Introduction to Software Development – C++ Lessons

An Introduction to Software Development

Introduction to software development

Our first program needs to be developed before we can execute it. This guide will help you learn how C++ software development happens in general.

An overview of the software development process:

Software development process

Table of contents:

  • Step # 1: Identify the problem you would like to solve
  • Step # 2: Decide How You Are Going To Solve This Problem
  • Step # 3: Write a program
  • Step # 4: Compilation
  • Step # 5: Linking (linking object files)
  • Step # 6: Testing and Debugging

Step # 1: Identifying the issue that needs to be resolved

This is the “What?” question. This is the point at which you need to determine what you want to achieve with your program. This can either be the simplest or most difficult step. Make sure you know what you want. Once that is done, you can proceed.

As an example of step # 1, here are some factors:

  • My goal is to develop a program that computes the arithmetic mean of the numbers I enter.”
  • There is a 2D maze that the user can explore through a program that I want to write.”
  • In order to make predictions about the jumps in stock prices up or down, I am going to write a program which analyzes stock prices on a stock exchange and makes predictions about these prices.”

Step # 2: Decide How You Are Going To Solve This Problem

In this case, we already have the answer to “How”?. What could you do to resolve the problem outlined in step # 1? This step is very often overlooked in software development. It is important to realize that there can be many possible methods of solving a problem, but some are better than others. It is necessary to learn to distinguish between the former and the latter. You can often see a programmer who has an idea and immediately begins programming. If you are like most people, then you have noticed that this scenario does not guarantee successful outcomes.

An effective solution typically consists of these characteristics:

  •    The simplicity of the solution;
  •    Good documentation (with comments and instructions);
  •    Programming principles that are modular: reusing or changing parts of code without affecting others;
  •    Reliability: Handling errors and emergencies in a timely manner.

You begin programming right away and think, “I need to do this, this and this and this!” Therefore, you make decisions that will enable you to accomplish the task quickly. It can lead to the fact that later on, you will be unable to change or modify the program, or you will be faced with a large number of bugs.

Approximately 20% of a programmer’s time is spent writing a program, and 80% of that time is spent debugging (fixing bugs) and maintaining (adding new features) the code. Consequently, it is better to think about the best solution before coding than to spend 80% of your time seeking out and fixing bugs.

Step # 3: Write a program

For the purpose of writing a program, it is necessary to have the following:

  •    Learn how to program in the language you have chosen (we will do this for you);
  •    Editor of source code.

This program can be written in any editor, including the same Notepad on Windows and Vi on the Unix system. Nevertheless, I strongly recommend using an editor designed for programmers. There is no need to worry if you don’t have it already. 

Our next lesson will demonstrate how to install such an application.

In general, programmers’ editors provide the following features to make programming easier:

  •    Line numbering. The compiler generally provides us with error messages when debugging programs using this function. Typically, compilation errors contain a line number and the name of the error (for instance, “x variable redefinition error, line 90”). Line numbers make finding the 90th code line easier, right? If line numbers are omitted, it’s hard to find every line of code within the same file.
  •    Syntax highlighting. By changing the color of the code and programs, syntax highlighting improves one’s understanding of the whole program as well as its parts.
  •    Special font. It is often difficult to determine which character is in front of you when you are using regular fonts. For example a number 0 or letter O, a number 1 or a letter l(lower case L), or maybe a letter I(uppercase i). Therefore, a special font is needed, in which it will be easy to differentiate between the characters, preventing the accidental usage of one in place of another.

When named name.cpp, your C ++ program will be recognized by your compiler (and you as well) as a C++ source code file. The .cpp extension indicates that the file contains instructions in the C ++ programming language. The .cc extension is sometimes used instead of the .cpp extension by some programmers, but I recommend .cpp.

Also worth mentioning is the fact that C++ programs are often composed of multiple .cpp files. In these lessons, you will create a variety of relatively small programs, but down the road, you will learn how to create much larger programs, including dozens or even hundreds of .cpp files.

Step # 4: Compilation

We need a compiler to compile the program. There are two parts to the compiler:

  •    Analyzing the program for compliance with C ++ language rules (syntax check). Upon failure, the compiler will produce error messages that need to be corrected.
  •    A machine language object file is created for each source code file (or “object module”). Objects are commonly named name.o or name.obj, where the name must match your original .cpp file name. Suppose you have three .cpp files in your program, the compiler will produce three .obj files.

Compilation

Note that some operating systems, including Linux and macOS, come with a built-in C++ compiler called g++. Compiling files using G++ from the command line requires the following:

g++ -c file1.cpp file2.cpp file3.cpp

File1.o, file2.o, and file3.o will be created. This option creates only object files (.o files) when compiled. In addition to g++, a variety of other compilers exist for different operating systems, including Linux, Windows, macOS, etc.

Step # 5: Linking (linking object files)

In linking,  the compiler links all the object files it generates into one executable program that you may run or execute. Linkers (or the “linker” program) are used to perform this process.

Linking object file

Additionally, linking includes files from the C++ Standard Library (or other libraries you use, such as graphics or sound libraries). C ++ is a small and simple programming language. In addition to these functions, there is a large library of additional functions in the C++ Standard Library that your programs can use. In order for your code to display anything on the screen, you must include a special command that specifies that you want to call the display function of the C ++ Standard Library.

If all the object files were linked successfully by the linker (assuming there were no errors), the executable ended up being created. Again, for the sake of clarity, to link the .o files we created above on Linux or macOS, we can use g ++ again:

g++ -o prog file1.o file2.o file3.o

With the -o command, we tell G++ to compile and link prog from files file1.o, file2.o, and file3.o. The compilation process can be combined with the linking process if desired:

g++ -o prog file1.cpp file2.cpp file3.cpp

Prog. will be the executable file that results from the process.

Step # 6: Testing and Debugging

Here’s where the fun begins! Using the executable, you can test whether the program is working properly. Your next step will be to debug the issue. The lessons corresponding to this one will go into more detail about debugging.

Note that you will need special software to complete steps # 3-# 6. The IDE (internal development environment) refers to an integrated software package that combines these tools for you. You can refer to it as an IDE if you want. A typical integrated development environment offers a code editor with syntax highlighting and line numbering as well as a compiler and linker. Additionally, you can also troubleshoot your program with the debugger that is built-in. Additionally, the IDE comes with other useful features: comprehensive help, code addition, and sometimes a version control system as well.

LEAVE A REPLY

Please enter your comment!
Please enter your name here