Thursday, 7 March 2013

c++ program on contructor overloading (person)

 #include<conio.h>

#include<string.h>

#include<iostream.h>

class person

{

char name[10];

int age,sal;

long double phno;

public:

void getvalue()

{

cout<< "\nenter name of person : ";

cin>>name;

cout<<"\nenter age of person : " ;

cin>>age ;

cout<<"\nenter phone number of person : " ;

cin>>phno;

cout<<"\nenter salary of person : " ;

cin>>sal;

}

void putvalue()

{

cout <<"\nname :" <<name;

cout <<"\nage  :" <<age;

cout <<"\nph no :" <<phno;

cout <<"\nsalary :" <<sal;

}

person(void);

person(char*,int,double,int);

person(person *p1);

};

person :: person(void)

{

strcpy(name,"_____");

age=sal=0;

phno=0;

}

person ::person(char *ch,int a,double p,int s)

{

strcpy(name,ch);

age=a;

phno=p;

sal=s;

}

person ::person(person *p1)

{

strcpy(name,p1->name);

age=p1->age;

phno=p1->phno;

sal=p1->sal;

}

void main()

{

person p2,p3("akash",29,98236589,2000),p4(&p3);

clrscr();

p2.putvalue();

p2.getvalue();

p2.putvalue();

p3.putvalue();

p4.putvalue();

getch();

}

//OUTPUT:

name :_____

age  :0

ph no :0

salary :0

enter name of person : ALOK

enter age of person : 28

enter phone number of person : 2469845

enter salary of person : 2000

name :ALOK

age  :28

ph no :2469845

salary :2000

name :akash

age  :29

ph no :2469845

salary :2000

name :akash

age  :29

ph no :2469845

salary :2000

1 comment: