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

Sort by
Subject
Level

Extracting Structured Institution Data with LangChain

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.45 KB

Automated Data Extraction Using LangChain and Cohere

This script demonstrates how to leverage LangChain, Cohere, and the Wikipedia API to extract structured information about institutions. By using Pydantic, we ensure the extracted data follows a strict schema for better reliability.

Required Libraries and Data Models

First, we import the necessary modules and define our data structure using a Pydantic model to store institution details such as the founder, founding year, and employee count.

from langchain_community.llms import Cohere
from langchain.prompts import PromptTemplate
from langchain_core.runnables import RunnableLambda
from pydantic import BaseModel
import wikipediaapi

class InstitutionDetails(BaseModel):
    founder: str
    founded:
... Continue reading "Extracting Structured Institution Data with LangChain" »

Advanced Web Design and JavaScript Exam Revision Sheet

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.65 KB

This revision sheet covers essential concepts for Advanced Web Designing and Advanced JavaScript exams, designed for effective last-minute study.


🧠 Advanced Web Design & JavaScript Revision

1. Fill in the Blanks (10 Marks)

  1. HTML stands for HyperText Markup Language.
  2. CSS is used for styling web pages.
  3. The <div> tag is a block-level element.
  4. The <span> tag is an inline element.
  5. External CSS files use the .css extension.
  6. JavaScript is a client-side scripting language.
  7. The <script> tag is used to embed JavaScript code in HTML.
  8. document.write() is used to print content on a web page.
  9. var, let, and const are used to declare variables in JavaScript.
  10. The href attribute is used in the <a> tag to link to another page.

2. True or False

... Continue reading "Advanced Web Design and JavaScript Exam Revision Sheet" »

Essential C++ Programming Examples and Code Snippets

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.19 KB

Palindrome and Digit Sum Calculation

#include <iostream>
using namespace std;
int main() {
    int n, r, rev = 0, sum = 0, t;
    cin >> n; t = n;
    while (n) {
        r = n % 10;
        rev = rev * 10 + r;
        sum += r;
        n /= 10;
    }
    cout << (t == rev ? "Palindrome" : "Not");
    cout << "\nSum=" << sum;
}

Matrix Addition in C++

