Notes, summaries, assignments, exams, and problems for Computers

Sort by
Subject
Level

Mastering Python String Methods and Syntax

Posted by Anonymous and classified in Computers

Written on in English with a size of 2.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" »

C++ Programming: Streams, Functions, and Memory

Posted by Anonymous and classified in Computers

Written on in English with a size of 11.17 KB

In C++, Input/Output (I/O) operations are managed through a hierarchy of classes collectively known as streams. A stream is an abstraction that represents a flow of data between a source (like a keyboard) and a destination (like a screen).

Here is a comprehensive breakdown of how C++ handles both unformatted and formatted I/O operations, along with the core stream mechanisms.

Streams, Insertion, and Extraction

At the heart of C++ I/O are the standard stream objects:

  • cin: Standard input stream (usually the keyboard), an instance of istream.
  • cout: Standard output stream (usually the screen), an instance of ostream.

The Insertion Operator (<<)

Used with cout to output data. It "inserts" data into the output stream.

cout << "Hello, World!";
... Continue reading "C++ Programming: Streams, Functions, and Memory" »

Java Inheritance and Polymorphism Examples

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.49 KB

Single Inheritance in Java

This Single Inheritance program demonstrates how a child class inherits properties and methods from a single parent class.

class Animal {
    // Constructor of Parent class
    Animal() {
        System.out.println("Animal constructor called");
    }
    // Method of Parent class
    void eat() {
        System.out.println("I can eat");
    }
}

// Child class inheriting from Animal
class Dog extends Animal {
    // Constructor of Child class
    Dog() {
        System.out.println("Dog constructor called");
    }
    // Method of Child class
    void bark() {
        System.out.println("I can bark");
    }
}

