Wednesday, October 13, 2010

Graphics in C Language Tutorial

,


C and C++ Very Useful Language for Creating Application and programs. It provide a platform for developing a application with many functionality. But we know that mostly users attract Interface design. Design of application gives easy to use for users, he can user any application easily by UI. All programmings language can easily implement with graphic eg: C,C++,PHP,.net etc. Here we are learning about Graphic in C language with example, graphics.h library is used for create GUI (Graphic User Interface).
Learn with below example :


#include <stdio.h>
#include <conio.h>
#include <graphics.h>


void main()
{
  int gd=DETECT,gm;
  clrscr();
  initgraph(&gd,&gm,"..\bgi");
  putpixel(100,100,WHITE);
  line(50,50,150,150);
  rectangle(200,200,400,400);
  closegraph();
  getch();
}
Read more →

What is Call By Value in C

,


In C Programmings we have different ways to parameter passing schemes such as Call by Value and Call by Reference.

Call By Value:- In the Call By Value the function is to be called by passing the value in the parameter of a function called. By default, C programming language uses call by value method to pass arguments.

There are the two type of a arguments which are passed in the function.

1) Formal Arguments:- Formal Arguments is the parameters which are passed in th function where the function body define.

2) Actual Arguments - Actual Arguments are those arguments which are passed in the function ,where the function called.

Why we use call By Value:-  In the Call By value when a function is called then the actual arguments are used and the value is passed in this argument.The control transfers to the function body then these values of actual arguments are being copied to the formal arguments and further processing start.

So there values are local to this block and does not take effect in the actual arguments. So that once the control get back to the main block then these values are completely vanished.These whole procedure are occurred in call by value. In below example we are swapping values with Call By Value


Example:-


/* function definition to swap the values */
void swap(int a, int b)
{
   int xx;
   xx = a;
   a = b;
   b = xx;
   return;
}

#include <stdio.h>
#include <conio.h>

void swap(int a, int b);
int main ()
{
   int m = 20;
   int n = 10;
   printf("Before swap, value of m : %d\n", m );
   printf("Before swap, value of n : %d\n", n );

   swap(m, n);

   printf("After swap, value of m : %d\n", m );
   printf("After swap, value of n : %d\n", n );

   return 0;
}
Read more →

What is Call By Reference in C

,


In C Programmings we have different ways to parameter passing schemes such as Call by Value and Call by Reference.

Call by Reference:- Reference means the address not the actual value, the address of a variable or anything. So in the call by reference we use the address of a variable instead of passing the value of a variable in the function. When we want to use address we have to use the concept of pointer because pointers have the capability to store the addresses of a variable.

In the function calling the actual arguments can send the addresses of a variables. In the function body the format arguments are to be treated as the pointers in which the address of a actual arguments are to be stored. So that the value is passed on the actual arguments are to be get by address in the formal arguments and the operations are to performed on addresses and when the control get back on the main block. These value would be remain same. Hence, result is that the changes made in the arguments are permanent.

In below example we are swapping values with Call By Reference.

Example:-

/* function definition to swap the values */
void swap(int *a, int *b)
{
   int xx;
   xx = *a;
   *a = *b;
   *b = xx;
   return;
}


#include <stdio.h>
#include <conio.h>

void swap(int *a, int *b);
int main ()
{
   int m = 60;
   int n = 80;
   printf("Before swap, value of m : %d\n", m );
   printf("Before swap, value of n : %d\n", n );

   swap(&m, &n);

   printf("After swap, value of m : %d\n", m );
   printf("After swap, value of n : %d\n", n );

   return 0;
}
Read more →

How to Use Union in C Programming

,



Union is a derived datatypes which group together a number of variable . Union is like a structure in c language which used to store one of a set of different types. A union holds the value of one-variable at a time. C Programming provide this facility which help to share same memory with different different variables. Accessing members of a union is via “.” member operator or, for pointers to unions, the -> operator.

union syntax in c :

union union_name
 {
  <datatype> first_element 1;
  <datatype> first_element 2;
  <datatype> first_element 3;
 };


Examples of  Union in C language

#include <stdio.h>
#include <conio.h>

union tech
{
 int i;
 char name[50];
};

void main()
{
  union tech a;
  printf("\n\t Enter developer id : ");
  scanf("%d", &a.i);
  printf("\n\n\t Enter developer name : ");
  scanf("%s", &a.name);
  printf("\n\n Developer ID : %d", a.i);//Garbage
  printf("\n\n Developed By : %s", a.name);
  getch();
}
Read more →

C Storage Classes With Examples

,

Storage Class refers to the persistence of a variable (life time) and its scope within the program, that is, the portion of the program over which the variable is recognized.

The following types of storage-class specifications in C Language.

  • global
  • automatic or local
  • static
  • extern

The visibility of a variable determines how much of the rest of the program can access that variable. You can arrange that a variable is visible only within one part of one function, or in one function, or in one source file, or anywhere in the program.


Global Variables : A variable declared outside of any function is a global variable, and it is potentially visible anywhere within the program.

int sum=0; /* Declare global variables outside */

main()
{
 
}

Automatic or local variables : A variable declared within the braces {} of a function is visible only within that function; variables declared within functions are called local variables. You can use the keyword auto to declare automatic variables, but, however it is optional.

#include<stdio.h>

main()
{
 auto int n; /* Here the keyword auto is optional */
}

Static Variables : Static variables are defined within individual functions and therefore have the same scope as automatic variables, i.e. they are local to the functions in which they are declared. Unlike automatic variables, however, static variables retain their values throughout the life of the program.

static int count;

main()
{

}

External Variables : When you have multiple files and you define a global variable or function which will be used in other files also, then extern will be used in another file to give reference of defined variable or function.
Read more →

Static Function in C Language

,

By default any function that is defined in a C file is extern, which means they're visible across translation units. But when we use “static” keyword it restricts visibility of the function to the translation unit in which it's defined.

static int sfun(void)
{
  printf("I am a static function ");
}

when we want to restrict access to functions, we make them static. Static functions are functions that are only visible to functions in the same file and they are not callable from outside.

/* a.c */
static void sfun1(void)
{
  puts("sfun1 called");
}

And store following program in another file b.c

/* b.c  */
int main(void)
{
  sfun1();
  getchar();
  return 0;
}

