How to build a program to solve a certain problem ?
The six steps that are required to build a computer program for solving a certain problem are explained below:
Problem Analysis: Problem analysis is the process of defining a problem and decomposing overall system into smaller parts to identify possible inputs, processes and outputs associated with the problem.
Problem Design: This stage consists of preparing algorithms, flowcharts and pseudocodes. Generally, this stage intends to make the program more user friendly, feasible and optimized.
Coding: Transforming the program logic design into a computer language format i.e. actual writing of computer programs is known as coding. It can be said that coding is the act of transforming operations explained in algorithm or in each boxes of flowchart into statement of the programming language.
Compilation and Execution: The conversion process of high level language into machine level language with the help of language translators(compiler) is known as compilation. Once the compilation process is complete it is linked with other object programs and library files resulting in an binary program(executable file). Thus obtained binary program is loaded into the memory for the purpose of execution.
Debugging and Testing: The presence of bugs(errors) in the program can cause it to behave unexpectedly or even crash. Debugging is the process of detecting and correcting existing and potential bugs in a software program. Testing is the process to find bugs. Testing ensures that the program performs the required task correctly.
Program Documentation: Any written text, illustrations or video that describe a software or program to its users is called a program or software documentation. Documentation should be from the point of view of the reader. Industry standards should be used and should be updated.
Different Types Of Errors
The common errors that are encountered during programming in any language can be generally categorized as:
Syntax Error : an error that occurs when the code does not follow the syntax rules of programming language. For example:
printf(“Hello World)
will show a syntax error because semicolon(;
) is missing at the end.Logical Error : an error that occurs when there is the logical mistake such as
>=
instead of>
or an infinite loop and so on . The code may run/execute but the desired result is not obtained.Runtime Error : an error that occurs when the program is being executed or running. For example, trying to open a file(File Handling) that doesn’t exist .
Debugging Vs Testing
Factors | Debugging | Testing |
WHAT ? | Fix error | Find error |
WHEN ? | Done at Development phase | Done at Testing phase |
WHO ? | Performed by developers | Performed by system testers. |
HOW ? | Manual operation | Manual or automatic operation |
Steps Involved During Compilation Of A Source Code Written In C
Source code
my_program.c
is transferred to the preprocessor.Preprocessor transforms the source code to expanded source code
my_program.i
.Extended/Expanded Source Code is transferred to the compiler to be converted into assembly code
my_program.s
.Assembly Code is transferred to Assembler to be converted into object code
my_program.o / my_program.obj
.Note
In the context of compiling C source code, the term "compiler" is often used more broadly to refer to the entire compilation process, which includes several stages. While it's true that the compilation process involves multiple steps, including preprocessing, compiling, assembling, and linking, the term "compiler" is commonly used to describe the entire process as a whole.- Object Code is combined with library files and other objects to generate an executable code
my_program.exe
.
Structure Of A Program In C
/* 1. Documentation Section */
//A program to find the area of a circle. Programmed by Er. Kushal Ghimire
/* 2. Link Section */
#include <stdio.h>
/* 3. Definition Section */
#define PI 3.14
/* 4. Global Section */
/* 4.1 Global Variable Declaration */
float result;
/* 4.2 Function Declaration/Prototype */
void area_of_circle(float);
void display();
/* 5. Main Section */
int main()
{
/* 5.1 Declaration Part */
float radius;
/* 5.2 Executable Part */
printf("Enter radius of a circle: ");
scanf("%f", &radius);
area_of_circle(radius);
display();
return 0;
}
/* 6. User Defined FUnction Section */
void area_of_circle(float r)
{
result = PI * r * r;
}
void display()
{
printf("\nThe area of circle is %f", result);
}
Documentation Section
Code Documentation
Programmers Details
Date and Time
Copyright Information
Link Section
- Include Header Files
Definition Section
- Define Macros and Symbolic Constant
Global Section
Global Variable
Function Prototype
Main Section
Declaration Part
- Declare The Variables
Executable Part
- Code To Execute
User Defined Section
- Define The Function Declared Previously On Global Section