Programming Examples and Source Code

mycplus

The best way to learn any programming language is by practicing examples. This source code section features a diverse collection of programming examples and source code snippets written C, C++ and other programming languages.

The examples includes practical implementations, tutorials, and demonstrations aimed at helping programmers enhance to enhance their programming skills.

Table of Contents

C Programming Source Code

  • LRU and FIFO L1 Cache Implementation using C
    This is a C program to demonstrate cache mechanism by simulating a cache in C. The source code can run in any C Compiler with minor modifications if required. It can run on real memory traces as input to your cache simulator. We have implemented two cache replacement policies i.e. least recently used (LRU) and First-in first-out (FIFO) replacement policies.
  • Random Number Generation in C/C++: Tricks for Generating, Seeding, and Working with Random Numbers
    C Standard Library provides two different methods to generate random numbers. They are: rand() and srand().
  • C Algorithms Library
    This article is about a collection of common Computer Science algorithms which may be used in C projects. The C Programming Language has a much smaller Standard Library as compared to other more modern programming languages such as Java or Python. The library provides a basic set of mathematical functions, string manipulation, type conversions, and file and console-based I/O.

C++ Programming Source Code

  • Rock, Paper, Scissors Game in C++ [C++ Game]
    This is a simple C++ program to demonstrate rock, paper, scissors game. In this game, players have to choose one of the three options to beat the opponent or the computer itself. The C++ code generates a random choice by creating a character to indicate that option. Options are: r is for ‘rock’, p is for ‘paper’, and s is for ‘scissors’.
  • C++ Code – Wave File Converter from Text File
    This C++ program is capable of turning a text file describing the notes of a piece of music into an audio file (.wav). The program reads the contents of the input file i.e. input.txt, constructs Song, Voice and Note objects describing the notes in the file, and call the different… Read more: C++ Code – Wave File Converter from Text File
  • Vigenere Encryption and Decryption in C++
    The Vigenere cipher is a method of encrypting or decrypting alphabetic text by using a series of interwoven Caesar ciphers (Caesar Shift), based on the letters of a keyword. In cryptography, Caesar shift is one of the simplest known encryption techniques. It employs a form of polyalphabetic substitution, which is using multiple substitution alphabets.

JavaScript Source Code

  • Difference Between [] and {}: Arrays vs. Objects in JavaScript
    In JavaScript, we use braces {} for creating an empty object and brackets [] for creating an empty array. I find the Developer console in Mozilla Firefox or Google Chrome more convenient to print out any object and study the details.
  • JavaScript Program to Show Current Time In Various Formats
    This is a small script that can display the current time in “Military Time” format or “12 Hour Time” format with the push of a button. It shows two radio buttons to change the time format and a text box to display the time.
  • JavaScript Program to Show Date and Timestamp
    This is a simple JavaScript Program to show Date and Time Stamp on a webpage. In this script  we define a JavaScript function named getFormattedDateTime. This function uses the Date object to get the current date and time. It then formats them into a human-readable string.

PHP Code Snippets

  • How to Send Email using PHP
    A detailed guide on PHP mail sending options with examples of using the built-in mail function(), PHPMailer, Symfony, and third-party mail service providers such as Amazon SES, SendGrid and GetResponse.
  • Search the LDAP Directory in PHP
    This PHP code connects to an LDAP server, performs a search for entries with the last name and then sorts and prints them alphabetically. The sorting is done by a custom function called compareEntry, which compares entries based on last names and first names. It uses the LDAP functions to communicate with the server and showcases basic error handling.
  • Printing numbers within a range in PHP
    The following PHP source code shows that how to print random numbers within a range using. It uses rand() function to return the random numbers within a predefined range. The srand() function is used to provide the seed or arbitrary int number.

Java Source Code

  • Java Program to Demonstrate the Use of Linked List
    This is a very simple implementation of linked list in java programming language. Very nice and well commented java source code for beginners.
  • Java Program to Show Stack Implementation
    This is a simple Java program to demonstrate the Stack data structure implementation. This code provides a simple implementation of a stack with basic operations (push, pop, and isEmpty).
  • Stack Implementation with Array
    This java code implements stack functionality by using arrays. It can Pop and Push an item in stack with the help of array. The item can only be an integer number and internally the java program uses arrays to maintain items in stack.