#include <iostream>
using namespace std;
int main() {
    int a[10][10], b[10][10], c[10][10], r, col;
    cin >> r >> col;
    for (int i = 0; i < r; i++)
        for (int j = 0; j < col; j++) cin >> a[i][j];
    for (int i = 0; i < r; i++)
        for (int j = 0; j < col; j++) cin >> b[i][j];
    for (int i = 0; i < r; i+
... Continue reading "Essential C++ Programming Examples and Code Snippets" »

Understanding Servlet Architecture for Java Web Apps

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.4 KB

Understanding Servlet Architecture for Java Web Applications

Servlet architecture is a core component of Java EE (Enterprise Edition) used for building dynamic web applications. A Servlet is a Java class that runs on a web server and acts as a middle layer between client requests (typically from a browser) and server responses (usually from a database or application logic).

What is a Servlet?

A Servlet is a Java class used to handle HTTP requests and responses in web applications. It runs on a server, receives requests from a client (usually a browser), processes them (e.g., reads form data, interacts with a database), and sends back a dynamic response (like HTML or JSON).

Key Components of Servlet Architecture

  • Client (Browser): Sends an HTTP request
... Continue reading "Understanding Servlet Architecture for Java Web Apps" »

Essential C Programming Syntax and Memory Management

Posted by Anonymous and classified in Computers

Written on in English with a size of 62.93 KB

Operators

  • Arithmetic: +, -, *, /, %
  • Relation: ==, !=, >, <, >=, <=
  • Logic: &&, ||, !
  • Assignment: =, +=, -=, *=, /=, ?=
  • Increment: ++, --
  • Order of operations: (), *, /, %, +, -, <>, ==, !=

ASCII Conversions

  • Lowercase to uppercase: 'x' - 32
  • Uppercase to lowercase: 'x' + 32

Data Types

Data TypesExampleSizeFormat
intint age = 19;4 bytes%d
floatfloat a = 3.7;4 bytes%f
doubledouble pi = 3.1415;8 bytes%lf
charchar grader = 'a';1 byte%c
stringchar name[20] = "pierre";array%s

Constants

#define TAX 0.13
const int Max = 100;

Control Structures

Statements: if, else if, else

Switches

switch(x) {
    case 1: printf("One"); break;
    case 2: printf("Two"); break;
    default: printf("Other");
}

Loops: while, do while, for

For Loop Example

#include <stdio.
... Continue reading "Essential C Programming Syntax and Memory Management" »

Java OOP Concepts: Inheritance and Polymorphism Examples

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.1 KB

Single Inheritance in Java

Single inheritance involves one class inheriting properties and methods from exactly one parent class. Below is a demonstration using the Animal and Dog classes.

class Animal {
    Animal() {
        System.out.println("Animal constructor called");
    }
    void eat() {
        System.out.println("I can eat");
    }
}

class Dog extends Animal {
    Dog() {
        System.out.println("Dog constructor called");
    }
    void bark() {
        System.out.println("I can bark");
    }
}

public class Main {
    public static void main(String[] args) {
        Dog myDog = new Dog();
        myDog.eat();
        myDog.bark();
    }
}

Implementing Multiple Inheritance using Interfaces

Java does not support multiple inheritance... Continue reading "Java OOP Concepts: Inheritance and Polymorphism Examples" »

C# Design Patterns: Essential Reference for Developers

Posted by Anonymous and classified in Computers

Written on in English with a size of 12.41 KB

C# Design Patterns: Essential Reference

Creational Design Patterns

PatternWhen to UseKey Implementation
SingletonNeed exactly one instance globally accessible.private static Singleton _instance;
public static Singleton Instance => _instance ??= new Singleton();
FactoryCreate objects without specifying concrete classes.public static IProduct Create(string type) => type switch { "A" => new ProductA(), ... }
BuilderConstruct complex objects step-by-step.public class CarBuilder { ... public CarBuilder WithEngine(...) { ... } }
PrototypeClone existing objects instead of creating new ones.public interface IPrototype { IPrototype Clone(); }

Structural Design Patterns

PatternWhen to UseKey Implementation
AdapterMake incompatible interfaces work together.
... Continue reading "C# Design Patterns: Essential Reference for Developers" »

Essential C Programming Exam Questions and Solutions

Posted by Anonymous and classified in Computers

Written on in English with a size of 37.36 KB

x4jbIeyLsADAAAAAElFTkSuQmCC

Store Fibonacci Series in an Array

Exam Source: 2024 Q6(b)

Note: fib[0]=0, fib[1]=1, fib[i] = fib[i-1] + fib[i-2] for i >= 2.

#include <stdio.h>

int main() {
    int n, i;
    printf("How many terms? ");
    scanf("%d", &n);
    int fib[n];
    fib[0] = 0;
    if (n > 1) fib[1] = 1;
    for (i = 2; i < n; i++)
        fib[i] = fib[i-1] + fib[i-2];
    printf("Fibonacci series: ");
    for (i = 0; i < n; i++)
        printf("%d ", fib[i]);
    return 0;
}

Dynamic Memory Allocation and Average Calculation

Exam Source: 2024 Q7(c) / 2025 Q6(a) — Repeated both years!

Note: malloc returns void*, cast to int*. Always free() after use. If malloc returns NULL, memory allocation failed.

#include <stdio.h>
#include <stdlib.h&
... Continue reading "Essential C Programming Exam Questions and Solutions" »

Array and String Algorithms: Core Problem Solutions

Classified in Computers

Written on in English with a size of 6.48 KB


Longest Substring Without Repeating Characters

This problem involves finding the length of the longest substring in a given string that does not contain any repeating characters. A common approach uses a sliding window technique with a Set to efficiently track unique characters.

Strategy:

  • Utilize a Set to store characters within the current window.
  • Iterate through the string with a right pointer, adding characters to the Set.
  • If a duplicate character is encountered, move the left pointer forward, removing characters from the Set, until the duplicate is no longer present.
  • At each step, update the maximum length found.

Java Implementation Snippet

class Solution {
    public int findLongestSubstringWithoutRepeatingCharacter(String str) {
        Set&
... Continue reading "Array and String Algorithms: Core Problem Solutions" »

Tensors and Variables in PyTorch and TensorFlow

Classified in Computers

Written on in English with a size of 2.4 KB

Tensors and Variables in PyTorch and TensorFlow

Here's a brief explanation of tensors and variables in the context of deep learning frameworks like PyTorch and TensorFlow:

Tensors

  • Definition: A tensor is a multi-dimensional array used to represent data (such as scalars, vectors, matrices, or higher-dimensional data).
  • Common Operations: Tensors can be manipulated with mathematical operations (addition, multiplication, etc.), reshaped, sliced, etc.

In PyTorch, tensors are the core data structure:

import torch
# Create a tensor
a = torch.tensor([[1, 2], [3, 4]])
# Basic operations
b = a + 2         # Adds 2 to each element
c = a * a         # Element-wise multiplication
d = a @ a         # Matrix multiplication

Output:

Tensor `b`: [[3, 4], [5, 6]]
Tensor
... Continue reading "Tensors and Variables in PyTorch and TensorFlow" »