Sunday, September 25, 2011

Multipath Inheritance in CPP

Hello friends, today I am going to discuss on one type of inheritance in c++. This is "Multipath Inheritance in CPP". Here also discuss about problem in multipath inheritance and how to solve this problem. Multipath Inheritance explains by using a sample c++ example.

What is Multipath Inheritance?

Multipath Inheritance is a hybrid inheritance. It is also called as Virtual Inheritance. It is combination of hierarchical inheritance and multiple inheritance.
In Multipath Inheritance there is a one base class GRANDPARENT. Two derived class PARENT1 and PARENT2 which are inherited from GRANDPARENT. Third Derived class CHILD which is inherited from both PARENT1 and PARENT2.

Problem in Multipath Inheritance

There is an ambiguity problem. When you run program with such type inheritance. It gives a compile time error [Ambiguity]. If you see the structure of Multipath Inheritance then you find that there is shape like Diamond.

Multipath Inheritance

Why Ambiguity Problem in Virtual Inheritance?

Suppose GRANDPARENT has a data member int i. PARENT1 has a data member int j. Another PARENT2 has a data member int k. CHILD class which is inherited from PARENT1 and PARENT2. It has a data member int l.
CHILD class have data member
int l(CHILD class data member)
int j( one copy of data member PARENT1)
int k ( one copy of data member PARENT2)
int i(two copy of data member GRANDPARENT)

This is ambiguity problem. In CHILD class have two copies of Base class. There are two duplicate copies of int i of base class. One copy through PARENT1 and another copy from PARENT2. This problem is also called as DIAMOND Problem.

Solve Multipath Inheritance Problem

To avoid duplicate copies of class Base we inherited intermediary classes with the prefix of the keyword "virtual". We use virtual keyword so it is also called as "Virtual Inheritance".
This results is avoiding duplicate copies of class Base members and in child class have only one copy of base class members.

C++ Program to demonstrate Multipath Inheritance

#include < iostream.h >
#include < conio.h >
class A
int a;
class B: virtual public A
int b;
class C: virtual public A
int c;
class D:public B,public C
int d;
void sum()
void display()
cout<<"Sum of a,b,c is:  " << d ;  
void main() 
D d1;  


when not using virtual keyword as prefix for intermediary class
Compile time error
Member is ambiguous: A::a and A::a

Output When use keyword virtual as prefix intermediary class
Sum of a,b,c =60

Hope, you like this post. If anybody known further details about multipath inheritance then share to others by comments.

Saturday, September 10, 2011

Difference Between C and C++ Programming

Difference Between C and C++ Programming

difference C and C++

C ProgrammingC++ Programming
C follows the procedural programming paradigmC++ is a multi-paradigm language(procedural as well as object oriented)
In C language focus on procedure and steps.C++ focuses on the data rather than the process
In C data hiding and data security is not possible.Data hiding and data security is present.
C uses Top-Down approchC++ uses Bottom-Up approach
C is a function driven programming languageC++ is a object driven programming language
C does not support overloading conceptC++ supports overloading concepts like operator overloading and function overloading
C does not support namespaces conceptCPP supports Namespaces concept.
C not support exception handlingC++ supports Exception Handling
C is structured programming languageC++ is object oriented programming language.
C does not support inheritance, reusability, polymorphism, data abstractionCPP supports inheritance, reusability, polymorphism, data abstraction.
C language only support Early bindingCPP supports both Early and Late binding
C uses standard input, output functions like scanf and printf.C++ uses input function cin and output function is cout.
There are all data is available to end user. No data securityThere is data abstraction. Not complete data is available to End user

C and C++

Sunday, September 4, 2011

C program for Binary Search

Hello, Today I am sharing how to implement Binary Search in C Programming 
language. Here is the basic algorithm for binary search:

C program for binary search :


int main(){
  int a[8];
  int i,x,first,last,mid;

printf("\nEnter 8 sorted elements like 
               [2 4 7 9 12 13 16 20]");
printf("\nYou entered following numbers:");
printf(" %d",a[i]);
printf("\nEnter the number you want to search: ");
printf("\nThe number is found at %d", mid);
        return 0;
      else if(x<a[mid]){

    printf("\nThe number is not in the list");

return 0;


I hope you this post is helpful for you. Thanks for reading.

Saturday, September 3, 2011

How to send email using PHP on WAMP

Hello guys, Today I was trying to fix my friends code problem, He was just trying to send email using php which was running on WAMP Server. Then I recollected this details and shared with him. Here is the step by step guide:

PHP Code for sending an email using mail() function :

 $toAddress = "";
 $emailSubject = "Sample Email";
 $emailBody = "Hello,\n\n\nJust Tesing This Code?";
 if (mail($
, $
, $
)) {
echo("<p>Email successfully sent!</p>"); } else { echo("<p>Error: Email delivery failed...</p>"); } ?>

Configuration in php.ini :
To make the above coe work, you have to set few value in your php.ini of your WAMP installation. Its quit easy to do this, just find your php.ini and replace the default values with the appropriate . 

; For Win32 only.
SMTP = mail.example.come ; for Win32 only
smtp_port = 25
sendmail_from= ; for Win32 only

Now you can use this code for sending emails using your php server which is running either on localhost or on some live domain.

I hope this information is helpful to you. Please share your comments.
Thanks for reading.

Hello World program in Java

Here is the basic java program which will help java beginners.
In every programming language when we initially starts learning,
we always find the "Hello World" program in books.
So in java same program is the first step for you to start with.

Here is the sample "Hello World" Program:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");

Please follow these steps to compile and execute this HelloWorld program.
  1. Open notepad or any type of text editor.
  2. Copy and paste above code into that text editor.
  3. Save that file and named it as ""
  4. Goto command prompt and compile this program using javac command 
    • c:\path\to\file\>javac
    • This will generate a HelloWorld.class file
  5. Now for executing that class file you have to issue following java command
    • c:\path\to\file\>java HelloWorld
  6. You will see Hello, World as the output.
I hope this post helped you in your learning. Please ask your questions by comments.

How to use document.write in JavaScript?

Hello guys, Today I am sharing very basic method of javascript which is "document.write()".
Using document.write you can write inside a html document using javascript.

A very basic hello world example is below:

<script type="text/javascript">
document.write("<p>Hello World</p>");

To understand document.write function in more depth, I am sharing few more simple usage of this function.

<script type="text/javascript">
var sampleText="Sample Example of Document.write function";

Printing date using document.write function:

<script type="text/javascript">
var sampleText="Sample Example of Document.write function";

Using document.write function inside a function:

<script type="text/javascript">
function f1() {
document.write('hello world');

<script type="text/javascript">
document.write('Ba Bye');

Overriding whole document's content using document.write function:
<script type="text/javascript">
function f1() {
document.write('Some text');//for overwrite entire page content
window.onload = w1;

I hope you like this post. Please share your feedback by commenting below.