Posts

Showing posts from February 25, 2018

Inheritance in C++ Programming | C++ Programming

Inheritance in C++ Programming  Introduction Inheritance (or derivation) is the process of creating new classes, called derived classes, from existing classes, called base classes. The derived class inherits all the properties from the base class and can add its own properties as well. The inherited properties may be hidden (if private in the base class) or visible (if public or protected in the base class) in the derived class.

Pointers in C Programming | C Programming Language

Pointers in C Programming   In c a pointer is a variable that points to or references a memory location in which data is stored. Each memory cell in the computer has an address that can be used to access that location so a pointer variable points to a memory location we can access and change the contents of this memory location via the pointer. 

Inline function in C++ Programming | C++ Programming

Inline function in C++ Programming A inline function is a short-code function   written and placed before main function   and compiled as inline code. The prototyping is not required for inline function. It starts with keyword inline . In ordinary functions, when function is invoked the control is passed to the calling function and after executing the function the control is passed back to the calling program.           But , when inline function is called, the inline code of the function is inserted at the place of call and compiled with the other source code together. That is the main   feature of inline function and different from the ordinary function.   So using inline function executing time is reduced because there is no transfer and return back to control. But if function has long code inline function is not suitable because it increases the length of source code due to inline compilation. // Inline Function //saves memory, the call to function cause the same co

Function in C++ Programming | C++ Programming

Default Arguments When declaring a function, we can specify a default value for each of the last parameters which are called default arguments. This value will be used if the corresponding argument is left blank when calling the function. To do that, we simply have to use the assignment operator and a value for the arguments in the function declaration. If a value for that parameter is not passed when the function is called, the default value is used, but if a value is specified this default value is ignored and the passed value is used instead.  For example: // default values in functions using namespace std ; int divide ( int a , int b = 2 ) {     int r ;     r = a / b ;     return ( r ); } int main () {     cout << divide ( 12 );     cout << endl;     cout << divide ( 20 , 4 );     return 0 ; } As we can see in the body of the program there are two calls to function divide. In the first one: divide (12) We have only specified one argument, but the

Structured Programming in C++ Programming | C++ Programming

Image
Structured Programming in C++ Programming Structured programming (sometimes known as modular programming) is a subset of procedural programming that enforces a top-down design model, in which developers map out the overall program structure into separate subsections to make programs more efficient and easier to understand and modify similar functions is coded in a separate module or sub-module, which means that code can be loaded into memory more efficiently and that modules can be reused in other programs. In this technique, program flow follows a simple hierarchical model that employs three types of control flows: sequential, selection, and iteration.

C Program For Matrix Multiplication | C Programming

Image
C Program For Matrix Multiplication #include <stdio.h> #include <conio.h> int main () {   int m , n , p , q , c , d , k , sum = 0 ;   int first [ 10 ][ 10 ], second [ 10 ][ 10 ], multiply [ 10 ][ 10 ];   printf ( "Enter number of rows and columns of first matrix \n " );   scanf ( " %d%d " , & m , & n );   printf ( "Enter elements of first matrix \n " );   for ( c = 0 ; c < m ; c ++)     for ( d = 0 ; d < n ; d ++)       scanf ( " %d " , & first [ c ][ d ]);   printf ( "Enter number of rows and columns of second matrix \n " );   scanf ( " %d%d " , & p , & q );   if ( n != p )     printf ( "The matrices can't be multiplied with each other. \n " );   else   {     printf ( "Enter elements of second matrix \n " );     for ( c = 0 ; c < p ; c ++)       for ( d = 0 ; d < q ; d ++)         scanf ( " %d " , & second [ c ][ d ]);    

Matrix Chain Multiplication

Image
Matrix Chain Multiplication Matrix chain multiplication (or Matrix Chain Ordering Problem, MCOP) is an optimization problem that can be solved using dynamic programming. Given a sequence of matrices, the goal is to find the most efficient way to multiply these matrices. The problem is not actually to perform the multiplications, but merely to decide the sequence of the matrix multiplications involved. Here are many options because matrix multiplication is associative. In other words, no matter how the product is parenthesized, the result obtained will remain the same. For example, for four matrices A, B, C, and D, we would have: ((AB)C)D = ((A(BC))D) = (AB)(CD) = A((BC)D) = A(B(CD)) Example of Matrix Chain Multiplication Example: Sequence {4, 10, 3, 12, 20, and 7}. The matrices have size 4 x 10, 10 x 3, 3 x 12, 12 x 20, 20 x 7. We need to compute M [i,j], 0 ≤ i, j≤ 5. We know M [i, i] = 0 for all i. Here P 0 to P 5 are Position and M 1 to