Write a program to illustrate array of object

Array Of Object

PROGRAM:

  1. #include<iostream>
  2. using namespace std;
  3. class employee{
  4. int age;
  5. char name[10];
  6. public:
  7.  
  8. void getdata(){
  9. cout<<"\nEnter name :";
  10. cin>>name;
  11. cout<<"\nAge :";
  12. cin>>age;
  13. }
  14. void print(){
  15. cout<<"\nEntered name :"<<name<<"\tAge: "<<age;
  16. }
  17. };
  18. int main(){
  19. employee Manager[3],Worker[5];
  20. int i;
  21. for(i=0;i<3;i++){
  22. Manager[i].getdata();
  23. Manager[i].print();
  24. }
  25. for(i=0;i<5;i++){
  26. Worker[i].getdata();
  27. Worker[i].print();
  28. }
  29. return 0;
  30. }

Comments

Popular posts from this blog

Introduction to ChatGPT: Explain what ChatGPT is, how it works, and what it is used for.

Multi Level Inheritance In cpp

Hybrid Inheritance In cpp