// Main class to test inheritance
public class Main {
    public static void main(String[] args) {
        /
... Continue reading "Java Inheritance and Polymorphism Examples" »

PHP Programming Essentials and Core Features

Classified in Computers

Written on in English with a size of 2.95 KB

What is PHP?

PHP (Hypertext Preprocessor) is a widely-used open-source scripting language primarily designed for web development. It runs on the server-side, meaning the code is executed on the web server before the output is sent to the user's browser. PHP is embedded within HTML and supports various databases, making it a powerful tool for creating dynamic and interactive web applications.

Key Features of PHP

PHP has several features that make it a popular choice for web development:

  • Open-Source – PHP is free to use, with a large community of developers providing support and updates.
  • Cross-Platform Compatibility – PHP works on multiple operating systems like Windows, Linux, and macOS.
  • Easy to Learn and Use – Its syntax is simple and similar
... Continue reading "PHP Programming Essentials and Core Features" »

Bitcoin Consensus and Ethereum Smart Contracts

Classified in Computers

Written on in English with a size of 106.85 KB

Bitcoin Consensus

The Problem: Decentralized Network

  • Bitcoin operates without a central authority; all users must agree on transaction history.
  • It faces the Byzantine Generals Problem; although unknown to each other, participants must establish trust.
  • Trust is established using consensus protocols, incentives, and cryptography.

How It Works

  • The Bitcoin algorithm operates on nodes.
  • Any device (computer) running the full Bitcoin software and connected to the internet acts as a connection point for creating blocks and verifying transactions.
  • When a block is created, nodes communicate to verify the transactions and ensure they follow the algorithm's rules.
  • Each node maintains a complete copy of the Bitcoin blockchain.

Participants in the Ecosystem

  • Full Nodes:
... Continue reading "Bitcoin Consensus and Ethereum Smart Contracts" »

C++ Code Examples: Arithmetic Mean, Sum, Product, Square

Classified in Computers

Written on in English with a size of 1.55 KB

Arithmetic Mean

The following C++ code calculates the arithmetic mean of numbers from 1 to n:

int main() {
    int n;
    double suma = 0;
    cout << "Vnesi broj: ";
    cin >> n;
    if (n <= 0) {
        cout << "Brojot na elementi mora da bide pogolem od 0!" << endl;
        return 1;  
    }
    for (int i = 1; i <= n; i++) {
        suma += i;  
    }
    double sredina = suma / n;
    cout << "Aritmetichkata sredina na broevite od 1 do " << n << " e: " << sredina << endl;
    return 0;
}

Sum

The following C++ code calculates the sum of numbers from 1 to n:

int main() {
    int n, sum = 0;
    cout << "Vnesi broj n: ";
    cin >> n;
    for (int i = 1; i <= n; i++)
... Continue reading "C++ Code Examples: Arithmetic Mean, Sum, Product, Square" »

Network Security & Configuration: Routing, VLANs, DHCP, and Attack Mitigation

Classified in Computers

Written on in English with a size of 2.38 KB

Router-on-a-Stick Inter-VLAN Routing

The router's port connecting to the LAN has multiple sub-interfaces, each the default gateway for a specific VLAN. For example, VLAN 10 traffic destined for VLAN 20 is first forwarded to VLAN 10's default gateway (the router sub-interface). The router then routes this traffic to VLAN 20's gateway (its corresponding sub-interface) and finally to the user in VLAN 20.

Why STP Is Needed for Redundant Ethernet LANs

  • Preventing Broadcast Storms: In redundant networks, frames can loop endlessly, exponentially increasing traffic. STP prevents this by disabling redundant paths, ensuring one active path between devices.
  • Ensuring MAC Address Table Consistency: Loops cause switches to receive the same frame on different
... Continue reading "Network Security & Configuration: Routing, VLANs, DHCP, and Attack Mitigation" »

Python Programming Essentials: Core Concepts & Techniques

Classified in Computers

Written on in English with a size of 1.35 MB

Understanding Variables & Data Types

Variables: Storing Data

Variables are containers used to store data. They are assigned values using the = operator (e.g., x = 5).

Essential Data Types

Python supports several fundamental data types:

  • int: Represents integer numbers (e.g., 10, -5).
  • float: Represents floating-point numbers (e.g., 3.14, -0.01).
  • str: Represents strings of characters (e.g., "hello", "123").
  • bool: Represents Boolean values, either True or False.

GOQmZWnx2PAAAAABJRU5ErkJggg==

Type Casting: Converting Data Types

Type casting allows you to convert data from one type to another using functions like int(), float(), and str().

Example: x = int("5") converts the string "5" to an integer. y = float("3.14") converts the string "3.14" to a float.

Input and Output Operations

Getting

... Continue reading "Python Programming Essentials: Core Concepts & Techniques" »

Banker's Algorithm Implementation in C

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.52 KB

This program demonstrates the Banker's Algorithm, a classic deadlock avoidance strategy used in operating systems to manage resource allocation safely.

C Source Code

#include <stdio.h>

int n, m;
int alloc[10][10], max[10][10], need[10][10];
int avail[10], work[10], finish[10];

// Safety Algorithm
int checkSafety() {
    int seq[10], count = 0;

    for (int i = 0; i < n; i++) finish[i] = 0;
    for (int i = 0; i < m; i++) work[i] = avail[i];

    while (count < n) {
        int found = 0;
        for (int i = 0; i < n; i++) {
            if (!finish[i]) {
                int j;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > work[j]) break;
                }
                if (j == m)
... Continue reading "Banker's Algorithm Implementation in C" »

Classic Algorithm Solutions: Step-by-Step Examples

Posted by Anonymous and classified in Computers

Written on in English with a size of 5.78 KB

1) DIJKSTRA (SSSP) — STEP TABLE (PAST-PAPER INSTANCE A)

Given edges: a→b(2), a→c(7), a→e(10), b→d(2), c→d(1), c→g(2), d→f(2), e→g(1), f→g(2). Source = a.
Rule: Pick unsettled vertex with minimum dist; relax outgoing edges.

Vertices:   a   b   c   d   e   f   g

Init:
Dist      = 0   2   7   ∞  10   ∞   ∞
S = ∅

Step 1: Pick a (min=0), S={a}
Relax from a: already set b=2, c=7, e=10
Dist      = 0   2   7   ∞  10   ∞   ∞

Step 2: Pick b (min=2), S={a,b}
Relax b→d: dist(d) = dist(b)+2 = 2+2 = 4
Dist      = 0   2   7   4  10   ∞   ∞

Step 3: Pick d (min=4), S={a,b,d}
Relax d→f: dist(f) = 4+2 = 6
Dist      = 0   2   7   4  10   6   ∞

Step 4: Pick f (min=6), S={a,b,d,f}
Relax f→g: dist(g) = 6+2 = 8
Dist
... Continue reading "Classic Algorithm Solutions: Step-by-Step Examples" »