Question

In: Computer Science

Explain the importance of program modularization using at least one example. 300 words

Explain the importance of program modularization using at least one example.

300 words

Solutions

Expert Solution

Modular programming is a software design technique that focus attention on highlight separating the functionality of a program into independent modules, such that each contains everything necessary to execute only one aspect of the desired functionality.

Concept of Modularization

One of the most important concepts of programming is the ability to group some lines of code into a unit that can be included in our program.

The original words for this is a sub-program.

Other names include:

  • Macro
  • sub-routine
  • procedure
  • module and function.

We are use the term function for that is what they are called in most of the main programming languages of today.

Functions are important because they allow us to take large complicated programs and to divide them into smaller pieces. Because the function is a smaller piece of the program, we can concentrate on what we want it to do and test it to make sure it works properly. Generally, functions fall into two categories:

1.       Program Control – Functions used to simply sub-divide and control the program. These functions are unique to the program being written

2.       Specific Task – Functions designed to be used with several programs. These functions perform a specific task and thus are usable in many different programs because the other programs also need to do the specific task

Depending on the programming language, there is a formal way to:

  1. define a function
  2. call a function
  3. declare a function

Program Control Function

The main program piece in many programming languages is a special function with the identifier name of main. The special or uniqueness of main as a function is that this is where the program starts executing code and this is where it usually stops executing code.

Specific Task Function

We often have the need to perform a specific task that might be used in many programs.

Advantages:

==> Development Can be Divided
Modular Programming allows development to be divided by splitting down a program into smaller programs in order to execute a variety of tasks.
This enables developers to work simultaneously and minimizes the time taken for development.
==> Readable Programs
Modular Programming helps develop programs that are much easier to read since they can be enabled as user-defined functions.
A program that carries multiple functions is easier to follow, whereas a program that does not have a function is much harder to follow.
==> Collaboration
With Modular Programming, programmers can collaborate and work on the same application. Designing a program also becomes simpler because small teams can focus on individual parts of the same code.
==> Improves Manageability
Having a program broken into smaller sub-programs allows for easier management. The separate modules are easier to test, implement or design. These individual modules can then be used to develop the whole program.
==> Allows Re-Use of Codes
A program module is capable of being re-used in a program which minimizes the development of redundant codes. It is also more convenient to reuse a module than to write a program from start. It also requires very little code to be written.

==> Programming Errors are Easy to Detect
Modular Programming minimizes the risks of ending up with programming errors and also makes it easier to spot errors, if any.
This is because the errors can be narrowed down to a specific function or a sub-program.


Example of Modular Programming in C

C is called a structured programming language because to solve a large problem,

C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility.

The program which solves the entire problem is a collection of such functions.
Module is basically a set of linked files that share their implementation details but hide it from the outside world.

How can we implement modular programming in c?

 Each function defined in C by default is globally accessible. This can be done by including the header file in which implementation of the function is defined.
Suppose, we want to declare a Stack data type and at the same time want to hide the implementation, including its data structure, from users.

We can do this by first defining a public file called stack.h which contains generic data Stack data type and the functions which are supported by the stack data type.
In the header file we must include only the definitions of constants, structures, variables and functions with the name of the module, that makes easy to identify source of definition in a larger program with many modules.
Keywords extern and static help in the implementation of modularity in C.
stack.h:
extern stack_var1;
extern int stack_do_something(void);
  
Now we can create a file named stack.c that contains implementation of stack data type:
stack.c
#include
int stack_var1;
static int stack_var2;

int stack_do_something(void)
{
stack_var1 = 2;
stack_var2 = 5;
}

The main file which may includes module stack
#include
int main(int argc, char*argv[]){
while(1){
stack_do_something();
}
}


Related Solutions

Explain the importance of program modularization using at least one example. 300 words
Explain the importance of program modularization using at least one example. 300 words
Explain the importance of microfinancing in 300 words in your own words.
Explain the importance of microfinancing in 300 words in your own words.
300 words explain: Disorders of the large intestine What is one example of a disorder that...
300 words explain: Disorders of the large intestine What is one example of a disorder that can effect the large intestine? What effect does the disorder have on the large intestine? Can the disorder be prevented? Why or why not?
Importance of Capital Markets In 300 words, please explain the importance of capital markets to corporations....
Importance of Capital Markets In 300 words, please explain the importance of capital markets to corporations. What is the difference between a primary market and secondary market? How do these types of capital markets differ in their impact on corporations? What are some influences that may negatively impact capital markets and how can corporations help keep these influences stabilized? +3 References would be nice! Thanks in advance and answer will be definitely well-rated.  
importance of market segmentation? 300 words
importance of market segmentation? 300 words
Explain the meaning and importance of accounting standards.(300-400 words needed)
Explain the meaning and importance of accounting standards.(300-400 words needed)
Write at least 300 words on ONE of the following topics. Answers will be graded on...
Write at least 300 words on ONE of the following topics. Answers will be graded on accuracy and specific details. What was new and innovative about Impressionism, and how was it a reaction to cultural change? Use one painting as an example. OR How did Picasso's Les Demoiselles d'Avignon embody the shift in painting from the literal to the conceptual? Discuss three particular elements of the painting that contributed to its status as groundbreaking art.
Give an example of a program in java that creates a GUI with at least one...
Give an example of a program in java that creates a GUI with at least one button and several textfields. Some of the textfields should be for input and others for output. Make the output textfields uneditable. When the button is clicked, the input fields should be read, some calculation performed and the result displayed in the output textfield(s).
Answer using at least 300 words and specific details. Trace the development of the first British...
Answer using at least 300 words and specific details. Trace the development of the first British colonies in North America. What specific problems did the Roanoke and Jamestown colonists face? Why did the Jamestown colony survive? How were Plymouth and the Northern colonies different from Virginia? How did events in England and Europe affect American colonization? What set British colonies apart from those of other European empires?
Answer in 5 to 6 sentences. Using at least one example in each question. 1. Explain,...
Answer in 5 to 6 sentences. Using at least one example in each question. 1. Explain, in your words, what administration is. 2. Indicate what the characteristics of effective and efficient management are (the two words have a different meaning)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT