Matrix Column Sum and Row Sum in C++

This C++ program calculates the sum of all the rows and columns of a given Matrix. As you can see in the image below, the sum of the rows and columns are given on the Right side with green arrows and Bottom with red arrows respectively. See code below:



Infix to Postfix Conversion in C++


This C++ Program converts an input Infix (Inorder) type of expression to its Postfix (Postorder) equivalent. Infix or Inorder is a way to represent expressions by writing the Operators inbetween the Operands. In the Postfix or Postorder representation, we write the operator after writing two operands successively. The Postfix Notation is also known as the Reverse Polish Notation. You can also find the Source Code at the end. 



Priority CPU Scheduling Algorithm in C++



#include <iostream>

using namespace std;

int main()
{
    clrscr();
    int n,i,a[5],b[5],bt;
    float p;
    cout<<"Enter no. of process : ";
    cin>>n;

SCAN Disk Scheduling Algorithm in C++


#include <iostream>

using namespace std;

int main()
{
    clrscr();
    int n,d[8],a,b,c=0,j,i=0;
    char ch='y';
    cout<<"Enter no. of elements in queue : ";
    cin>>n;
    cout<<"enter value of initial head position : ";
    cin>>a;

Shortest Job First (SJF) Disk Scheduling Algorithm in C++


#include <iostream>

using namespace std;

int main()
{
    clrscr();
    int n,a[4],b[4],i,j;
    float k;
    cout<<"Enter no. of process :";
    cin>>n;

First Come First Serve (FCFS) Disk Scheduling Algorithm in C++



#include <iostream>

using namespace std;

int main()
{
    clrscr();
    int a,b,c=0,i=1;
    char ch='y';
    cout<<"enter value of initial head position : ";
    cin>>a;

Binary Search Algorithm Implemented in C++

Binary Search also known as the half-interval search algorithm is a  type of Divide and Conquer Algorithm. It is a fairly simple algorithm in that the key element to be found is searched with a logic that is determined by the element present in the middle of the list of all elements to be found. All the elements have to be arranged in ascending or descending order for this algorithm to work. The simple logic used is checking if the value is greater or lesser than the middle element. If the value is lesser than the key element, then we check the left series of elements. If the middle value is greater than the key element, then it implies that the value to be found must be present in the right series of the list. This case happens in an increasing numbered list i.e. ascending ordered list. In a descending ordered list, the searching changes direction i.e. if lower value is required we go to the right of the series and higher value is present on the left of the series. 

Linear Search Algorithm Implemented in C++

Linear Search is the simplest of searching techniques that can be implemented with a simple array and a for loop. All elements of a particular array are checked one by one to find a given key element. If the element is found, the system returns that the search was successful. Also the user will be presented with a location where the search element was found i.e. the index in the array matched. See the code below followed by the C++ source code: 

Print Prime Numbers in C++

This little program shows how to take input an integer specifying the number for consecutive prime numbers to print. All numbers starting from 1 are continuously checked for being prime. If found to be prime, they are immediately printed. If not, the current number is simply skipped and the loop variable is incremented to get a new number i.e. 1 greater than the current number. 

Find NCR and NPR in C++ Console

This C++ program shows you how to calculate the NCR and NPR of two given numbers. NCR is basically a combination number i.e. if you had N number of distinct objects then taking R objects at a time, NCR determines how many combinations are possible. In NPR, we get the number of permutations i.e. the combinations but with the sequence being also taken into account. 

Addition and Subtraction of Two Matrices in C++

Matrix Addition and Subtraction are very simple operations applied to Matrices in which we add/subtract corresponding terms of the matrices to obtain the resultant matrix. There is no complicated operation and the process is fairly simple. There are two matrices required of exactly equal dimensions. These matrices are stored in two dimensional arrays of integers. The entering of numbers is done through the 2 for loops. The for loop is iterated by keeping in mind the number of rows first followed by the number of columns. When finding the result, the same skeleton for loop is run but this time adds the corresponding elements of the matrix together to give the resultant matrix. Watch the code below:

Matrix Multiplication in C++

This is the Matrix Multiplication program code for C++. The coding has been done in Code:Blocks and the source code can be found at the very end. The program is simple and consists of taking input a couple of Matrices and multiplying them using Matrix Multiplication rules. The logic for Matrix Multiplication is as follows in the picture below:

Call by Reference in C++


Call by Reference is a mechanism in C++ in which we intend to modify the parameters that we pass on to our function permanently. The actual parameter values are automatically changed when we change the formal parameter values. Also note that the actual and formal parameters may or may not have the same name. But they must have the same address which connects them together. 

We may also understand the meaning of Formal and Actual parameters. Actual Parameters are the ones passed on to the function(c and d in the program below). What usually happens is that they are copied into the Formal Parameters(&i and &j in the program below) before they are worked with. These Formal Parameters are used inside the function to calculate values or provide other functionality. 

Default Argument Constructor in C++


This program elegantly describes the Default Argument Constructor used in C++. This type of constructor can be well used to replace the usual constructors that we create. These constructors are designed to simply give the class variables some valid value even if  a value has not been assigned in the Object declaration and initialization inside main(). 

To do this, simply write the value of the variable that you want to initialize the variable with. Now if in case a new value is assigned in the Object initializer, this default defined value will be overridden with the new value. Therefore explicit as well as implicit assigning is supported. 

New & Delete Example in C++ Program


This C++ Program shows you how to create new objects via the new keyword. In the program below, we create an integer pointer variable named *p. The value of the integer is initialized to 87. Then we have printed the value of p through the cout operator. This is the basic procedure for creating new objects from classes. 


The deletion of previously created objects can be done with the help of delete operator. Simply write delete followed by the variable name to delete the variable.This process of deleting previously created is a good practice as it frees up memory resources from the computer. Also, if a huge number of Objects are left untreated after their usage, their memory piles up to form wasted memory resources which can significantly slow down the speed of the computer. 
Custom Search