Write the definition of a class PIC in C++ with following description:
Private Members:
- Pno // integer for Picture Number
- Category // String for Picture Category
- Location // String for Exhibition Location
- FixLocaiton() // A member function to assign Exhibition locaiton
// as per category as shown below:
Category Location
Classic Amina
Modern Jim Plaq
Antique Ustad Khan
Public Members:
- Enter() // A function to allow user to enter values of
// Pno, Category & Call FixLocaiton() function.
- SeeAll() // A function to dispaly all the data members.
===============================================
Solution:
===============================================
class PIC
{
int Pno;
char Category[40];
char Location[40];
void FixLocaiton()
{
if(strcmpi(Category,"Classic")==0)
strcpy(Location,"Amina");
else if(strcmpi(Category,"Modern")==0)
strcpy(Location,"Jim Plaq");
else if(strcmpi(Category,"Antique")==0)
strcpy(Location,"Ustad Khan");
}
public:
void Enter();
void SeeAll();
};
void PIC::Enter()
{
cout<<"Enter Picture Number : ";
cin>>Pno;
cout<<"Enter Picture Category: ";
cin.getline(Category,40);
FixLocaiton();
}
void PIC::SeeAll()
{
cout<<"......PICTURE DETAILS......\n";
cout<<"Picture Number : "<<Pno<<endl;
cout<<"Picture Category : "<<Category<<endl;
cout<<"Location : "<<Location<<endl;
}
- Pno // integer for Picture Number
- Category // String for Picture Category
- Location // String for Exhibition Location
- FixLocaiton() // A member function to assign Exhibition locaiton
// as per category as shown below:
Category Location
Classic Amina
Modern Jim Plaq
Antique Ustad Khan
Public Members:
- Enter() // A function to allow user to enter values of
// Pno, Category & Call FixLocaiton() function.
- SeeAll() // A function to dispaly all the data members.
===============================================
Solution:
===============================================
class PIC
{
int Pno;
char Category[40];
char Location[40];
void FixLocaiton()
{
if(strcmpi(Category,"Classic")==0)
strcpy(Location,"Amina");
else if(strcmpi(Category,"Modern")==0)
strcpy(Location,"Jim Plaq");
else if(strcmpi(Category,"Antique")==0)
strcpy(Location,"Ustad Khan");
}
public:
void Enter();
void SeeAll();
};
void PIC::Enter()
{
cout<<"Enter Picture Number : ";
cin>>Pno;
cout<<"Enter Picture Category: ";
cin.getline(Category,40);
FixLocaiton();
}
void PIC::SeeAll()
{
cout<<"......PICTURE DETAILS......\n";
cout<<"Picture Number : "<<Pno<<endl;
cout<<"Picture Category : "<<Category<<endl;
cout<<"Location : "<<Location<<endl;
}
No comments
Post your comments