Understanding the problem
Before we can write and execute our first program, we need to understand in more detail how C++ programs get developed. Here is a graphic outlining a simplistic approach:
Step 1: Understand and define the problem that you would like to solve.
Try to understand what the problem is. Unless you understand the problem, you won't be able to find the solution.
Eg: What is 2+5?
So, here the problem is we don't know what is 2+5,(I know everyone knows. I am just giving an eg.). Hence, we will try to find a solution and write a program which gives output of 2+5.
Step 2: Determine how you are going to solve the problem.
You should know what path you should choose in order to get the solution. In the eg. above you will give command like "Add 2+5" to the computer or the machine. You are not going to command "Subtract 2 and 5" or something else because you know that it is not going to produce the desired output.
Typically, good solutions have the following characteristics:
- They are straightforward.
- They are well documented (especially any assumptions being made).
- They are built modularly, so parts can be reused or changed later without impacting other parts of the program.
- They are robust, and can recover or give useful error messages when something unexpected happens
Step 3: Write the program
Here, you need programming knowledge and a compiler. That's it! Well! Its not going to be easy but slowly and steadily we can do it.
Step 4: Compiling
In order to compile a program, we need a program called a compiler. The job of the compiler is twofold:
1) To check your program and make sure it follows the rules of the C++ language. If it does not, the compiler will give you an error to help pinpoint what needs fixing.
2) To convert each file of source code into a machine language file called an object file. Object files are typically named name.o or name.obj, where name is the same name as the .cpp file it was produced from. If your program had 5 .cpp files, the compiler would generate 5 object files.
Step 5: Linking, testing and Debugging
Linking is the process of taking all the object files generated by the compiler and combining them into a single executable program that you can run. This is done by a program called the linker. Well! Integrated Development Environment (IDE) comprises of all these.
At last, after compiling if you find any error or undesired results, then you need to debug the errors which is most time-consuming part.
No comments