SK Aknoor Rahaman - Es-Cs201

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

KALYANI GOVERNMENT ENGINEERING COLLEGE

DEPARTMENT OF MECHANICAL ENGINEERING

Technical Report on
Programming For Problem Solving (Code ES-CS201)
Submitted By

Name: Sk Aknoor Rahaman. Department: Mechanical Engineering


University Roll: 10200723038 Semester: 2nd
University Registration No: 231020110245
Registration Year: 2023

Session: 2023-2024
Kalyani Government Engineering College
Department Of Mechanical Engineering

SI. Question Question/Problem Statement Page


No No no
1 1 What is Modular Programming, Benefits,
Construction.
3-5

2 2 Explain Primary Data Types Use in C


6

3 3 State the Rules for Declaring Variable in C 7-9


.
1.What is Modular Programming?

Modular programming is a software design technique that emphasizes separating the


functionality of a program into independent, interchangeable modules. Each module is a
separate piece of software that handles a specific part of the application's overall
functionality.

Key features of modular programming include:

1. Separation of Concerns: Each module is designed to perform a specific role within the
system. This separation allows individual modules to be developed, tested, and debugged in
isolation, improving productivity and error detection.
2. Reusability: Modules are often designed with the idea of reusability in mind. A well-
designed
module can be used in many different systems, reducing the need for code duplication.
3. Maintainability: Since each module is separate, changes to one module can be made with
minimal impact on other parts of the system. This greatly simplifies maintenance and
enhancements.
4. Interchangeability: If a module becomes outdated or needs to be upgraded, it can be
swapped out for a new module with minimal impact on the rest of the system.

"The concept of modular programming is not confined to a particular programming


paradigm. It
can be applied in procedural programming, object-oriented programming, and many other
paradigms. There are even some programming languages, such as Modula-2 and Modula-3,
that have been specifically designed to support modular programming. At a higher level,
similar principles are used in system design. For example, the idea of microservices in
software architecture is essentially a way of designing a system as a collection of independent
modules, each running in its own process and communicating with the others through a well-
defined interface.
Benefits of Modular Programming

Enhanced Maintainability
The isolation of modules simplifies the process of updating and debugging software. Changes
within a module typically don't affect the operation of other modules. This level of isolation
reduces the risk of creating new bugs when making changes or updates to a specific part of
the software.
Promoting Reusability
A well-constructed module is a reusable piece of software that can be used across different
projects. This practice significantly reduces development time and promotes code
consistency. Imagine having a collection of proven modules at your disposal, ready to be used
whenever you're tackling a problem that they can solve.
Improved Collaboration
Modular programming enables developers to work concurrently on different modules of a
software project. This parallelism in development can drastically reduce the project's overall
development time. Furthermore, the encapsulation within a module can allow a developer to
fully understand a specific aspect of the project without needing to comprehend the complete
system.
Constructing and Utilizing Modules
Creating and using modules in C involves separating code into different files and then linking
them together. To demonstrate this, let's consider aerospace software where one module
calculates thrust and another module controls the fuel flow.
Constructing and Utilizing Modules Creating and using modules in C involves separating
code into different files and then linking
them together. To demonstrate this, let's consider aerospace software where one module
calculates thrust and another module controls the fuel flow.
The thrust calculation module (thrust.c) might look like this:

The fuel control module (fuel.c) could be something like this:


In our main module (main.c), we Would include these modules and use their functionalities:

By dividing our code into separate modules, we have made it easier to understand, maintain,
and extend. Any updates to the thrust calculation or fuel control logic will be confined to their
respective modules, limiting the potential for bugs to spread to other parts of the program.
Modularity isn't just an abstract concept; it's a vital tool that can help you write cleaner, more
structured code. When you start viewing your programs not just as a monolithic block of
code, but as a collection of interacting modules, you're on your way to becoming a more
proficient,
effective programmer.
So, go forth, start identifying the natural divisions within your code, and unlock the power of
modular programming! We'll be diving into more intriguing facets of C programming in our
upcoming chapters. Keep those coding hats on, and keep exploring!

Conclusion
Modular programming fundamentally shifts our approach to writing software, promoting a
philosophy where software is assembled rather than written from scratch. By decomposing
complex problems into manageable modules, we not only simplify our software development
process but also make our software more robust and adaptable to future changes. It is indeed
the evolutionary approach to coding that aligns with the inevitable complexity and ever-
changing nature of our software needs.

2.It is possible to have more than one main () function in a C program?


No, it is not possible to have more than one main() function in a C program. The main()
function is the entry point for the program, and the operating system will only call one main()
function. If you try to define more than one main() function, the compiler will generate an
error.
There are a few workarounds for this limitation. One is to use preprocessor directives to
conditionally compile different main() functions. For example, you could have two main()
functions, one for a debug build and one for a release build. You would then use a
preprocessor directive to select the appropriate main() function to compile.
Another workaround is to use a function pointer to call the main() function. For example, you
could have a global function pointer called main_func, and you could initialize it to point to
the main() function that you want to call. You would then call the main_func function instead
of the main() function directly.
However, these workarounds are not recommended. It is generally best to have only one
main() function in your C program. This will make your code more readable and easier to
maintain.
Here are some of the reasons why you should not have more than one main() function in your
C program:
• It can make your code more difficult to read and understand.
• It can make your code more difficult to maintain.
• It can lead to errors.
• It is not standard practice.
If you need to have multiple entry points for your program, you should consider using a
different programming language, such as C++ or Java. These languages allow you to have
multiple entry points for your program without the drawbacks of having multiple main()
functions.

3.Write a C Program to Make a Simple Calculator?


#include <stdio.h>
int main() {
char operator;
double num1, num2, result;
printf("Enter operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
switch (operator) {
case '+':
result = num1 + num2;
printf("Result: %.2lf\n", result);
break;
case '-':
result = num1 - num2;
printf("Result: %.2lf\n", result);
break;
case '*':
result = num1 * num2;
printf("Result: %.2lf\n", result);
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
printf("Result: %.2lf\n", result);
} else {
printf("Error! Division by zero.\n");
}
break;
default:
printf("Invalid operator.\n");
}

return 0;
}
Thank You

You might also like