#include<iostream.h>
#include<string.h>
#include<conio.h>
class person
{
char name[10];
int age;
public:
person(char *n,int a)
{
strcpy(name,n);
age=a;
}
void display()
{
cout<<"\n Maximum age person \n";
cout<<"\n ------------------- \n";
cout<<"\n Name:"<<name<<"\n";
cout<<"\n Age: "<<age;
}
person&person::maximum(person &x)
{
if(age>x.age)
return *this;
else
return x;
}
};
void main()
{
char *n1;
int a1;
clrscr();
cout<<"\t\t THIS POINTER USING MAXIMUM AGE OF PERSON\n";
cout<<"\t\t ---------------------------------------------- \n";
cout<<"\n Enter First person name & age:";
cin>>n1>>a1;
person p1(n1,a1);
cout<<"\n Enter Second person name & age:";
cin>>n1>>a1;
person p2(n1,a1);
person p=p1.maximum(p2);
p.display();
getch();
}
-------------
OUTPUT:
-------------
THIS POINTER USING MAXIMUM AGE OF PERSON
----------------------------------------------------------------------
Enter First Person Name & Age : SUDHA
26
Enter Second Person Name & Age: Priya
62
Maximum Age Person
---------------------------
Name: Priya
Age: 62
#include<string.h>
#include<conio.h>
class person
{
char name[10];
int age;
public:
person(char *n,int a)
{
strcpy(name,n);
age=a;
}
void display()
{
cout<<"\n Maximum age person \n";
cout<<"\n ------------------- \n";
cout<<"\n Name:"<<name<<"\n";
cout<<"\n Age: "<<age;
}
person&person::maximum(person &x)
{
if(age>x.age)
return *this;
else
return x;
}
};
void main()
{
char *n1;
int a1;
clrscr();
cout<<"\t\t THIS POINTER USING MAXIMUM AGE OF PERSON\n";
cout<<"\t\t ---------------------------------------------- \n";
cout<<"\n Enter First person name & age:";
cin>>n1>>a1;
person p1(n1,a1);
cout<<"\n Enter Second person name & age:";
cin>>n1>>a1;
person p2(n1,a1);
person p=p1.maximum(p2);
p.display();
getch();
}
-------------
OUTPUT:
-------------
THIS POINTER USING MAXIMUM AGE OF PERSON
----------------------------------------------------------------------
Enter First Person Name & Age : SUDHA
26
Enter Second Person Name & Age: Priya
62
Maximum Age Person
---------------------------
Name: Priya
Age: 62
0 comments:
Post a Comment