Inheritance-Array of Objects Using Pointers in C++ -Example
#include <iostream>
using namespace std;
class Dukan
{
protected:
int item_number;
string item_name;
public:
void set_data(int num,string name)
{
item_name=name;
item_number=num;
}
void get_data()
{
cout<<"Item number : "<<item_number<<endl<<"Item name is : "<<item_name<<endl<<endl;
}
};
int main() {
int size;
cin>>size;
Dukan *d=new Dukan[size];
for(int i=0;i<size;i++)
{
int num=0;
string name;
cin>>num>>name;
d->set_data(num,name);
d->get_data();
d++;
}
return 0;
}
Comments
Post a Comment