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

JavaScript Cheat Sheet: Arrays, Functions, Objects & More

Computer science4.2 KB

JavaScript Cheat Sheet

JavaScript Arrays

var cars = ["Mercedes", "Tesla","Volvo"];

  • pop(): Removes the last element of an array.
  • push(): Adds a new element at the end of an array.
  • concat(): Joins various arrays into a single array.
  • reverse(): Reverses the order of elements in an array.
  • indexOf(): Returns the first index of a given element in an array.
  • lastIndexOf(): Returns the last index of a given element in an array.
  • join(): Combines elements of an array into a single string.
  • sort(): Sorts array elements based on a condition.

Global Functions

These functions are built-in to every browser that runs JavaScript:

  • parseFloat(): Parses the argument and returns a floating-point number.
  • parseInt(): Parses the argument and returns an integer.
  • Number(): Returns a
...
Continue reading "JavaScript Cheat Sheet: Arrays, Functions, Objects & More" »

Computer System Essentials: Components, Functions, and Utilities

Computer science4.02 KB

Computer System Essentials

Core Operating System Components

Kernel: The OS's Foundation

The operating system's core, a platform that allows other software to execute.

Shell: User Interaction Interface

The operating system's interface for users to interact with all computer elements.

Thread: A Running Program or Task

Any program or task that is currently running.

File System: Data Storage & Retrieval Protocol

A protocol that defines how files are stored and retrieved on disk drives, or by threads and programs.

Disk Formatting: Setting a File System

The process of setting a disk's file system.

Major Operating Systems and Their Focus

  • Microsoft Windows: Focuses its operating system on security.
  • Linux: Emphasizes customizability.
  • Chrome OS: Centered on web
...
Continue reading "Computer System Essentials: Components, Functions, and Utilities" »

Automated Fact-Checking of Text Summaries for Relational Databases

Computer science4.06 KB

Verifying Text Summaries of Relational Data Sets

• Relational data is often summarized by text.
• The focus of this paper is the problem of verifying, in an automated fashion, whether text claims are consistent with the actual database.
• The authors proposed a tool for verifying text summaries of relational data sets, which works similarly to a spell checker and marks up claims that are believed to be erroneous.
• The system converts claims into SQL queries and then evaluates them.
• The main problem is converting natural language claims to SQL queries.
• The tool is called AggChecker.

AggChecker

• AggChecker consists of two parts: a relational data set and a text document.
• The text contains claims about the data.
• The goal is to
...
Continue reading "Automated Fact-Checking of Text Summaries for Relational Databases" »

Python Functions and Errors: Time, Triangle, Bonus, and Digits

Computer science4.09 KB

TIME DIFFERENCE

def time_difference(time1, time2):
time1=time_to_seconds(time1)
time2=time_to_seconds(time2)
diffinsecond=time2-time1
hours=diffinsecond//3600
minutes=(diffinsecond-(hours*3600))//60
seconds=diffinsecond-(hours*3600)-(minutes*60)
return(make_time_string(hours,minutes,seconds))

# Predefined helper functions. Do not edit them.
def time_to_seconds(time):

