Professional Documents
Culture Documents
UNIT I: Programming Fundamentals: 1.0 Learning Outcomes
UNIT I: Programming Fundamentals: 1.0 Learning Outcomes
1.1 Introduction
In this section, we will explore the importance of understanding algorithms,
pseudocode, and flowcharts in the context of computer programming. Algorithms
are the heart of efficient problem-solving, while pseudocode and flowcharts act as
powerful tools to represent and visualize complex procedures, aiding in the
development of effective software solutions.
1.2 Topics/Discussion
This module covers the following topics:
3. Pseudocode or Flowchart: Use pseudocode or flowcharts to clarify the program's logic and structure.
4. Code Writing: Implement the algorithm in C, keeping the code organized and well-commented.
5. Compilation: Compile the C code into machine-readable format using a C compiler.
6. Testing & Debugging: Thoroughly test the program, fixing any errors or bugs.
7. Optimization: Improve code performance and efficiency if needed.
8. Documentation: Maintain comprehensive code comments for clarity and future modifications.
9. Version Control: Use Git or similar tools to manage and track code changes.
10. Deployment: Deploy the stable program for end-users or integration.
11. Maintenance: Regularly update and maintain the program for reliability.
1. Functions: Building blocks of the program, taking input, performing operations, and returning
results.
2. Global Variables: Declared outside functions, accessible from any part of the program. Excessive use
discouraged due to complexity and data integrity issues.
3. Sequential Execution: Follows step-by-step execution, managing flow through function calls and
return statements.
4. Limited Data Abstraction: Data and functions not tightly encapsulated, leading to potential
management challenges.
5. Code Reusability: Promotes code reusability by breaking functionality into smaller functions.
6. Top-Down Design: Divides problems into smaller sub-problems, solved by separate functions.
1.2.3 Algorithm
1 | Computer Programming 1 3
1. Well-Defined: The steps of the algorithm must be precisely and unambiguously defined. Each step
should have a clear purpose and should be executable without any ambiguity.
2. Finite: An algorithm must have a finite number of steps. It should eventually terminate after
completing all the necessary instructions.
3. Input: Algorithms take some input, which is processed to produce an output. The input could be
data, values, or information required to perform the task.
4. Output: After the algorithm has completed its execution, it should produce a result or output that
solves the problem or accomplishes the task.
5. Deterministic: The steps in an algorithm should be deterministic, meaning that given the same input,
it will produce the same output every time it's executed.
6. Feasible: The algorithm should be practical and feasible to execute. It should not rely on infinite
resources or take an unreasonable amount of time to complete.
7. Correctness: The algorithm must produce the correct output for all valid inputs. It should solve the
problem it is designed to address
Example:
Algorithm: Adding Two Numbers
1. Get the value of the first number.
2. Get the value of the second number.
3. Add the value of the first number to the value of the second number.
4. Display the sum obtained from step 3 as the output.
IPO Model
1.2.4 Pseudocode
Pseudocode is a high-level, informal way of representing an algorithm or program.
It is not specific to any particular programming language and is designed to be easily
understandable by humans. Pseudocode uses simple and natural language-like
constructs to outline the logical steps of an algorithm or program without focusing on
specific syntax.
Pseudocode is often used in the early stages of software development to plan and
design algorithms before writing code in a specific programming language. It is a
valuable tool for developers to communicate and collaborate with each other, as well as
with stakeholders, without getting bogged down by language-specific syntax and
technical details.
Example
Pseudocode: Addition of Two Numbers
1. Start
2. Read the value of num1
3. Read the value of num2
4. Set sum = num1 + num2
5. Display sum as the output
6. End
1.2.5 Flowchart
A flowchart is a visual representation of an algorithm or a process. It uses various
symbols and arrows to depict the sequence of steps and decision points in a clear and
easy-to-understand manner. Flowcharts are widely used in various fields, including
computer programming, business processes, and problem-solving, to visually represent
complex procedures.
Golden Rule
1. Each algorithm should have only one entry point and one exit point.
2. A null statement is shown by a flow line; there is no symbol for null.
1 | Computer Programming 1 6
Variable ← Expression
A parallelogram shows any input read or output produced. A rectangle with two
vertical bars inside represents a module call. Selection statements (Decisions) may be
two-way or multi-way selections. In both cases, the statement ends with a connector
where the true and false flows join. In this case, the connector has nothing in it. This is
applicable to switch statements or even for, while, and do-while loops of C
Both flowcharts and algorithms are isomorphic—that is, one can be converted to
another form without the loss of data (although there are some differences).
Key Features of C:
1. Procedural Language: C is a procedural programming language, which means it follows a top-down
approach, breaking a program into functions that perform specific tasks.
2. Portability: C programs can be compiled and run on different platforms with minimal changes,
making them highly portable.
3. Efficiency: C allows direct access to memory and hardware, making it an efficient language for
system-level programming and resource-constrained environments.
4. Standard Library: C comes with a standard library that provides a set of functions for common
operations, such as I/O, string manipulation, and mathematical operations.
5. Pointers: C supports pointers, which are variables that store memory addresses. Pointers are a
fundamental feature for memory management and data manipulation.
6. Static Typing: C is statically typed, meaning variable types must be declared before they are used,
enhancing type safety and performance.
1 | Computer Programming 1 8
7. Modularity: C allows modular programming, enabling developers to create reusable code through
functions and libraries.
8. Low-Level Access: C provides low-level access to memory and allows bitwise operations, making it
suitable for low-level programming tasks.
9. Extensibility: C can be extended with custom libraries or system-specific code, making it suitable for
embedded systems and operating systems development.
When you issue the command to compile a C program, the program is run
automatically through the preprocessor. The preprocessor is a program that modifies the
C source program according to the directives supplied in the program. An original
source program is usually stored in a file. The preprocessor does not modify this
program file but creates a new file that contains the processed version of the program.
This new file is then submitted to the compiler. When we compile this program, the
compiler shows the number of lines compiled to be greater than 6. This is because during
the preprocessing stage, the include preprocessor directive searches the file iostream.h in
the prescribed list of directories and if the header file is found, the include directive is
replaced by the entire content of the header file. If the included header file contains
another include directive, it will also be processed. This processing is carried out
recursively till either no include directive remains or till the maximum translation limit is
achieved (ISO specifies a maximum of 15 nested levels of include files). Thus, one line of
source code gets replaced by multiple lines of the header file. During the compilation
stage, these added lines will also be compiled. Thus, the compiler shows the number of
lines to be greater than 6.
Some compilers enable the programmer to run only the preprocessor on the source program
and to view the results of the preprocessor stage.
12. A preprocessor symbol is never replaced if it occurs within single or double quotation marks. 13.
Header files also provide consistency among several program files. Often a program is large and thus it
is possible to break it into smaller units, each of which is stored in a separate file. After these separate
program files are compiled, they must somehow be linked together to form a single program. This
linking is usually done by a program called the linkage editor (which is run automatically when a
program is compiled).
14. A header file can contain other #include directives. Please note that it cannot include itself because this
would result in an infinite recursion. Also note that it cannot include another file that includes the first
file as this would also result in an infinite recursion.
15. Header files can contain any text at all. They may also contain C code to define structure templates,
global variables, or function definitions. However, header files usually do not contain function
definitions as it is more efficient to store these in the function libraries set up by the user. But global
variables are sometimes included.
16. If iostream.h is included in the program, the macro versions (to be discussed later) are used. On the
other hand, if the programmer wishes to use the function versions they can be undefined after the
#include directive.
17. A preprocessor directive is terminated by the end of the line it occupies but if necessary it can be
continued onto one or more lines by ending all but the last line with backslashes.
Definition Section
In this section, we define a variable with some value in it. This is also known as a
special constant section. Here, a define statement is used. The general syntax of a
symbolic preprocessor or symbolic compiler directive can be defined using the following
#define statement:
1 | Computer Programming 1 10
Here the opening curly bracket “{” shows the starting of the main program while “}”
shows its end. The variables declared after these braces are known as local variables that is,
they have a scope local to this main function. Then comes the portion where the user writes
his or her program. This is known as the user-defined section.
ASSESSMENT
1 | Computer Programming 1 11