Write a C++ program to create a class Person which contains data members as P_Name, P_City, P_Contact_Number. Write member functions to accept and display five Persons information. Design User defined Manipulator to print P_Contact_Number. (For Contact Number set right justification, maximum width to 10 and fill remaining spaces with ‘*’)
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<iostream.h>
#include<conio.h>
#include<iomanip.h> //manipulator
class person
{
char pname[10],city[10]; //pname=person name , no=ph no
int no;
public:
void accept()
{
cout<<"Enter person name: ";
cin>>pname;
cout<<"Enter person city: ";
cin>>city;
cout<<"Enter phone number: ";
cin>>no;
}
void disp()
{
cout<<"\nPerson name: "<<pname;
cout<<"\nPerson city: "<<city;
cout.width(10);
cout.fill('*');
cout.right;
cout<<"\nperson phone number: "<<setw(10)<<no;
}
};
int main()
{
person p; //creating instance of class person
p.accept(); //calling member functions
p.disp();
getch();
return(0);
}
0 Comments