create class part using constructor accept,display().
#include<iostream.h>
#include<conio.h>
//#include<math.h>
class part
{
int id;
char name[30];
float price;
public:
part(int a=0,char b,float c=0)// parameter constructor
{
id=a;
name[30]=b;
price=c;
}
part(part &x)//copy constructor
{
id=x.id;
name[30]=x.name[30];
price=x.price;
}
void getdata()//using inside class
{
cout<<"\nenter part id:\n";
cin>>id;
cout<<"\nenter part name:\n";
cin>>name;
cout<<"\nenter price:\n";
cin>>price;
}
int displaydata ()//using inside class
{
cout<<"\n part id: \n"<<id;
cout<<"\n part name: \n"<<name;
cout<<"\n price: \n"<<price;
return 0;
}
};
void main()
{
int i,n,k;
part z[10];
clrscr();
cout<<"\n enter how many detail you want to enter";
cin>>n;
for(i=0;i<n;i++)
{
z[i].getdata();
cout.precision(2);
}
for(i=0;i<n;i++)
{
z[i].displaydata();
cout.setf(ios::right,ios::adjustfield);
}
getch();
}
#include<iostream.h>
#include<conio.h>
//#include<math.h>
class part
{
int id;
char name[30];
float price;
public:
part(int a=0,char b,float c=0)// parameter constructor
{
id=a;
name[30]=b;
price=c;
}
part(part &x)//copy constructor
{
id=x.id;
name[30]=x.name[30];
price=x.price;
}
void getdata()//using inside class
{
cout<<"\nenter part id:\n";
cin>>id;
cout<<"\nenter part name:\n";
cin>>name;
cout<<"\nenter price:\n";
cin>>price;
}
int displaydata ()//using inside class
{
cout<<"\n part id: \n"<<id;
cout<<"\n part name: \n"<<name;
cout<<"\n price: \n"<<price;
return 0;
}
};
void main()
{
int i,n,k;
part z[10];
clrscr();
cout<<"\n enter how many detail you want to enter";
cin>>n;
for(i=0;i<n;i++)
{
z[i].getdata();
cout.precision(2);
}
for(i=0;i<n;i++)
{
z[i].displaydata();
cout.setf(ios::right,ios::adjustfield);
}
getch();
}