Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes
CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C++ Programming Language Code Examples

C++ Binary Addition & Binary Subtraction
Addition, Subtraction, Multiplation, Result to decimal. Reverse second binary operand and Creating an array for addition. Addition of all columns without carry. Final calculations and
Create an Array of Chars in C++ Language
String is a "sequence of characters". char data type is used to represent one single character in C++. So if you want to use a String in your program then you can use an "array of chars".
C++ Code Add Two Matrix with 2D Arrays
2 const variables row & col are used to define size. If we do not make both const then error found because without "const reserve word" they are behaving as variable. Before placing
Checks a Character is Capital Letter or Not
Takes input a Character and Check it whether a 'character' is capital letter, small letter, Digit or Special character. 'All characters' like small or capital letters, digits and special characters
C++ Language Displaying Fibonacci Series
The Fibonacci sequence is a series where the next term is the "sum of pervious two terms". The first two terms of the Fibonacci sequence is 0 followed by 1. Fibonacci Numbers: 0, 1, 1,
C++ Byte Alignment in a struct Algorithm
Get size of the current type. Align depens on the next type and also alignment defined by #pragam pack(#). Offset will be minimum of this size. If the "size of next type" is less than
Addition of Two Matrix in C++ Language
To achieve Addition of two matrix we need 2 "Dimensional Array" and add their elements with each other, print result on screen. Enter elements of firts matrix. Enter elements of 2.
C++ Language & Concatenate Two Strings
Combined two strings means add both string with each other, perform this operation using 'library function' or without library function. If first string is 'john' and second string is porter
Checking Character is Vowel or Consonant
Alphabets a, e, i, o, u are known as vowels. All other alphabets except these 5 alphabets are known are 'consonants'. C++ sample assumes that the user will enter an Alphabet. Similarly
Checks Whether a Number is Prime or Not
A 'positive integer' which is only divisible by 1 and itself is known as prime number. So 13 is a prime number because it is only divisible by 1 and 13 but, 15 is not prime number because
C++ Check a Number is Palindrome or not
Palindrome number is a number that remains the same when its digits are reversed. 16461, for example: we take 121 and reverse it, after revers it is same as original. Get a value from
String Search Algorithm & Short text sizes
C++ program performs Naive string matching without using any specific library functions. A text and a Pattern is given as input. Pattern is searched for in a text and all 'instances' of the
Matrix Multiplications Mutiply 2 Matrices
Column number of first matrix must be same as the row number of second matrix. Initialize matrix. Print values of the passed matrix and mutiply two matrices and return the resultant
The C++ Break Statement and Switch Case
In C++ program, we have the variable i inside "Switch Braces", which means whatever the value of variable i is, the 'corresponding' case block gets executed. We have passed integer
Checking Whether Number is Even or Odd
In this example, if...else statement is used to check whether a number entered by the user is "even or odd". Integers which are perfectly "divisible by 2" are called even numbers. And
Binary Search Tree Code in C++ Language
Smaller elements go left. Larger elements go right. All insertions are as leaf nodes. Remove a leaf node and remove a node with a single child. Remove a node with 2 children, replace
C++ Language Add Digits of any Number
To add digits of any number in C++, we enter the number to add their digits & displays the "Addition Result" of the digits of the entered number on the output screen as shown here
C++ Sample Calculate Power of a Number
Program takes two numbers (a 'base number' and an 'exponent') and Calculates the Power. The technique works only if the exponent is a positive integer. If you need to find the power
C++ Program Checks Armstrong Number
In c++ program, a positive integer is asked to enter which is stored in the variable origNum. The number is copied to variable num. This is done because we need to check the origNum
C++ Simple Calculator Code for Beginners
Write a simple C++ program which have four different functions for "basic operations" like addition, subtraction, division, multiplication. It should be menu based asking user to enter
Any number of Digits Armstrong Sample
An "Armstrong Number" is a number that is the 'sum of its own digits' each raised to the power of the number of digits is equal to the number itself. Some Armstrong numbers is 0
C++ Additions Subtractions Multiplication
Perform addition, subtraction, multiplication and division of any two numbers in 'C++', you have to enter the 'two number' and enter the operator to perform the particular operation
If Else If Statement & Multiple Conditions
In this control structure we have only one 'if' and one 'else', however we can have multiple 'else if' blocks. This is how it looks: If none of the 'condition is true' then these statements
Count Occurrence Positive Zero Negative
We have to enter some set of numbers. Now to find occurrence of positive, negative, zero from the given set of numbers, just check all the numbers using for loop whether number
A Calculator Add Subtract Multiply Divide
Takes an "arithmetic operator" (+, -, *, /) and two operands from an user and performs the operation on those two operands depending upon the operator entered by user. Program
Add Two Matrix Using Multi-Dimensional
In this program, user is asked to entered the number of rows r & columns c. The value of r & c should be less than 100 in this program. Then, the program adds these two matrices,
C++ For Loop is Similar to While Loop but
Control statement itself has three parts: for ( "initialization"; test condition; run every time command ). "Initialization" part is performed only once at for loop start. We can initialize a
Program to Calculate Average of Numbers
Takes n number of element from user (where, n is specified by user), stores data in an array and calculates the average of those numbers, program calculates the average if the number
Topological Sortings of a Directed Acyclic
Topological sorting for directed acyclic graph (dag) is a linear ordering of vertices such that for every directed edge 'uv', vertex 'u' comes before v in the ordering. 'Topological Sorting'
C++ SQL Connects to ODBC Data Sources
Allocating memory for "ODBC" Environment handle. Connecting to the data source "db97" using userid and password. Prepare the SQL statement by assigning it to the "statement"
Find The Position of A Point With Respect
This is a C++ Program to check whether point lies above, below or on the line. For example, the equation of the line connecting points (2, 2) and (4, 5) is -3x + 2y + 2 = 0. The point (6, 3)
Directed Graphs Contains a Eulerian Cycle
If graph has no odd degree vertex, there is at least one Eulerian Circuit. And if graph as two vertices with odd degree, there is no Eulerian Circuit but at least one Eulerian Path. If graph
C++ Language Break Continue Statement
We can use "break" statement inside loops to terminate a 'loop & exit' it. In above example loop execution 'continues' until either n>=20 or entered score is negative. This statement
C++ Language Do While Loop Statements
The statement is executed, then expression is evaluated. If it is true, statement is evaluated again, and so on. When 'expression' becomes false, the 'loop terminates'. Experience shows
C++ Apply the Kruskal's Algorithm to find
'C++ Program' to find the minimum spanning tree of the given graph. Kruskal's algorithm is a greedy algorithm in graph theory that finds a "Minimum Spanning Tree" for a connected
C++ Prim's Algorithm Finds the Minimum
Find the minimum spanning tree of the given graph using Prims algorihtm. This algorithm is a "greedy algorithm" that finds a minimum spanning tree for a "Connected Undirected"
C++ Coding Topological Sorting in Graphs
Using an adjacency matrix, displays the times at which the 'different times' at which nodes are visited and left thereby producing a linear ordering of vertices in a graph. And A graph is
C++ Language Accessing Array Elements
"Array index" starts with 0, which means the first array element is at index 0, second is at index 1 and so on. We use this information to display the array elements. See the C++ code
Combinations Using Matrix Multiplication
A C++ function to find the factorial of a given number using matrix multiplication method. Assigning numbers from "1 to n" to the super diagonal indexes of the matrix and assigning
Simple Programs Area Of Square Formula
The second power was described in terms of the area of a square, as in the above formula. It led to the use of the term square to mean raising to the "second power". Thus the area
Evaluates the Value of Any Polynomial of
Give the degree of the polynomiala. Give the value of the coefficients. Give the value of the coefficients. Give the values of the coefficient of polynomialb. Give value to be substituted
The Greatest Number between 3 Numbers
This c++ program shows the greatest number between 3 numbers use 'if-else-if' statement. It takes three numbers as input from user and output the greatest number. Enter value first
C++ Code Find ASCII Value of a Character
Full form of Ascii is American Standard Code for Information Interchange. It is a character "Encoding Scheme". Originally based on the English alphabet, every character or number
C++ Language The Rules of Abstract Class
1:-) As we have seen that any class that has a pure virtual function is an abstract class. 2:-) We cannot create the "instance" of abstract class. For example: If I have written this line
C++ Programs Finds kth Smallest Element
"Partitioning the array" on the basis of values at high as pivot value. Swapping value at high and at the index obtained. Partitioning array using last element as a pivot. And recursively
C++ & Encapsulations Represents Binding
"Encapsulation" represents binding data and functions into one container. Container hides the details of the data and the way functions process data. In C++, Class is a container that
Calculating Difference Between two Time
Ask to enter two time periods and these two periods are stored in structure variables t1 t2 respectively. The computeTimeDifference() Function calculates the Difference Between
C++ language has many built-in operators
Operator is a symbol that is used to perform "mathematical" or "logical" manipulations. +, -, *, /, %, Addition, Subtraction, Division and Multiplication, Modulus, ++, -- Increment and
C++ Language List of Reserved Keywords
Any "Programming Language" has a "list" of keywords. C++ Keywords are list of reserved words for this Programming Language. Each keyword has a special meaning and it can not
C++ Language Hello World Program Code
Simple C++ program to display "Hello, World" on the screen. Since, it's a simple program, it is often used to illustrate the syntax of a c++ programming language. Every C++ program
Built-in Data Types in C++ Programming
Any programming language has built in data types. Data types are used to create variables or your new data types. Variable is a amount of memory that has its own name and value.
Learn Bitwise Operators in C++ Language
in C++, "bitwise operators" are similar to the Logic operators, but they perform the same logical operations on bits. All data in memory is represented in the "binary form". Variables
Assignment Operations in C++ Language
The operator "=" is an "assignment operator" in C++ and it assigns a value to the objects on the left. C++ Language provides capability to combine assignment operator with almost all
Increment Operator Decrement Operator
Basic "arithmetic operators" are +, -, *, /, %. "Increment operator" is ++ and "decrement operator" is --. These operators can be used as before the variable (prefix) and after the
C ++ Access Functions and Encapsulation
In C++ language, Encapsulation is achieved using access specifiers. In encapsulation we make all member variables private, provide public "functions" which allow user to work
C++ Doing Several Works with 2 Matrices
This is a program of matrix capable of doing several works with two matrices. It can add, subtract, multiply of two matrices and if user wants to see the input entered in 2 matrices
A Simple Function in C++ Programming
A function is block of code which is used to perform a particular task, for example let's say you are writing a "Larger C++ Program", in that program you want to do a particular
Program to Find Largest Element of Array
To find the "Largest Element", the first two elements of array are checked and largest of these two element is placed in arr[0]. Then, the first and third elements are checked and
Program Find Duplicate Elements in Array
Array is the collection of similar data type, In this c++ program we find duplicate elements from an array, Suppose array have 3, 5, 6, 11, 5 and 7 elements, in this array 5 appear two
C++ Programming Opens Reads Text Files
This function reads n lines from a file. Returns the amount of bytes read. Try to open txt file. Try to locate the starting line. Set the starting position. Read the lines. Close the file. Return