x = list(map(int, time.split(":"))
return x[0] * 3600 + x[1]*60 + x[2]

def make_time_string(hours, mins, seconds):
return "{:02d}:{:02d}:{:02d}".format(hours, mins, seconds)

TYPE OF TRIANGLE

def triangle(side1, side2, side3):
if side1+side2<>
return "Not a triangle"
elif side1==side2 and side2==side3:
return "Equilateral"
elif...

Continue reading "Python Functions and Errors: Time, Triangle, Bonus, and Digits" »

Java Sudoku Solver: Backtracking Algorithm Implementation

Computer science5.57 KB

Building a Sudoku Solver in Java with Backtracking

This document presents a Java implementation of a Sudoku solver, utilizing a classic backtracking algorithm. The code demonstrates how to represent a Sudoku board, check for valid moves, and recursively find a solution to the puzzle.

Initial Sudoku Puzzle Setup

The Sudoku board is represented as a 2D integer array. A value of 0 indicates an empty cell that needs to be filled.

int[][] board = {
  { 8, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 3, 6, 0, 0, 0, 0, 0 },
  { 0, 7, 0, 0, 9, 0, 2, 0, 0 },
  { 0, 5, 0, 0, 0, 7, 0, 0, 0 },
  { 0, 0, 0, 0, 4, 5, 7, 0, 0 },
  { 0, 0, 0, 1, 0, 0, 0, 3, 0 },
  { 0, 0, 1, 0, 0, 0, 0, 6, 8 },
  { 0, 0, 8, 5, 0, 0, 0, 1, 0 },
  { 0, 9, 0, 0, 0, 0, 4, 0, 0 }
};

Implementing

...
Continue reading "Java Sudoku Solver: Backtracking Algorithm Implementation" »

Microsoft Word & Computer Basics: Key Features Explained

Computer science4.08 KB

Key Concepts in Microsoft Word and Computer Applications

1. Microsoft Word Application Type

Which type of computer application is Microsoft Word an example of?

Word processing

2. Touchscreen Right-Click

Which action enables you to right-click on a touchscreen?

Press and hold for a few seconds

3. Word 2016 Document Starting Point

A preformatted document used as a starting point in Word 2016 is known as what?

A template

4. Wordwrap Functionality

Word uses wordwrap. If a word does not fit at the end of a line, what happens to that word?

It is automatically moved to the next line.

5. Understanding Inline Objects

What does inline object refer to?

A picture or object positioned directly in the text at the insertion point, just like a character in a sentence.

6.

...
Continue reading "Microsoft Word & Computer Basics: Key Features Explained" »

Functions, Arguments, and Recursion in Programming

Computer science4.58 KB

Functions and Arguments

A function is a module of program code that takes input (arguments) and produces output (a return value).

  • Arguments allow us to customize the operation performed by the function.
  • The return value is often the result of executing the code.
  • Calling a function causes the code in a function to execute. If called again, it will execute again.

To document a function, use a multi-line comment immediately after the def line.

Local Variables

Local variables are variables used inside functions.

  • They are accessible/usable within that function only.
  • This refers to the variable's scope.

Global Variables

Global variables are variables used outside of a function.

  • Global variables' scope includes both inside and outside of functions.
  • However, since
...
Continue reading "Functions, Arguments, and Recursion in Programming" »

Alpha Vantage API Integration for Stock Market Data

Computer science3.22 KB

Stock Market Data Integration

Listar

Stock Data Table Headers

OPENHIGHLOWCLOSEVOLUME

Alpha Vantage API Implementation

The following script utilizes jQuery AJAX to fetch real-time stock data for MSFT from the Alpha Vantage API.


function main() {
    $("#list").click(function() {
        $.ajax({
            type: "GET",
            url: "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo",
            success: function (azul) {
                var roxo = azul["Time Series (1min)"];
                for (var verde in roxo) {
                    var vermelho = roxo[verde];
                    var str = "<tr><td>" + vermelho["1. open"] + "</td>"
...
Continue reading "Alpha Vantage API Integration for Stock Market Data" »

C++ Cheat Sheet: Structs, Classes, Pointers, Arrays, and More

Computer science6.65 KB


```c++
    //input 
    int main(int argc, char * argv[]){ // or char ** argv
        const char* strs[] = {"Hello", "World!"};
        const char str[] = {"Hello"};
        const int arr[] = {1,2,3};
        std::cout << *strs<< std::endl;
        std::cout << str << std::endl;
        std::cout << arr << std::endl;
        std::cout << *arr << std::endl;
        std::cout << *str << std::endl;
        std::cout << *(strs + 1)<
    } 
    //output
    Hello
    Hello
    0x77d02fb38050
    1
    H
    World!
    void insert(int array[], int size, int item, int num_copies){
    for(int * i = array; i < array + size - num_copies;
...
Continue reading "C++ Cheat Sheet: Structs, Classes, Pointers, Arrays, and More" »