Thursday, 17 January 2013

Load and view Name and Age with Class in C++

Write this program on Turbo C++ or Bordland C++ , and Save As Details.cpp

#include<iostream.h>
#include<conio.h>

class persion{
char name[10];
int age;
public:
  void getdata(){
  cout <<"Enter Name:";
  cin>>name;
  cout<<"Enter Age:";
  cin>>age;
  }
  void display(){
  cout<<"Age of "<<name<<" is "<<age<<".\n";
  }
};

void main(){
 persion a[20];
 int i,n;
 clrscr();
 cout<<"Enter List Length( Up to 20 ) :";
 cin>>n;
 for(i=0; i<n; i++){
 a[i].getdata();
 }
 for(i=0; i<n; i++){
 a[i].display();
 }
 getch();
 }

 Output:

 Enter List Length( Up to 20 ) :2
 Enter Name:Asif
 Enter Age:19
 Enter Name:Sujan
 Enter Age:18

 Age of Asif id 19.
 Age of Sujan is 18.


Thanks...Comment It...

No comments:

Post a Comment