Software Development Concepts: Top-Down, Cohesion, and More

Software Development Concepts

Top-Down ApproachBottom-Up Approach
1. Focuses on breaking problems into smaller parts.1. Solves smaller problems and integrates them into a complete solution.
2. Mainly used by structured programming languages like COBOL, Fortran, C.2. Mainly used by object-oriented programming languages like C++, C#, Python.
3. Each part is programmed separately, potentially containing redundancy.3. Redundancy is minimized by using data encapsulation and data hiding.
4. Communication among modules is less.4. Modules must have communication.
5. Used in debugging and module documentation.5. Primarily used in testing.
CohesionCoupling
1. Measures the degree of relationship between elements of a module.1. Measures the degree of relationship between different modules.
2. An intra-module concept.2. An inter-module concept.
3. Represents the functional strength of the modules.3. Represents the independence among the modules.
4. High cohesion leads to high-quality software.4. Loose coupling leads to high-quality software.
5. A module focuses on a single thing.5. Modules are connected to each other.
Deterministic TechniqueNon-Deterministic Technique
1. For a particular input, the program always gives the same output.1. For a particular input, the program may produce different outputs on different executions.
2. Can solve the problem in polynomial time.2. Cannot solve the problem in polynomial time.
3. Can determine the next step of execution.3. Cannot determine the next step of execution due to multiple possible paths.
RecursionIteration
1. A function calls itself to perform a repeated task.1. Uses loops to perform repeated tasks.
2. Follows a top-down approach, dividing the problem into pieces.2. Follows a bottom-up approach, constructing the solution step by step.
3. A function calls itself until a condition is satisfied.3. A function does not call itself.
4. Always applied to functions.4. Applied to a set of instructions.
5. Uses a stack to store recursive calls.5. Does not require a stack.
6. Reduces the size of program code.6. Iterations can make code longer compared to recursion.
CompilerInterpreter
1. Saves machine language as machine code on disks.1. Does not save machine language.
2. Generates an output in the form of (.exe).2. Does not generate any output.
3. Mostly used in production environments.3. Mostly used in programming and development environments.
4. Object code is permanently saved for future use.4. No object code is saved for future use.
5. C, C++, C# are compiler-based languages.5. Python, Ruby, Perl, MATLAB are interpreter-based languages.
While LoopDo-While Loop
1. The condition is tested before any statement is executed.1. The statement is executed at least once, even if the condition is false.
2. Syntax: while(condition) { // statements }2. Syntax: do { //statements } while(expression);
3. No semicolon is needed after the end of the condition.3. Semicolon is needed after the end of the condition.
4. An entry-controlled loop.4. An exit-controlled loop.
5. May or may not be executed at all.5. Will execute at least once.
6. Can lead to errors if the condition is always false.6. Helps prevent errors as it runs at least once.
Library FunctionUser-Defined Function
1. Predefined in the compiler of the C language.1. Not predefined in the compiler.
2. Not created by users.2. Created by users as per their requirements.
3. Stored in a special library file.3. Not stored in library files.
4. Execution does not begin from the library function.4. Execution begins from the user-defined function.
5. Examples: printf(), scanf(), sqrt(), etc.5. Examples: sum(), fact(), etc.


Implicit ConversionExplicit Conversion
1. Done automatically.1. Done programmatically.
2. No data loss occurs during conversion.2. Data loss may or may not occur.
3. Does not require any special syntax.3. Requires a cast operator to perform conversion.
4. Example: int a=21, b=a;4. Example: float a=32.32; int b=(int) a;

Dynamic Memory Allocation (DMA)

#include <stdio.h>
#include <stdlib.h>

int main() {
    int N, i, *numbers, largest, smallest;

    printf("Enter the number of elements: ");
    scanf("%d", &N);

    numbers = (int *)malloc(N * sizeof(int));
    if (numbers == NULL) {
        printf("Memory allocation failed.\n");
        return 1;
    }

    printf("Enter %d numbers:\n", N);
    for (i = 0; i < N; i++) {
        scanf("%d", &numbers[i]);
    }

    largest = smallest = numbers[0];

    for (i = 1; i < N; i++) {
        if (numbers[i] > largest) largest = numbers[i];
        if (numbers[i] < smallest) smallest = numbers[i];
    }

    printf("Largest: %d\n", largest);
    printf("Smallest: %d\n", smallest);

    free(numbers);
    return 0;
}

File Handling

#include <stdio.h>

int main() {
    FILE *source, *destination;
    char ch;

    source = fopen("student.txt", "r");
    if (source == NULL) {
        printf("Error: Cannot open source file.\n");
        return 1;
    }

    destination = fopen("info.txt", "w");
    if (destination == NULL) {
        printf("Error: Cannot open destination file.\n");
        fclose(source);
        return 1;
    }

    while ((ch = fgetc(source)) != EOF) {
        fputc(ch, destination);
    }

    printf("File copied successfully.\n");

    fclose(source);
    fclose(destination);
    return 0;
}

Reverse Number

#include <stdio.h>

int main() {
    int num, reversed = 0, sum = 0, count = 0, digit;
    float avg;

    printf("Enter a number: ");
    scanf("%d", &num);

    int originalNum = num;

    while (num != 0) {
        digit = num % 10;
        reversed = reversed * 10 + digit;
        sum += digit;
        count++;
        num /= 10;
    }

    avg = (float)sum / count;

    printf("Reversed Number: %d\n", reversed);
    printf("Sum of digits: %d\n", sum);
    printf("Average of digits: %.2f\n", avg);

    return 0;
}

Call by Value

#include <stdio.h>

void swapByValue(int a, int b) {
    int temp = a;
    a = b;
    b = temp;
    printf("Inside swapByValue: a = %d, b = %d\n", a, b);
}

int main() {
    int x = 5, y = 10;

    printf("Before swapByValue: x = %d, y = %d\n", x, y);
    swapByValue(x, y);
    printf("After swapByValue: x = %d, y = %d\n", x, y);

    return 0;
}

Call by Reference

#include <stdio.h>

void swapByReference(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int x = 5, y = 10;

    printf("Before swapByReference: x = %d, y = %d\n", x, y);
    swapByReference(&x, &y);
    printf("After swapByReference: x = %d, y = %d\n", x, y);

    return 0;
}