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 →