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

C Programming: Matrix Data Transfer and Calculations

Computer science4.45 KB

Matrix Data Transfer Example

This section presents C code intended to transfer data between matrices based on region identifiers.

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

int main () {
    int a[64][4];
    int b[3][15];
    int i, region, sum_asup, sum_ahab, j;

    j = 0;
    region = 1;
    sum_asup = 0; // Initialize sums
    sum_ahab = 0; // Initialize sums

    // Assuming 'a' matrix is populated with data
    for (i = 0; i < 64; i++) { // Corrected loop condition
        if (a[i][0] == region) {
            sum_asup = sum_asup + a[i][2];
            sum_ahab = sum_ahab + a[i][3];
        }
        
        // Check if the next element belongs to a different region or if it's the end of the array
        if (i + 1 < 64
...
Continue reading "C Programming: Matrix Data Transfer and Calculations" »

Program Translators: Compilers, Interpreters, and Execution

Computer science3.39 KB

Program Translators: Compilers and Interpreters

Programs written in a programming language need to be translated into machine code to be executed by the CPU. This task is carried out by translators.

Translators can be categorized into two main types based on the translation process:

  • Interpreters: Take the original program (source code), translate each instruction, and execute it immediately.
  • Compilers: Take the source code, translate it completely into object code, and then the translated program is executed.

The Compilation Process: Object Code and Linking

After compiling a program, the result is known as object code. Object code is a new program written in a language very similar to machine code, but it is still not executable by the CPU.

Following...

Continue reading "Program Translators: Compilers, Interpreters, and Execution" »

Understanding IEEE 802 Standards for Networking

Computer science2.88 KB

Model 802
IEEE defined in the 80s
Responsible for defining communication,
transmission, and use of LANs.

802.1: Definition Network International
We define that the network devices should be identified by 48 bits where the first 3 bytes are defined by the IEEE. This identifier must be unique for each product.

802.2: Logical Link Control (LLC)
It defines the controls for the transmission, i.e., defines handshaking.

802.3: Method of Access to the Medium
It defines the access method or wireless LAN, and collisions are resolved by the present CSMA/CA and CSMA/CD.

802.5: Token Ring
It defines the logical and physical topologies of Token Ring.

802.11: Wireless Networks (WiFi)
Establishes standards for speed, frequency, and scope in local wireless transmissions....

Continue reading "Understanding IEEE 802 Standards for Networking" »

Printer Technology Comparison: Daisy Wheel to Laser

Computer science2.27 KB

Printer Technology Comparison

Translation 2

Printers

Daisy Wheel Printer

The highest quality of printer available is the daisy wheel with flexible stems radiating from the center. The letters are well-defined and can be read clearly. The printer moves bi-directionally, printing both ways from left to right and then right to left. Remember that what is to be printed already exists in the computer's memory, and the daisy wheel does not have to type in sequence as would be expected from a human brain. The carriage therefore does not need to waste time returning at the end of each line.

Dot Matrix Printer

The dot matrix is usually faster than the daisy wheel. The printer has a print head consisting of a row of needles. This moves speedily over the place...

Continue reading "Printer Technology Comparison: Daisy Wheel to Laser" »

C Programming: Transaction and Vehicle Structs

Computer science6.92 KB

Section A: Transaction Data Management

Defining the Transaction Structure

A. Create a structure Transaction with the following attributes: ID (integer number), account_number (array of characters), amount (float), and typology (character).

typedef struct {
    char plate_number[PLATELENGTH + 1];
    char brand[NAMELENGTH];
    char model[NAMELENGTH];
    int production_year;
} Vehicle;

Constants for Transaction Typology

A. Define the max length for the attribute "account" to 20, and two constants to determine the typology of the transaction, such as CREDIT or DEBIT (respectively 'c' and 'd').

#define MAX_ACCOUNT_LEN 20
#define CREDIT 'c'
#define DEBIT 'd'

Reading Transaction Data from Input

A. Create a method named readInstance() that reads from the...

Continue reading "C Programming: Transaction and Vehicle Structs" »

JavaScript Evolution: JSONP and 3D Data Structures

Computer science4.27 KB

JavaScript: A Fast-Growing Language

JavaScript is a fast-growing language, with a lot of features being added to every release! These include:

  • JSONP
  • Arrow functions
  • Arguments and call arguments
  • Rest parameters
  • Blob and DOMString
  • A download button
  • apply() vs call()

Understanding JSONP (JSON with Padding)

JSONP (JSON with Padding) was a technique used before modern CORS support to get data from another website. JSONP (JavaScript Object Notation with Padding) is an older technique used to retrieve data from a server when normal AJAX requests using XMLHttpRequest (XHR) or fetch() are blocked by the browser's Same-Origin Policy.

Normally, when a client requests data from a server, the server returns plain JSON, such as { "value": 123 }, which is then parsed...

Continue reading "JavaScript Evolution: JSONP and 3D Data Structures" »

Essential C Programming Algorithms and Data Structures

Computer science3.78 KB

1. Infix to Postfix Conversion

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

char stack[20];
int top = -1;

void push(char x) { stack[++top] = x; }
char pop() { return stack[top--]; }

int priority(char x) {
    if (x == '(') return 0;
    if (x == '+' || x == '-') return 1;
    if (x == '*' || x == '/') return 2;
    if (x == '^') return 3;
    return 0;
}

void main() {
    char exp[20];
    int i;
    char x;
    clrscr();
    printf("Enter Infix Expression: ");
    scanf("%s", exp);
    printf("Postfix Expression: ");
    for (i = 0; exp[i] != '\0'; i++) {
        if (isalnum(exp[i])) printf("%c", exp[i]);
        else if (exp[i] == '(') push(exp[i]);
        else if (exp[i] == ')') {
            while ((x =
...
Continue reading "Essential C Programming Algorithms and Data Structures" »

Essential CSS and HTML Techniques for Web Development

Computer science2.77 KB

Understanding CSS text-overflow

The text-overflow property in CSS specifies how overflowed content that is not displayed should be signaled to the user. It works only when text exceeds the container size.

Required Conditions

To use text-overflow, the following properties must be applied:

  • overflow: hidden;
  • white-space: nowrap;
  • Fixed width

Values of text-overflow

  • clip: Default behavior; cuts off text without showing any symbol.
  • ellipsis: Shows “...” at the end of truncated text.
<style>
.clipText { width: 200px; white-space: nowrap; overflow: hidden; text-overflow: clip; border: 1px solid #000; }
.ellipsisText { width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid red; }
</style>
<div class=
...
Continue reading "Essential CSS and HTML Techniques for Web Development" »

Essential PHP Programming: Forms, Databases, and Sessions

Computer science2.37 KB

PHP Form Validation

To create a PHP form and perform server-side validation for user input such as name, email, and password:

<?php
$name = $email = $password = "";
$nameErr = $emailErr = $passwordErr = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Name Validation
    if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = $_POST["name"]; }
    // Email Validation
    if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = $_POST["email"];
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } 
    }
    // Password Validation
    if (empty($_POST["password"])) { $passwordErr = "Password is required"; } else { $password = $_POST["password"];
...
Continue reading "Essential PHP Programming: Forms, Databases, and Sessions" »

Mastering CSS Box Model and JavaScript Fundamentals

Computer science9.13 KB

The CSS Box Model Fundamentals

The CSS Box Model is the absolute foundation of web layout and design. In CSS, virtually every HTML element is treated as an invisible, rectangular box. The Box Model is the set of rules that defines how the dimensions, spacing, and borders of these boxes behave and interact with each other.

The Four Layers of the Box Model

Every CSS box consists of four layers, nesting inside one another like Russian nesting dolls. Moving from the innermost layer to the outermost layer:

1. Content

This is the core of the box where your actual content lives—such as text, an image, or a video. Its dimensions are controlled by the width and height properties.

2. Padding (Inside Space)

Padding is the clear space around the content, but...

Continue reading "Mastering CSS Box Model and JavaScript Fundamentals" »