Notes, summaries, assignments, exams, and exercises for Computer science for Baccalaureate

Java File I/O, CSV, and Database Demo Tutorial

Computer science6.73 KB

Java File I/O, CSV, and Database Demo

This example demonstrates how to read and write text files, parse CSV data, and perform basic database operations using JDBC with UCanAccess and an MS Access database.

Required Imports

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

Class Declaration and Constants

public class Demo05 {

    private static final String IN_FILE = "./input.txt";
    private static final String OUT_FILE = "./output.txt";
    private static
...
Continue reading "Java File I/O, CSV, and Database Demo Tutorial" »

Sistema de Inventario de Libros en PHP

Computer science2.01 KB

Lectura del Inventario

$fich = fopen("inventario.txt", "r");
$aver = fgets($fich);
while (!feof($fich)) {
    $array = explode("-", $aver);
    echo "Título: " . $array[0] . "<br>Autor: " . $array[1] . "<br>Código: " . $array[2] . "<br>Precio: " . $array[3] . "<br>Cantidad: " . $array[4] . "<br>****************************<br>";
    $aver = fgets($fich);
}
fclose($fich);
?>

Busque su libro por título o por código

Buscar por...

CódigoTítulo
if (isset($_POST['enviar'])) {
    $busqueda = $_POST['opcion'];
    $buscar = $_POST['buscar'];
    if ($busqueda == "titulo") {
        $f1 = fopen("inventario.txt", "r");
        $linea = fgets($f1);
        $encontrado = false;
        while (!feof($f1)) {
...
Continue reading "Sistema de Inventario de Libros en PHP" »

Internet Fundamentals and Digital Communication Technologies

Computer science3.9 KB

Digital Communication and Internet Fundamentals

Electronic Presentations

Electronic presentations are information expositions combining the use of visual and auditory content.

Common programs include Microsoft Office and OpenOffice.org.

Benefits of Electronic Presentations

  • Guides the speaker during an exhibition.
  • Allows programmed animation effects.
  • Easy for the audience to follow and understand.

Applications of Electronic Presentations

  • Exposing class issues or educational topics.
  • Creating reports (business and general).
  • Submitting proposals.
  • Visually supporting a conference.

Core Internet Services and Applications

The Internet

The Internet is formed by a set of interconnected local and global networks.

Website and Hyperlinks

A Website is a collection of related...

Continue reading "Internet Fundamentals and Digital Communication Technologies" »

Mastering Multithreading: Synchronization and Concurrency

Computer science1.59 MB

qGVLGm2yySS1cN0JACAgBISAEhMC8R2DmvCdBFAgBISAEhIAQEAJCQAgIASHgCCDBiRQfEmxIryGJyIFMHD5jtvjSQQcdVEVFmp4DuuSEgBAQAkJACAiByYeAJNwmX5uIIiEgBISAEBACQkAICIFpjgCnWc+ZM6crCqilcnrurFmzusZRgBAQAkJACAgBITDvEBDDbd5hr5KFgBAQAkJACAgBISAEhEBXBG644Ybq4Jmrrroq29zceOON0+zZs9NOO+0kZltX5BQgBISAEBACQmDeIyCG27xvA1EgBISAEBACQkAICAEhIAR6IoBaKYdEtDksqmdGChQCQkAICAEhIAQmBAEx3CYEZhUiBISAEBACQkAICAEhIASEgBAQAkJACAgBITBdEJgxXSqqegoBISAEhIAQEAJCQAgIASEgBISAEBACQkAICIGJQEAMt4lAWWUIASEgBISAEBACQkAICAEhIASEgBAQAkJACEwbBMRwmzZNrYoKASEgBISAEBACQkAICAEhIASEgBAQAkJACEwEAmK4TQTKKkMICAEhIASEgBAQAkJACAgBISAEhIAQEAJCYNogIIbbtGlqVVQICAEhIASEgBAQAkJACAgBISAEhIAQEAJCYCIQEMNtIlBWGUJACAgBISAEhIAQEAJCQAgIASEgBISAEBAC0wYBMdymTVOrokJACAgBISAEhIAQEAJCQAgIASEgBISAEBACE4GAGG4TgbLKEAJCQAgIASEgBISAEBACQkAICAEhIASEgBCYNgiI4TZtmloVFQJCQAgIASEgBISAEBACQkAICAEhIASEgBCYCAT+HyWALbQbtlyiAAAAAElFTkSuQmCC
aUYra0n3POOTMqHP7ejoAj4Ag4Ao6AI+AIOAKOgCPQDQj8P+NhDYXW1R55AAAAAElFTkSuQmCC
kuoQAAAAAElFTkSuQmCC
AXrPdSYSRfcvAAAAAElFTkSuQmCC
mbeQTol1LPUPY27XQ683KlFIuACEwiASnGJrFUlCYREAEREAEREAEREAEREAEREAEREAEREIGxE5CNsbEjVgQiIAIiIAIiIAIiIAIiIAIiIAIiIAIiIAKTSECKsUksFaVJBERABERABERABERABERABERABERABERg7ASkGBs7YkUgAiIgAiIgAiIgAiIgAiIgAiIgAiIgAiIwiQSkGJvEUlGaREAEREAEREAEREAEREAEREAEREAEREAExk5AirGxI1YEIiACIiACIiACIiACIiACIiACIiACIiACk0hAirFJLBWlSQREQAREQAREQAREQAREQAREQAREQAREYOwEpBgbO2JFIAIiIAIiIAIiIAIiIAIiIAIiIAIiIAIiMIkEpBibxFJRmkRABERABERABERABERABERABERABERABMZOQIqxsSNWBCIgAiIgAiIgAiIgAiIgAiIgAiIgAiIgApNIQIqxSSwVpUkEREAEREAEREAEREAEREAEREAEREAERGDsBKQYGztiRSACIiACIiACIiACIiACIiACIiACIiACIjCJBKQYm8RSUZpEQAREQAREQAREQAREQAREQAREQAREQATGTkCKsbEjVgQiIAIiIAIiIAIiIAIiIAIiIAIiIAIiIAKTSECKsUksFaVJBERABERABERABERABERABERABERABERg7ASkGBs7YkUgAiIgAiIgAiIgAiIgAiIgAiIgAiIgAiIwiQT+F4vc9jGTjhomAAAAAElFTkSuQmCC


Understanding Synchronization

Synchronization ensures the correct ordering of instructions across threads. It relies on hardware support to achieve two primary concurrency objectives:

  • Mutual Exclusion: Solved using locks.
  • Ordering: Solved using locks and semaphores.

A condition variable acts as a queue for waiting threads. Maintain state alongside condition variables; they are used to signal threads when state changes. If the state is already as needed, the thread does not wait for a signal. Whenever a lock is acquired, recheck assumptions about the state. Some libraries experience spurious wakeups, where multiple threads may wake up unexpectedly. To wake the right thread, use specific condition variables per condition rather than waking all threads....

Continue reading "Mastering Multithreading: Synchronization and Concurrency" »

painlessMesh and namedMesh Arduino Examples for ESP Networks

Computer science3.14 KB

painlessMesh and namedMesh Examples

The following two sketches demonstrate how to build a wireless mesh network with the painlessMesh library on ESP8266 and ESP32 boards.

Example 1: Broadcasting with painlessMesh

#include "painlessMesh.h"

#define MESH_PREFIX "whateverYouLike"

#define MESH_PASSWORD "somethingSneaky"

#define MESH_PORT 5555

Scheduler userScheduler;

painlessMesh mesh;

void sendMessage();

Task taskSendMessage(TASK_SECOND * 1, TASK_FOREVER, &sendMessage);

void sendMessage() {
  String msg = "Hello from node ";
  msg += mesh.getNodeId();
  mesh.sendBroadcast(msg);
  taskSendMessage.setInterval(random(TASK_SECOND * 1, TASK_SECOND * 5));
}

void receivedCallback(uint32_t from, String &msg) {
  Serial.printf("startHere: Received from...

Continue reading "painlessMesh and namedMesh Arduino Examples for ESP Networks" »

Arduino Obstacle-Avoiding Robot with Servo Motors and Ultrasonic Sensor

Computer science3.03 KB

Arduino Obstacle-Avoiding Robot Code

#include <Servo.h>


Servo myservo; // crea el objeto servo
Servo rDerecha;
Servo rIzquierda;


#define irDerecho 3
#define irIzquierdo 2
#define ruedaD 9
#define ruedaI 8
#define echoPin 5
#define triggerPin 4



void setup() {
// put your setup code here, to run once:
pinMode(echoPin, INPUT);
pinMode(triggerPin, OUTPUT);
pinMode(irDerecho, INPUT);
pinMode(irIzquierdo, INPUT);
rDerecha.attach(ruedaD);
rIzquierda.attach(ruedaI);
myservo.attach(13); // vincula el servo al pin digital 13
}


void loop() {
// put your main code here, to run repeatedly
int valor;


valor = ping(triggerPin, echoPin);


if (valor < 10) {
parar(rDerecha, rIzquierda);
} else {
if (digitalRead(irDerecho) == LOW && digitalRead(
...
Continue reading "Arduino Obstacle-Avoiding Robot with Servo Motors and Ultrasonic Sensor" »

Librerías en Lenguaje C: Funciones Estándar y Sintaxis

Computer science5.29 KB

Librerías Estándar del Lenguaje C

A continuación se detallan las cabeceras principales de la biblioteca estándar de C (ANSI C) junto con sus funciones más representativas.

stdio.h: Entrada y Salida Estándar

La cabecera <stdio.h> provee capacidades esenciales para operaciones de entrada, salida y manejo de archivos.

  • clearerr
  • fclose
  • feof
  • ferror
  • fflush
  • fgetc
  • fgetpos
  • fgets
  • fopen
  • formato
  • fprintf
  • fputc
  • fputs
  • fread
  • freopen
  • fscanf
  • fseek
  • fsetpos
  • ftell
  • fwrite
  • getc
  • getchar
  • gets
  • perror
  • printf
  • putc
  • putchar
  • puts
  • remove
  • rename
  • rewind
  • scanf
  • setbuf
  • setvbuf
  • sprintf
  • sscanf
  • tmpfile
  • tmpnam
  • ungetc
  • vfprintf
  • vprintf
  • vsprintf

stdlib.h: Utilidades Generales y Memoria

La librería <stdlib.h> contiene funciones para gestión dinámica de memoria, control de procesos y conversiones numéricas.

  • abort
  • abs
  • atexit
  • atof
  • atoi
  • atol
  • bsearch
  • calloc
  • div
  • exit
  • free
  • getenv
  • labs
  • ldiv
  • malloc
  • mblen
  • mbstowcs
  • mbtowc
  • qsort
  • rand
  • realloc
  • srand
  • strtod
  • strtol
  • strtoul
  • system
  • wctomb

string.

...
Continue reading "Librerías en Lenguaje C: Funciones Estándar y Sintaxis" »

C# Currency Persistence Class Implementation

Computer science3.25 KB

Namespace Pers
{
    public class Persistencia
    {
        

Method: Add Currency (AniadirDivisa)

Adds a currency and its value to Divisas.txt if it does not already exist.

public static void AniadirDivisa(String d, double valor)
{
    if (!ExisteDivisa(d))
    {
        StreamWriter sw = new StreamWriter(@"Divisas.txt", true);
        sw.WriteLine(d + "\t" + valor);
        sw.Close();
    }
}

Method: Get Currency Value (ValorDivisa)

Retrieves the value associated with a specific currency symbol.

public static double ValorDivisa(String d)
{
    String v = "";
    StreamReader sr = new StreamReader(@"Divisas.txt");
    String l = sr.ReadLine();
    while (l != null)
    {
        if (l.Contains(d))
        {
            // Extracts the value
...
Continue reading "C# Currency Persistence Class Implementation" »

Exercício de Herança em Java: Conta Bancária, Corrente e Poupança

Computer science4.32 KB

Exercício - Banco

Classe abstrata ContaBancaria

package ExercicioHeranca;

import java.util.Scanner;

public abstract class ContaBancaria {

protected int senha;

protected int numero;

protected double saldo;

public ContaBancaria(int senha) {

this.senha = senha;

}

public abstract void saca(double valor);

public abstract void deposita(double valor);

public abstract double tiraExtrato();

public void alteraSenha(int senha_nova) {

Scanner in = new Scanner(System.in);

System.out.println("Entre a senha atual: ");

int senha_digitada = in.nextInt();

if (senha_digitada == this.senha) {

this.senha = senha_nova;

System.out.println("Senha trocada");

} else {

...

Continue reading "Exercício de Herança em Java: Conta Bancária, Corrente e Poupança" »

Inter-VLAN Routing and Wireless LAN Fundamentals

Computer science2.74 KB

Inter-VLAN Routing

Inter-VLAN routing is the process of forwarding network traffic from one VLAN to another via a router. As shown in the figure, traffic from PC1 in VLAN10 is routed through the router to reach PC3 in VLAN30.

Traditional Routing

Traditionally, routing the LAN using routers involves multiple interfaces. You must connect each interface to a separate network and configure it to a different subnet.

Router-on-a-Stick Configuration

"Router-on-a-stick" is a configuration where a single physical interface routes traffic between multiple VLANs on a network.

Subinterfaces

Subinterfaces are multiple virtual interfaces associated with a single physical interface. These software interfaces are configured on a router independently with an IP address...

Continue reading "Inter-VLAN Routing and Wireless LAN Fundamentals" »