we get the error “undefined reference to `sfun1′”. 
Read more →

Type Casting in C Language

,

Type casting is a way to convert a variable from one data type to another data type. Type Casting is force to convert one data type to another data type. The process of such local conversion is known as casting a value. The general form of cast is: (type-name) expression where type-name is one of the standard C data types.

Consider, for example, the calculation of salary of employee to engineers in a town.

salary = amount / days

Since amount and days are declared as integers in the program, the decimal part of the result of the division would be lost and salary would represent a wrong figure. This problem can be solved by converting locally one of the variables to the floating point as shown below:

salary = (float) amount / days

The operator (float) converts the amount to floating point for the purpose of evaluation of the expression.


Example 
Action 
X=(int) 8.5  8.5 is converted to integer by truncation. 
A=(int) 21.3 / (int) 4.5  Evaluated as 21/4 and the result would be 5. 
B=(double) sum/n  Division is done in floating point mode. 
Y= (int) (a+b)  The result of a+b is converted to integer. 
Z= (int) a+b  a is converted to integer and then added to b. 
P=cos(( double)x)  Converts x to double before using it. 
Read more →

What is Loops in C and C Plus Plus Programmings

,
Introduction

Loops in simple languages it's process of round (circle) of a work or activity. C and C Plus Plus also provide this function in c  and c plus plus. It provide a function which repeat your code in a block. It itterate you code and execute until work when condition will not be false.

Types of Loops

1. While Loop
2. Do While Loop
3. For Loop

While Loop:- While Loop is another type of loop which very useful for C Programmings.  In this loop in case we are using increament or decrement with condition. then atleast one time increament or decrement will be run. Either it's true or false condition.

Examples of Do While loop

# Include
main()

{

int a,i;

a=1;
while (x=10);
{

printf(x++);

}

}


Do While:-Do While Loop is another type of loop which very useful for C Programmings.  In this loop in case we are using increament or decrement with condition. then 1st Condition check after then increment and decrements is possible.


# Include
main()

{

do
{
while (x=10);
}
{

printf(x++);

}

};


For Looop:-For Loop is another type of loop which very useful for C Programmings.  In this loop in case we are using increament or decrement with condition. then we can intialize the value, test the condition and increament or decrement at a time

# Include
main()

{

int a;
for (i=0;i<=5;i++)
{

printf("%d",i);
}

};
Read more →

Data Types in C Language With Size

,

C has a concept of 'data types' which are used to define a variable before its use. C compilers support four fundamental data types, namely integer (int), character (char), floating point (float), and double-precision floating point (double). Like integer data type, other data types also offer extended data types such as long double and signed char.

Data Type

Data Type of a variable tell to the compiler
  • Name of variable
  • Which type of value that variable can hold
  • How much memory space it reserve
1. Primary data type or predefined data type or Fundamental data type - are those data type that are defined in c already.
Data Type
Used for
Size(in Byte)
Range
Format
Int Integer 2 -32768 to 32767
%d
Char Character 1 -128 to 127
%c
Float Single precision floating point number 4 -3.4e38 to +3.4e38
%f
Double double precision floating point number 8 -1.7e308 to +1.7e308
%lf
Void - - -
0


Data Type Modifiers –There are four modifiers available.
  • Signed
  • Unsigned
  • Short
  • Long
Data Type
Size(in Byte)
Range
Format
signed char  1 -128 to + 127
%c
unsigned char  1 0 to 255
%c
signed int  2 -32768 to +32767
%d
unsigned int  2 0 to 65535
%u
short signed int  2 -32768 to +32767
%d
short unsigned int  2 0 to 65535
%u
long double  10 -1.7e4932 to +1.7e4932
%Lf

2. Derived data type - are those data type that are derived by predefined data type.

Example-Array, pointer


3. User defined data type - are those data type that are defined by the user itself.

Example-struct, union

Read more →

File Handling in C Language

,

File handling means one can perform operations like create, modify, delete etc on system files. You want to read from or write to one of the files you're working with, you identify that file by using its file pointer.

File Handling Funtions :

fopen() : The fopen() function is used to open a file and associates an I/O stream with it.

The mode string "r" indicates reading. Mode "w" indicates writing, so we
could open. The third major mode is "a" for append. mode is "+" for read and write. Mode "b" character to indicate that you want to do “binary''

fread() and fwrite() : The functions fread/fwrite are used for reading/writing data from/to the file opened by fopen function.

fseek() : The fseek() function is used to set the file position indicator for the stream to a new position.

fclose() : The fclose() function first flushes the stream opened by fopen() and then closes the underlying descriptor.

You declare a variable to store a file pointer like this:

FILE *fp;

If you were reading from one file and writing to another you might declare an input file pointer and an output file pointer:

FILE *ifp, *ofp;

One thing to beware of when opening files is that it's an operation which may fail, file might not exist, or it might be protected against reading or writing. Fopen returns a null pointer if it can't open the requested file, and it's important to check for this case before going off and using fopen's return value as a file pointer. eg:

ifp = fopen("input.dat", "r");
if(ifp == NULL)
{
 printf("can't open file\n");
 exit or return
}


Example : Writing a data to the file

#include <stdio.h>
main( )
{
  FILE *fp;
  char stuff[25];
  int index;
  fp = fopen("TENLINES.TXT","w");
  strcpy(stuff,"This is an example line.");
  for (index = 1; index <= 10; index++)
  fprintf(fp,"%s Line number %d\n", stuff, index);
  fclose(fp);
}

Read more →

String In C Language

,


The string in C programming language are represented by arrays of characters. The end of the string is marked with a special character, the null character, which is simply the character with the value 0. Whenever we write a string, enclosed in double quotes, C automatically creates an array of characters for us, containing that string, terminated by the \0 character.

For example, we can declare and define an array of characters, and initialize it with a string constant:

char string[ ] = "Hellopg";



Print With Example :

#include <stdio.h>
int main ()
{
   char Value[8] = {'H', 'e', 'l', 'l', 'o','p','g', '\0'};
   printf("Greeting message: %s\n", Value );
   return 0;
}

 
 Function  Purpose
 strcpy(s1, s2); Copies string s2 into string s1.
 strcat(s1, s2); Concatenates string s2 onto the end of string s1.
 strlen(s1); Returns the length of string s1.
 strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.
 strchr(s1, ch); Returns a pointer to the first occurrence of character ch in string s1.
 strstr(s1, s2); Returns a pointer to the first occurrence of string s2 in string s1.

Copy Function :

#include <string.h>

char string1[ ] = "Hello, world!";
char string2[20];
strcpy(string2, string1);

Try all function and observe result.
Read more →

How structures are to be used in c

,
Read more →

Thursday, October 7, 2010

What is Inheritance?

,
What is Inheritance?

Inheritance is one of the important feature of the OOP.Inheritance is the method by which objects of one class gets the properties of another class.

Advantages of Inheritance?

Sometimes we need to repeat the code or we need repeat the whole class properties. So It helps in various ways.

1.) It saves memory space.

2.) It saves time.

3.) It will remove frustration.

4.) It increases reliability of the code

5.) It saves the developing and testing efforts.

Why we use Inheritance?

To increase the reusability of the code and to make further usable for another classes. We use the concept of inheritance.

How Inheritance can be achieved?

In the inheritance there will be a parent child relationship .There is a class called in which all the properties are defined and generally,it is refered as a base class.There is also an another class in which is derived from the existing one are known as a derived class.

Types of Inheritance

There are Five types of Inhertance found in Object Oriented Programming.

1.)Single Inheritance

2.)Multiple Inheritance

3.)Hierarchical Inheritance

4.)Multiple Inheritance

5.)Hybrid inheritance
Read more →

Tuesday, September 7, 2010

static data member in c++ | How to use Static Data Member

,
Static data member:-The static is a keyword and are used to retain value of a variable.
When a variable is declared as static it is initialised to zero
.A static function or data element is only recognised inside the scope of the current.
if the local variable is declared with static keyword.it allows the last value of the variable to be retained between continuation calls to that function.
A static data  item is helpful when all the objects of the class should share a common data.
The satic data variable is accessible within the class,but its value remains through the whole program.


class sumnum
{
private:
static int c;
int num;
public:
void input()
{
cout<<"\nEnter number:";

cin>>num;
c=c+num;
}
void sum()
{
cout<<<"the sum"<
}
};
int sumnum:: c=0;
int main()
{
class sumnum a,b,c;
clrscr();
a.input();
b.input();
c.input();
a.sum();
return 0;
}
Read more →

Classes in Cplusplus | How to use Class in C++

,
A class is a group of Objects that have the identical properties,common behavior, and shared relationship.
The entire group of data and code of an object can be built as a user-defined data type using class.
Objects are nothing but variable of type class.
A class is a model and not a true structure of the object
.However it shares the property names or operations with other objects of the class.


#include<iostream.h>
#include<conio.h>
 Class p
{
Private :
Char n [20];
Public :
Float h ;
Float w ;
} ;
Int main ()
{
Clrscr ()
p a;
//a.n =”Sanjay”;// not accessible
a.h = 5.5;
a.w = 38;
cout <<”H : “<
cout<<”W: “<
return 0;
}

OUTPUT

Height : 5.5
Weight : 38

Read more →

How to use functions in Cplusplus

,
Why we are use Function?

Function is a block of task, In simple word we can say that it's block which we contain instruction or procedure. Which is very useful when we need some procedure or instruction block which execute process and less of development time for a software or solution any kind C and C++ program.


Types of Function

1. Parameterize Function
2. Non Parameterize Function
3. Friend Function
4. Virtual Function

Guidelines for using function.
1. Always define prototype
2. When we use friend function use friend keyword
3. In virtual function use keyword virtual

Example of Function in C plus plus


#include<iostream.h>
#include<conio.h>
Int main()
{
Clrscr();
Float sum (int,float);
Int a=20;
Float b=2.5;
Cout <<”sum=”<
Return 0;
}
Float sum (int  x,float  y)
{
Return (x+y);
}

OUTPUT
Sum = 22.5

Read more →

Sunday, August 29, 2010

How to use Pointer in c tutorial | Pointers in Cplusplus | pointer in c language

,
What is Pointer?

Pointer is very important in C and C++. It's  a variable which stores memory of user type and primary variable. It Hold the value of memory of a variable.

Why we use Pointer?
Some time we need to storing the address of variable for solving this problem we use pointer which capable to storing the memory address of a variable.

Guideline for using pointer
1. Define * When we use pointer
2. when we store address of pointers of pointer then we use **variable name

Example of Pointer

#include<iostream.h>

int main ()
{
int first,second;
int * ptr;
ptr = &first;
*ptr = 10;
ptr = &second;
*ptr = 20;
cout << "first is " << first << endl;
cout << "second is " << second << endl;
return 0;
}

Output:- First is =10
Second is =20
Read more →

String Operations in cplusplus

,
String Handling:-A string is a collection of  characters.String is  a class in cplusplus and there are three constructors in the String class.
1.)String():-For creating an empty string
2.)String(Const char *str):-For creating a string object from a null terminated string
3.)String(const string &str):-For creating a string object from other string object

#include<iostream.h>
#include<string.h>
void main( )
{
char ch1[] = “Cplusplusexample”;
char ch22[80];
for(int i=0; i
ch2[i]=ch1[i];
ch2[i]=’\0’;
cout<< “The copied string is “<< ch2;
}
Output:-The copied string is Cplusplusexample
Read more →

Exception Handling in Cplusplus

,
Exception handling:-Exception Handling is used in object oriented programming.It is feature by which we can handle easily a lot of feature.so that u can easily debug the code and to find the where the actual problem reside.In the Exception Handling we can use the try and the catch block
In the try block we can use the code in which the error may be occured that are to be placed in try block.
In the catch block particular error are to be handled in which way.The solution of particular error are provided in the catch block.
Example:-
#include<iostream.h>
int  main()
{
int a,b;
cout<<”Enter Values of a and b\n”;
cin>>a>>b;
int x=a-b;
try
{
If(x!=0)
{
cout<<”Results(a/x)=”<<<”\n”;
}
else
{
 throw(x);
}
}
catch(int i)
{
cout<<”Exception Caught :x=”<<<”\n”;
}
cout<<”END”;
return 0;
}

Output1:-            Enter Values of a and b
                                400       20
Result(a/x)  =   20
END

Enter Values of a and b
                                20           20
Exception Caught:   x =   0
END


Read more →

Thursday, August 26, 2010

Vectors

,
Read more →

Function overriding in c++ | What is Function overriding

,
Read more →

Recursion

,
Read more →

Access Modifiers

,
Read more →

What is Base class in c++ and How to use with derived class c++

,
Read more →

Derived class

,
Read more →

Preprocessor directives

,
Read more →

Difference between Structure and classes

,
Read more →

Command Line Arguments

,
Read more →

Example of constructor overloading c++ | How to Constructor Overload

,
class CO
{
   private:
       int a;
       int b;
       int c;
  public:
      CO(int x,int y,int z);
      CO(int x,int y);
      CO();
      void   show()
      {
          cout<<"\na="<<"b="<<<"c="<
      }
};


Read more →

Array Of objects

,
Read more →

Delete Operator

,
Read more →

Memory Management Operators

,
Read more →

cout object

,
Read more →

cin object

,
Read more →

Compiling and linking

,
Read more →

Structure of C++ Program

,
Read more →

Nesting of Classes

,
Read more →

Dynamic Binding

,
Definition of Dynamic Binding:-Binding means that  a procedure call of the code is executed , when we call the particular code.
Dynamic Binding means at the run time we know that which code is particularly associated to which code.
Dynamic Binding also known as Late Binding.
It is generally associated with polymorphism and Inheritance.
Read more →

Data Hiding

,
Read more →

Message Passing

,
A mesage for an object is a request for execution of a procedure,and therefore will invoke a function in the receiving object that generates the desired result

Example:-Employee.salary(name);
Read more →

Encapsulation

,
What is Encapsulation?

The packing of data member and member functions into a single component is called Encapsulation.The data is not reached by the outside functions.Only those functions that are able to access the data are defined within a class.Class is the best example of Encapsulation.
Read more →

Abstraction

,
Read more →

Compile time polymorphism

,
Read more →

Runtime Polymorphism

,
Read more →

Late Binding

,
Read more →

Early Binding

,
Read more →

Arrays In Cplusplus

,
Read more →

Do-While Loop

,
Read more →

While-Loop

,
Read more →

For-Loop

,
Read more →

Polymorphism

,
Read more →

Default Constructor

,
Read more →

Monday, August 16, 2010

Scope Resolution Operator

,
Definition of Scope Resolution Operator:-The scope access(or resolution operator)operator :: (the two semicolons)allow programmers to access a global name even if it is hidden by a local re-declaration of that name.
When we declare a variable it is available only to a specific part or block of the program.Remaining block cannot access the variable .The area of a block where the variable is accessed is known as the scope resolution operator.


Example:-#include
int a=10;
main()
int a=20;
cout<<"::a"<<::a;
cout<<"a="<
return 0;

Result:- 10
20
Read more →

Operators

,
Read more →

Saturday, August 14, 2010

Constants

,
Definition Of Constant:-The constants in C and C++ are applicable to the values ,which do not change during the execution of a program.
There are a several type of constants in C and C++.They are Claasified into various categories are as follows:-
1.)Integer Constant
2.)Real Constant
3.)Character Constant
4.)String Constant

1.)Integer constant:-Integer constants are those who provide the numbers are either positive or negative.
Example:-const int a=5;

2.)Real Constant:-The real constants can be written in exponential notation,which contains a fractional part and an exponential part.
Example:-Const float=3.4;

3.)Character Constant:-A character constant is a single character constant.A digit,alpahabets,white space enclosed with a pair of single quote marks.
Example:-Const char ch='a';

4.)String Constants:-A String constant is a collection of characters enclosed with a pair of double quote marks.
Example:-"Anusha";







Read more →

Identifiers

,
Definition of Identifiers:-Identifiers are the names of variables,functions,arrays and classes.They are the user-defined names,consisting of sequence of letters and digits.The underscore is also permitted if u want ,u can use it according to need.

Example:- 1.) Class person
{ };
2.)void show
{ };
Read more →

Keywords

,
Read more →

Tokens

,
Read more →

Enumerated data Types

,
Read more →

Function Overloading

,
#include<iostream.h>
#include<conio.h>
Int sqr  (int);
Float sqr (float);
Main ()
{
Clrscr ();
Int a= 15;
Float b = 2.5;
Cout <<”Square =”<<<”/n”;
Cout <<”Square =”<<<”/n”;
Return 0;
}
Int sqr (int s)
{
Return (s*s);
}
Float sqr (float j)
{
Return (j*j);
}

OUTPUT

Square = 225
Square = 6.25

Read more →

Operator Overloading

,
Read more →

Copy Constructor

,
Read more →

Parameterized constructor

,
Read more →

Destructor

,
Read more →

Static functions

,
Read more →

Typecasting in C and C++

,
Read more →

Inline functions

,
Read more →

Default Arguments

,
C++ lets the programmer to assign default values in the function prototype declaration of the function.When the function is called with less parameter or without parameters the default values are used for the operations .It is not allowed to assign default values to any variables,which is between the variable list.

Example:-

#include<iostream.h>
#include<conio.h>
int main()
{
Clrscr ();
int sum (int a, int b=10, int c=15, int d=20);
Int a=2;
Int b=3;
Int c=4;
Int d=5;
Cout<<”Sum=”<
Cout<<”/nSum=”<
Cout<<”/nSum=”<
Cout<<”/nSum=”<
Cout<<”/nsum=”<
Return 0;
}
Sum(int j, int k, int l, int m)
{
Return (j+k+l+m);
}

OUTPUT :

Sum = 14
Sum = 29
Sum = 40
Sum = 47
Sum = 32

Read more →

Manipulators

,
Read more →

This Pointer

,
Read more →

Data Types in c++

,
Read more →

Interfaces

,
Read more →

Abstract Class

,
Read more →

Virtual Base Class

,
Read more →

Pure Virtual functions

,
Read more →

Virtual functions

,
Read more →

Hybrid inheritance

,
Hybrid Inheritance:- It is a combination of two of the inheritance Multiple and hierarchical
Inheritance

Example:-
class A
{
A()
{

Cout<<”I m in A”;
}
};
Class B:public A
{
B()
{
Cout<<”I m in B”;
}
};
class C:public C
{
C()
{
Cout<<”I m in C”;
}
};
Class D:public B,public C
{
D()
{
Cout<<”I m in D”;
}
};
Voi d main()
{
D d;
}

Output:-
I m in A
I m in B
I m in C
I m in D
Read more →

Hierarchical inheritance

,
Hierarchical Inheritance:-In the Hierarchical Inheritance there is only base class and all
the derived classes are derived from this base class.
Example:-
class A
{
A()
{
Cout<<”I m in A”;
}
};
Class B:public A

{
B()
{
Cout<<”I m in B”;
}
};
class C:public A
{
C()
{
Cout<<”I m in C”;
}
};
Class D:public A
{
D()
{
Cout<<”I m in D”;
}
};
Voi d main()
{
D d;
}

Output:-
I m in A
I m in B
I m in C
I m in D
Read more →

Multilevel Inheritance

,

 Multilevel Inheritance:-In the Multilevel Inheritance there is one base class and other class which is derived from this base class is called derived class. The process of deriving a class  from another derived class.


class A
{
A()
{
Cout<<”I m in A”;
}
};
Class B:public A
{
B()
{
Cout<<”I m in B”;
}
};
class C:public B
{
C()
{
Cout<<”I m in C”;
}
};
Class D:public C
{
D()
{
Cout<<”I m in D”;
}
};
Void main()
{
D d;
}


Output:-I m in A
I m in B
I m in C
I m in D



Read more →

Multiple Inheritance

,
Multiple Inheritance:-I n the multiple Inheritance there will be many base classes and there is only one derived class which derives from all the base classes.

Example:-
class A
{
A()
{
Cout<<”I m in A”;
}
};
Class B
{
B()
{
Cout<<”I m in B”;
}
};
class C
{
C()
{
Cout<<”I m in C”;
}
};
Class D:public A,public B,public C
{
D()
{
Cout<<”I m in D”;
}
};
Voi d main()
{
D d;
}

Output:-
I m in A
I m in B
I m in C
I m in D
Read more →

Single Inheritance

,
Single Inheritance:-In the Single Inheritance there will only one base class and only one derived class.It should be like this.
Example:-
class A
{
A()
{
Cout<<”I m in A”;
}
};
Class B:public A
{
B()
{
Cout<<”I m in B”;
}
};
Voi d main()
{
B b;
}

Output:-I m in A
I m in B
Read more →

C++ Description

,
Read more →

Difference between C and C++

,
Read more →

Thursday, July 22, 2010

What is C++ Constructor, and How to use Constructor with Inheritance

,
A constructor is a special type of function whose functionality is to intialize the data members of a class at a time of object creation.so that it is also called automatic intialization of objects.

Properties of a constructor:-
1.)It is invoked automatically at a time of the creation of object.so that the data members are intialized.

2.)It has neither return type nor void type.

3.)The name of a constructor and class should be identical.

4.)It should be declared on a public section.


Types of aconstructor:-

1.)Default Constructor.
2.)Copy Constructor.
3.)Parametrised constructor
Read more →

Thursday, July 8, 2010

Use of Friend Function

,
Friend Function is a very nice feature of C++. You know that when we write a programme in c ++ we also use class. We also define members of classes which are accessible or not. In this post we'll discuss what is friend function, what the use of friend function, and how to use of friend function.

1. What is friend function

What function is ordinary function and another feature of C++. Which is very useful when we use Private or Public classes both.

2. What the use of friend function

Some Time we write programme in C++ and declare some member private and some public but in case we another class which not derived to main class and we need to use member of main class then friend function provide a facility to access private member in any class.

3. How to use friend function

It's easy to use and not complex we just declare this function with keyword of friend






Read more →

Wednesday, July 7, 2010

what is object in c++

,
In C++ be are Write many because it's object oriented programming language (OOPS). But Many beginner student of C++ confuse what is Object and how to use. In this post we'll discuss about Object of C++ and, What is Object, How to use.

What is Object.

Objects are the basic runtime entities in any system.Objects are behave as a container which contains the properties of a class.


How to use

For Example:-Student is a class and the student1 is the object of class student.

class student
{
char name[50];
void display();
};

student student1; //object created of class student

student1 contain the name and by the use of this object.we can call display function

Read more →

Friday, July 2, 2010

Example of If Else Statement in C

,

If else statement is very useful in any programming language.  An if statement may also optionally contain a second statement, the “else" clause which is to be executed if the condition is not met.

Here is an example:

if(n > 0)
{
average = sum / n;
else {
printf("can't compute average\n");
average = 0;
}

The general syntax of an if statement in c:

if ( expression )
statement(s)
else
statement(s)


This feature is based in our daily life many times we think if we do or else not. eg: if i will reading carefully and properly i'll get good marks if i'll not reading i am not get good marks same procedure is if else.

> Here need to decide division of the student with the percentage

#include <stdio.h>
#include <conio.h>

main()
{
  int percentage;
  printf("Enter the percentage : ");
  scanf("%d", &percentage);
   if (percentage >= 70)      
     printf("Passed: Grade A \n");
   else if ((percentage >=40) && (percentage <=70))
     printf("Passed: Grade B \n");
   else if ((percentage >=35) && (percentage <=40))      
     printf("Passed: Grade C \n");
  else      
   printf("Failed\n");
}

We have entered 60 and the result is Passed: Grade B.


Read more →

What is Loop in C++

,
Loop is a block code which is very useful in C or Cplusplus Programming. In real life many times we need some work in a repeated way. C and Cplusplus also provide this feature in programming we can easy to create loop which is help to your program when you need some repeat work. Loops are 2 types
1. Entry Control Loop.
2.)Exit Control Loop.



Q. if we need print a name in 10 times then we have 2 option first is write the printf command in 10 times and second is use loop


In C

# Include
# include
main()
{

int i;
char name[]={"abcd"};
for (i=1;i<=10;i++)
{

printf("%s",name);
}

in C++


# Include
# include
main()
{

int i;
char name[]={"abcd"};
for (i=1;i<=10;i++)


cout<



}

We can also write through Do while and While loop

Do While Loop

Do
{

statement

}

While Loop


main()

{

i=0;
while i<=10
{

statement

i++

}
}
Read more →

Tuesday, June 29, 2010

What is Object Oriented Programming Language

,

What is OOP?

OOP refers to the object oriented programming which enables the feature of several new concepts by using this the programming become more easier than the conventional programming. In C++ have many features which is very useful and depend on real world entities. Some Features of OOPS Programming Languages are as follows:

1. Inheritance
2. Polymorphism
3. Data Hiding
4. Abstraction
5. Classes and Objects
6. Encapsulation
7. Dynamic Binding
8. Message Passing

Benefits of OOP

It ties data more securely to the functions that operate on it and prevents it from accidental change from external functions. Following are the impressive characteristics of OOP :-

  • Importance of data partially then functions.
  • Programs are divided into objects.
  • New data items and functions can be comfortably added whenever essential.
  • Data is private and prevented from accessing external functions.
  • Object can communicate among each other through functions.


Read more →