consider the example
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
class employee
{
char name[20];
int num;
float da,bs,it,net;
public:employee(){}
void get()
{
cout%26lt;%26lt;';Enter the name:';;
cin%26gt;%26gt;name;
cout%26lt;%26lt;';Enter register number:';;
cin%26gt;%26gt;num;
cout%26lt;%26lt;';Enter basic salary:';;
cin%26gt;%26gt;bs;
}
void netsalary()
{
da=0.52*bs;
it=0.3*bs;
net=da+bs-it;
}
void disp()
{
cout%26lt;%26lt;name%26lt;%26lt;';\t';%26lt;%26lt;num%26lt;%26lt;';\t';%26lt;%26lt;bs%26lt;%26lt;';\t\t';%26lt;鈥?br>
}
};
void main()
{
employee e[10];
clrscr();
cout%26lt;%26lt;';Enter the number of employees:';;
int n;
cin%26gt;%26gt;n;
cout%26lt;%26lt;';Enter employee details\n';;
for(int i=0;i%26lt;n;i++)
{
cout%26lt;%26lt;';Enter details of employee ';%26lt;%26lt;i+1%26lt;%26lt;';\n';;
e[i].get();
e[i].netsalary();
}
cout%26lt;%26lt;';EMPLOYEE DETAILS ARE\n';;
cout%26lt;%26lt;';\nNAME\tREG NO.\tBASIC SALARY\tNET SALARY\n';;
for(i=0;i%26lt;n;i++)
{
e[i].disp();
}
getch();
}
this is creating object for a class in object oriented programming. it is c++ programming.Creating object for a class in object oriented programming
any class is collection of data members(variables) and methods(functions)
to define an object first define a class
syntax
class class_name
{
public static void main(String args[])
{
class_name object_name= new class_name();
}
}
example in java:
class fruits
{
public static void main(String args[])
{
fruits mango= new fruits();
fruits orange = new fruits();
fruits apple = new fruits();
}
}
Creating object for a class in object oriented programming
taken by example
class student
{
private:
int a;
public:
void getdata();
}
void main()
{
student obj; //declaration of object of a class named student
:
:
:
}
In PHP:
// Class declaration
class Foo
{
public $bar;
function __construct($bar)
{
$this-%26gt;bar = $bar;
}
}
//Object instantiation
$bar = new Foo('foo_bar');
in c++
class class name
//body
}
void main()
{
class name obj;
}
this is just a rough idea in c++ to declare object
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment