Write a program to get the Name, Age, address, phone number from the user and display them by using the class function.
#include<iostream.h>
#include<conio.h>
class sample
{
char name[30];
int age;
char add[30];
int phone;
public :
void getdata(void);
void display(void);
};
void sample :: getdata(void)
{
cout << " Enter your Name : " ;
cin >> name;
cout << " Enter your Age :";
cin >> age;
cout << " Enter your Address :";
cin >> add;
cout << " Enter your Phone Number :";
cin >> phone;
}
void sample :: display(void)
{
cout << "\n Name : " << name;
cout << "\n Age : " << age;
cout << "\n Address : " << add;
cout << "\n Phone Number : " << phone;
}
void main()
{
clrscr();
sample s;
s.getdata();
s.display();
getch();
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
class sample
{
char name[30];
int age;
char add[30];
int phone;
public :
void getdata(void);
void display(void);
};
void sample :: getdata(void)
{
cout << " Enter your Name : " ;
cin >> name;
cout << " Enter your Age :";
cin >> age;
cout << " Enter your Address :";
cin >> add;
cout << " Enter your Phone Number :";
cin >> phone;
}
void sample :: display(void)
{
cout << "\n Name : " << name;
cout << "\n Age : " << age;
cout << "\n Address : " << add;
cout << "\n Phone Number : " << phone;
}
void main()
{
clrscr();
sample s;
s.getdata();
s.display();
getch();
}
OUTPUT:
we cant print 10digits phonenumber using this
ReplyDeletethanks
ReplyDelete