Notes, summaries, assignments, exams, and exercises for Computer science for Secondary education

5 Essential Computer System Hardware Components Explained

Computer science1.76 KB

Computer System Components

There are five main hardware components in a computer system: Input, Processing, Storage, Output, and Communication devices. These devices are used for entering data or instructions into the central processing unit.

The Five Basic Components of a Computer System

  • Input Unit: Data and instructions must enter the computer system before any computation can be performed. The input unit links the external environment with the computer system to perform this task.
  • Output Unit: The job of an output unit is the reverse of an input unit. It supplies information and results of computation to the outside world, linking the computer with the external environment.
  • Storage Unit: Data and instructions entered through input units must
...
Continue reading "5 Essential Computer System Hardware Components Explained" »

Solving the Knapsack Problem in Java: Greedy Approach with Code Example

Computer science2.3 KB

Solving the Knapsack Problem in Java

public class ProblemaMochila {

public ProblemaMochila() {

}

public ArrayList<ItemRoubo> resolver(ArrayList<ItemRoubo> totalItems, int max_items, int peso_max) {

ArrayList<ItemRoubo> mochila = new ArrayList<ItemRoubo>(max_items);

Collections.sort(totalItems);

double pesoMochila = 0;

int posicao = 0;

while (pesoMochila < peso_max && posicao < totalItems.size()) {

ItemRoubo tmp = totalItems.get(posicao);

if (pesoMochila + tmp.getPeso() <= peso_max) {

mochila.add(tmp);

pesoMochila += tmp.getPeso();

}

posicao++;

}

return mochila;

}

}

Main

...
Continue reading "Solving the Knapsack Problem in Java: Greedy Approach with Code Example" »

Java Method to Load Race Data from a Database into a List

Computer science2.35 KB

Método llenarLista()


Este método carga las carreras desde la base de datos y las agrega a una lista, junto con las posiciones de cada carrera y los puntos de los pilotos.

private void llenarLista() {
    try {
        modeloLista = (DefaultListModel) lista.getModel();
        Statement sentenciaCarreras = conexion.createStatement();
        String sql = "SELECT * FROM carreras ORDER BY ncarrera;";
        java.sql.ResultSet rsCarreras = sentenciaCarreras.executeQuery(sql);
        System.out.println(sql);
        int nCarrera;
        java.util.Date fecha; /* PARA DIFERENCIAR java.util DE java.sql */
        String nombre;
        String circuito;
        double km;
        int nVueltas;
        javax.swing.ImageIcon mapa;
        while (rsCarreras.
...
Continue reading "Java Method to Load Race Data from a Database into a List" »

Java Dataset Class: Reading, Parsing and Exporting CSV Data

Computer science6.1 KB

Java Dataset Class for Reading and Exporting Delimited Files

The following ConjuntoDatos class is part of the org.mp.sesion06 package. It reads a delimited text file, stores its header and numeric values, and can export selected columns to a new file.

package org.mp.sesion06;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;

public class ConjuntoDatos {

    private File archivoTexto;
    private String separador;
    private Locale locale;
    private List<String> cabecera;
    private int numeroLineas;
    private int numeroColumnas;
...
Continue reading "Java Dataset Class: Reading, Parsing and Exporting CSV Data" »

Java String, Matrix and MySQL JDBC Code Examples

Computer science3.47 KB

Java String Manipulation

Private Attribute

private String lectura;

Obtain N Characters

// Obtain N characters

public String obtieneCar(int numCar) {
    String caract;
    caract = lectura.substring(0, numCar);
    return caract;
}

Check String

// Check whether a substring is contained

public boolean compruebaString(String sub) {
    if (lectura.contains(sub)) {
        return true;
    } else {
        return false;
    }
}

Count Characters

// Count occurrences of a character

public int cuentaCar(char car) {
    int contador = 0;
    for (int i = 0; i < lectura.length(); i++) {
        if (lectura.charAt(i) == car) {
            contador++;
        }
    }
    return contador;
}

Reverse

...
Continue reading "Java String, Matrix and MySQL JDBC Code Examples" »

C++ Programi za Delo z Nizi: Vnos, Izpis in Obdelava

Computer science5.23 KB

C++ Programi za Delo z Nizi

Spodaj so zbrani primeri programov v jeziku C++, ki obdelujejo nize: vnos, izpis, obračanje, primerjavo, štetje besed, zamenjavo in izbris znakov ter preverjanje palindroma.

1) Program, ki prebere niz in ga izpiše

Za vnos in izpis uporabi funkcijo.

#include <iostream>
#include <string>
using namespace std;

string vpis(string niz){
    cout << "Vnesi niz: ";
    getline(cin, niz);
    return niz;
}

void izpis(string niz){
    cout << "Vnesen niz je: " << niz;
}

int main()
{
    string vnesenaBeseda;
    vnesenaBeseda = vpis(vnesenaBeseda);
    izpis(vnesenaBeseda);
    return 0;
}

2) Program, ki prebere niz in ga izpiše v obratnem vrstnem redu

#include <iostream>
#include <string&
...
Continue reading "C++ Programi za Delo z Nizi: Vnos, Izpis in Obdelava" »