C++ Programming Examples: Templates, Data Structures, and Algorithms

C++ Programming Examples

Templates

Maximal Function

This template function returns the larger of two items:

template<typename item>
item maximal(item a, item b) {
    if (a > b)
        return a;
    else
        return b;
}

Swap Function

This template function swaps the values of two items:

template<typename item>
void swap(item& x, item& y) {
    item temp = x;
    x = y;
    y = temp;
}

Linked Lists

Bag Class

This template class implements a bag data structure using a linked list:

Read More

Assembly Language Examples: Calculators, Palindrome, Loaders

CALCU

Assumptions:

  • ss: Stack Segment
  • cs: Code Segment
  • ds: Data Segment

Procedure:

Initialization:

  1. Display a message using a macro.
  2. Initialize necessary messages and variables in the code segment.

Code Segment:

  1. Specify the address of the data segment to the data register.
  2. Read the choice using the read procedure.
  3. Compare the choice:
    • If the choice is 1: Read values into registers, add them using the add operator, call the print procedure, and jump to exit.
    • If the choice is 2: Read values into registers, subtract
Read More

Web Development Tutorial: HTML, CSS, JavaScript, PHP & AJAX

Web Development Basics

HTML

HTML (HyperText Markup Language) is the foundation of web pages. It provides the structure and content of a webpage using elements like headings, paragraphs, images, and links.

Forms

HTML forms allow users to input data, which can then be submitted to a server for processing. They are essential for tasks like user registration, login, and data collection.

Input Fields

Input fields within forms collect specific types of data, such as text, numbers, or selections. They are defined

Read More

Remote Control System for Elevators and Calculators

Remote Control: RMI Implementation

Package: customer java.rmi

Import java.rmi.*;

Import java.util.Scanner;

Import interfaz.GestorAscensores;

Import java.lang.Math

Public class Remote {

GestorAscensores manager;

Scanner keyboard = new Scanner(System.in);

Public Remotecontrol() throws Exception {

handle = ((GestorAscensores) Naming.lookup(“rmi://localhost/Manager“));

}

Public void check() throws Exception {

Scanner keyboard = new Scanner(System.in);

int option, pisodest, id;

do {

choice = menu();

switch (option) {

Read More

Business Documents and File Management

Types of Business Documents

Sales/Purchase Documents

  • Offer
  • Order
  • Contract
  • Statement
  • Bill of Lading
  • Invoice
  • Proforma Invoice
  • Receipt
  • Bills
  • Notes
  • Check

General Documents

  • Internal Communications
  • Reports
  • Minutes
  • Announcements
  • Memos
  • Resource Instance
  • Officiates
  • Affidavit
  • Certificate

Internal Communications

Notices and internal communications share common characteristics:

  • Short and informal
  • No specific protocol
  • Dated and signed

Reports

Generally prepared by specialists in a third-person, impersonal style, using specialized language

Read More

Chrominance, Sync & Deflection Circuits in Video Monitors

6.13 Chrominance Process:

To start, the signal is given by the video control block. This signal goes through a 4.43 MHz bandpass filter, which removes luminance and sync components. The filter output will only signal corresponding to the color information of the image.

Once extracted, the chroma information is taken to the chroma control block, which controls the signal’s amplitude, resulting in varying saturation.

The PAL demodulator consists of a 64 microsecond delay line, an adder, and a subtracter.

Read More