C++ program to accept information about a person and then display it


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class person
{
               char name[30];
               long phone;
               public:
               person()
               {
                              cout<<"\nConstructor initialize\n";
               }
               void getname()
               {
                              cout<<"\nEnter the name\n";
                              gets(name);
                              cout<<"\nEnter the phone number\n";
                              cin>>phone;
               }
               void display()
               {
                              cout<<"\nName\t";puts(name);
                              cout<<"\nPhone number\t"<<phone;
               }
               ~person()
               {
                              cout<<"\n******************\n";
               }
};
class spouse:public person
{
               char spousename[40];
               public:
               void getsp();
               void display();
};
void spouse::getsp()
{
               person::getname();
               cout<<"\nEnter the spouse name\n";
               gets(spousename);
}
void spouse::display()
{
               person::display();
               cout<<"Spouse name\t";puts(spousename);
}
void main()
{
               clrscr();
               spouse obj;
               obj.getsp();
               obj.display();
getch();
}

OUTPUT:


Constructor initialized                                                        
                                                                                
Enter the name                                                                 
ARUN                                                                           
                                                                                
Enter the phone number                                                         
6667070                                                                        
                                                                               
Enter the spouse name
ARUNA                                                                          
                                                                               
Name    ARUN                                                                    
                                                                               
Phone number    6667070

Spouse name      ARUNA
                                                                               
******************

No comments:

Post a Comment