Notes, summaries, assignments, exams, and problems for Computer science

C Programming: Arrays, Structs, and Pointers Explained

Computer science3.22 KB

1. Defining a Car Structure in C

Define a structure suitable for the following details of a car: Brand, Category (compact, family), Model, Engine Size, and Year.

Answer:

struct Datos_auto {
  char brand[30];
  char model[10];
  char category[30];
  int year;
  int size;
};

4. Array Index Out of Bounds

What happens if you assign a value to an element of an array whose index exceeds the array size?

Answer: It will overwrite data in adjacent memory locations.

5. Array Name Representation

If an array is declared as int list[12];, what does the word list represent?

Answer: It represents the array name (which also acts as a pointer to the first element).

6. Definition of a String in C

In the C language, what is a string?

Answer: A string is a composite data

...
Continue reading "C Programming: Arrays, Structs, and Pointers Explained" »

System Network Interface Configuration Details

Computer science3.71 KB

Network Interface Activation

Instructions for managing network interfaces: These describe the network interfaces available on your system.

  • Activate the loopback network interface (the computer itself).

Interface Configuration Example (Assuming 'eth0')

Target Interface (e.g., eth0):

Automatic DHCP:

auto eth0
iface eth0 inet dhcp

Static IP Configuration

Adding Static IP Configurations (Class A Example):

iface eth0 inet static
    address 10.0.0.4
    netmask 255.0.0.0
    gateway 10.0.0.1

DNS Server Configuration

DNS Servers for the Client Host: Configuration is performed in /etc/resolv.conf.

The following entries define the DNS servers:

# search example.com
nameserver 72.125.134.133
nameserver 220.11.126.131
nameserver 72.125.134.132
nameserver 224.
...
Continue reading "System Network Interface Configuration Details" »

Operating System Core Functions and Digital Signature Essentials

Computer science3.12 KB

Operating System Core Functions

A program in execution requires resources for its tasks. The Operating System (OS) is responsible for managing these resources through various core functions.

Process Management

The OS is responsible for:

  • Creating and destroying processes.
  • Pausing and resuming processes.
  • Providing mechanisms to communicate and synchronize processes.

Memory Management

Memory is a table of words, each referenced using a unique address. The OS is accountable for:

  • Knowing which parts of memory are used and by whom.
  • Deciding which processes are loaded into memory when space is available.
  • Assigning and reclaiming memory space when needed.

Secondary Storage Management

Secondary storage is necessary because main memory is volatile and often too small...

Continue reading "Operating System Core Functions and Digital Signature Essentials" »

C Program for Matrix Addition using Arrays and Functions

Computer science3.8 KB

This document presents two methods for implementing matrix addition in C: a monolithic approach within the main function and a modular approach utilizing separate functions for input, calculation, and display. Both examples handle 2D arrays up to 100x100 dimensions.

Method 1: Monolithic Implementation in main()

This initial approach places all logic—input handling, calculation, and output—directly within the main function. The code below has been corrected for proper C syntax, including loop conditions and scanf format specifiers.

Corrected C Code Snippet 1

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

void main(void) {
    float a[100][100], b[100][100], c[100][100];
    int rows, columns, i, j;

    printf("Enter number of rows: ");
...
Continue reading "C Program for Matrix Addition using Arrays and Functions" »

Essential Python Programming Examples and Algorithms

Computer science4.88 KB

Binary Search Algorithm

The Binary Search algorithm is an efficient way to find a target value within a sorted array.

arr = [10, 20, 30, 40, 50, 60, 70]
key = int(input("Enter number to search: "))

low = 0
high = len(arr) - 1

while low <= high:
    mid = (low + high) // 2

    if arr[mid] == key:
        print("Element found at index", mid)
        break
    elif arr[mid] < key:
        low = mid + 1
    else:
        high = mid - 1
else:
    print("Element not found")

Finding the Largest Element

This snippet demonstrates how to iterate through a list to identify the maximum value.

numbers = [10, 25, 8, 45, 30]

largest = numbers[0]

for i in numbers:
    if i > largest:
        largest = i

print("Largest element is:", largest)

Linear

...
Continue reading "Essential Python Programming Examples and Algorithms" »

Python String Methods and Character Functions

Computer science4.03 KB

Explain 1. ord() and chr(), 2. in and not in Operators

1. ord() and chr() Functions

Python provides the ord() and chr() functions for converting between characters and their Unicode values.

  • ord() converts a character into its corresponding Unicode (ASCII) integer value.
  • chr() converts a Unicode integer value into its corresponding character.

These functions are useful in character manipulation, encoding, encryption, and text processing applications.

Example

print(ord('A'))
print(ord('a'))
print(chr(65))
print(chr(97))

Output

65
97
A
a

2. in and not in Operators on Strings

The in and not in operators are called membership operators in Python. They are used to check whether a character, word, or substring exists in a string.

  • in returns True if the specified value
...
Continue reading "Python String Methods and Character Functions" »

White Box Testing Techniques and Unit Testing Principles

Computer science8.98 KB

What is White Box Testing?

White Box Testing (also known as Clear Box, Glass Box, Structural, or Open Box Testing) is a software testing method where the internal structure, design, and implementation of the code are fully visible and known to the tester. Unlike Black Box testing, where you only focus on inputs and outputs, White Box testing requires you to look "under the hood." The tester inspects the actual source code, control flows, data structures, and logic paths to ensure everything operates correctly, securely, and efficiently.

The Need for White Box Testing

While Black Box testing ensures that the software satisfies the user's requirements, White Box testing is essential to guarantee internal code quality and stability. Here is why it...

Continue reading "White Box Testing Techniques and Unit Testing Principles" »

Theory of Computation: Solved Questions on Automata

Computer science9.55 KB

DFA vs NFA: Key Differences

Deterministic Finite Automata (DFA) vs Nondeterministic Finite Automata (NFA):

Deterministic Finite Automata (DFA)

  • For each input symbol, only one transition is possible.
  • No ε (epsilon) transitions are allowed.
  • The transition function gives exactly one next state.
  • Easier to implement in code.

Nondeterministic Finite Automata (NFA)

  • For one input symbol, multiple transitions may be possible.
  • ε-transitions may exist.
  • The transition function gives zero, one, or many next states.
  • Easier to design.

Pumping Lemma for Regular Languages

Statement

If L is a regular language, then there exists a pumping length p such that any string w in L with |w| ≥ p can be written as:

w = xyz

such that:

  1. |xy| ≤ p
  2. |y| > 0
  3. xynz ∈ L for all n ≥ 0

Primary

...
Continue reading "Theory of Computation: Solved Questions on Automata" »

Mastering jQuery, Regex, and JavaScript Objects

Computer science4.02 KB

jQuery: Simplify Your JavaScript

jQuery is a fast, small, and popular JavaScript library. Its motto is "Write less, do more." Before jQuery, writing plain JavaScript for interactivity required complex code that often behaved inconsistently across browsers. jQuery wraps these tasks into simple, short commands that work perfectly everywhere.

Think of it as a handy shortcut dictionary for JavaScript.

The Basic Syntax

Every jQuery command follows this pattern:

  • $: Points to jQuery, signaling its use.
  • (selector): Finds the HTML element to modify.
  • .action(): Defines the operation (e.g., hiding, styling, or animating).

1. jQuery Selectors

Selectors "grab" HTML elements using CSS-style syntax.

  • Element Selector: $("p") selects all paragraph tags.
  • ID Selector: $
...
Continue reading "Mastering jQuery, Regex, and JavaScript Objects" »

Mastering Python String Methods and Syntax

Computer science2.83 KB

Case Manipulation Methods

  • title(): Displays each word in a string in Title Case, where every word begins with a capital letter.
  • upper(): Converts every character in a string to all uppercase letters.
  • lower(): Converts every character in a string to all lowercase letters. This is particularly useful for normalizing user input before storing it.

Whitespace Stripping Methods

Python considers whitespace (tabs, spaces, etc.) significant. Use these methods to clean up extra spacing:

  • rstrip(): Removes whitespace from the right side (end) of a string.
  • lstrip(): Removes whitespace from the left side (beginning) of a string.
  • strip(): Removes whitespace from both the beginning and the end of a string simultaneously.

Related Data Type Conversion

  • str(): While not
...
Continue reading "Mastering Python String Methods and Syntax" »