Skip to main content

C++

Illustrating Binary Countdown Protocol with C++ Program

The Binary Countdown Protocol is a contention-resolution MAC (Medium Access Control) protocol used on shared broadcast channels. When multiple stations want to transmit simultaneously, each station broadcasts its address as a binary number, bit by bit from the most significant bit (MSB) downward. Stations with a 0 bit at a position where another station has a 1 bit drop out of the contention. The station whose complete binary address survives the entire comparison wins the channel and transmits its frame. This guarantees that the station with the highest binary address always wins each contention round. This C++ program simulates the Binary Countdown Protocol. Each frame is treated as an 8-bit binary number. The program converts each frame to its decimal equivalent (which represents the station’s binary address), then announces the frames in descending priority order — highest decimal value first — as they would be granted channel access.

Implementation of Distance Vector Routing (DVR) Algorithm in C++

Distance Vector Routing (DVR) is a decentralised routing protocol where each router maintains a table containing its estimated shortest distance to every other router in the network. Routers exchange these distance vectors with their neighbours, and each router updates its own table whenever a shorter path is discovered. The algorithm continues iterating until no table changes occur — a state known as convergence. DVR is the conceptual basis for real-world protocols such as RIP (Routing Information Protocol). This C++ program simulates DVR on a user-defined network. The user specifies the number of nodes and the distances between directly connected node pairs. The program iteratively updates routing tables until convergence and then prints each node's final routing table showing the shortest distance and the next-hop node to reach every destination.

Demonstrating Deadlock with Resource Allocation

Deadlock is a situation in a distributed or multi-process system where a set of processes are permanently blocked, each waiting for a resource that another process in the set holds. Detecting which processes are causing a deadlock is a critical operating system responsibility. This C program implements a deadlock detection algorithm using a resource allocation graph. It uses a claim matrix (maximum resource needs), an allocation matrix (currently held resources), and availability vectors to identify processes that are involved in a deadlock.

C++ Implementation of Substitution Cipher

This simple C++ implementation of a substitution cipher—specifically the Caesar cipher—demonstrates how basic cryptographic techniques can be used with file handling. The Caesar cipher is one of the oldest and simplest substitution cipher techniques. It works by shifting the letters in a message by a fixed number of positions in the alphabet. Unlike transposition ciphers, which rearrange character positions, substitution ciphers replace characters with others based on a defined scheme. This blog post demonstrates a C++ implementation that reads a message from a file, performs Caesar cipher encryption or decryption, and writes the result to another file. How It Works Input and Output Files: Input is read from a file named anip.txt. Output is written to a file named anop.txt. User Choices: You can choose between encryption and decryption. Provide a key (shift amount), e.g., 2. Caesar Cipher Logic: For encryption, each letter is shifted forward in the alphabet by the key. For decryption, each letter is shifted backward by the key. Non-alphabet characters are left unchanged.

Implementation of Bottom-Up (Shift-Reduce) Parsing in C++

Bottom-up parsing is a strategy used by compilers to analyse source code by building the parse tree from the leaves (terminal symbols) up to the root (start symbol). The most common bottom-up technique is shift-reduce parsing, which uses a stack and a set of production rules. At each step the parser either shifts the next input symbol onto the stack, or reduces the top of the stack by replacing a substring that matches the right-hand side of a production rule with the corresponding left-hand side symbol. This C++ program implements a simple shift-reduce parser. It reads a set of production rules and an input string from the user, then processes the string step by step, displaying the stack contents, remaining input, and the action taken (Shifted or Reduced) at every stage.

Implementing Lexical Analyser in C++

Lexical analysis (also called scanning or tokenisation) is the very first phase of a compiler. The lexical analyser reads the raw source text character by character and groups characters into meaningful units called tokens. Each token belongs to a category: an identifier (variable or function name), a literal (numeric constant), or a terminal (operator or punctuation symbol found in a predefined database file). This C++ program reads an expression string (terminated by $) from the user, classifies each character, and builds a Uniform Symbol Table (UST) that records every token together with its type (LIT, IDN, or TER) and a pointer (sequential index within its type). The results are written to four files and then displayed on the console. Required file: Before running the program you must create D:andb.txt containing all operator/punctuation characters that should be recognised as terminals (e.g. =+-*/()/), one or more per line.

Implementing Code Generator in C++

Code generation is the final back-end phase of a compiler. It takes the intermediate representation (IR) of the program — typically a sequence of three-address instructions — and translates each one into the equivalent target machine instructions. For a register-based architecture like the 8086, this means emitting MOV, ADD, SUB, MUL, DIV, and assignment instructions that use the AX and BX registers. This C++ program reads three-address IR instructions from an input file (AIP.TXT), generates the corresponding 8086-style assembly code, and writes it to an output file (ANOP.TXT). Each IR instruction has the form: operator operand1 operand2 result

Implementing Absolute Loader in C++

A loader is a system program responsible for placing a program into memory so it can be executed. An absolute loader is the simplest type: it loads a program at a fixed, pre-determined memory address (the starting address is embedded in the object file itself and cannot be changed). This contrasts with a relocating loader, which can place the program anywhere in memory and patches all address-dependent instructions accordingly. This C++ program simulates an absolute loader. You provide a starting address and the values to be placed at consecutive bytes, and the program then lets you query what the value at any relocation address (offset from the starting address) would be — mimicking the act of loading and then reading back memory.

Implementing Socket Programming in Java

Socket programming is the foundation of network communication in Java. A socket is one endpoint of a two-way communication channel between two programs running on a network. Java provides the java.net package with high-level abstractions — ServerSocket for the server side and Socket for the client side — that handle the underlying TCP/IP details so you can focus on reading and writing data streams. This example implements a simple interactive TCP chat between a server and a client. Both sides can send and receive messages. Either side can type Q or q to close the connection gracefully. The server listens on port 5000; the client connects to localhost:5000.

Illustrating Working of Bit-Map Protocol with C++ Program

The Bit-Map Protocol is a contention-free MAC (Medium Access Control) layer protocol used to coordinate which stations are allowed to transmit on a shared channel. Before any data frame is sent, each station broadcasts a single bit during its reserved slot in a contention slot period: a 1 signals that the station has a frame ready to send, while a 0 means the station has nothing to transmit. Once every station has announced its status, transmissions occur in station order, eliminating collisions entirely. This C++ program simulates the Bit-Map Protocol. The user specifies the number of stations and their ready/not-ready status. The program reads each station's status, then announces which stations are ready to transmit in station-number order.