Write a program to illustrate array of object

Array Of Object

PROGRAM:

#include<iostream>
using namespace std;
class employee{
    int age;
    char name[10];
public:

    void getdata(){
    cout<<"\nEnter name :";
    cin>>name;
    cout<<"\nAge :";
    cin>>age;
    }
    void print(){
        cout<<"\nEntered name :"<<name<<"\tAge: "<<age;
    }
};
int main(){
employee Manager[3],Worker[5];
int i;
for(i=0;i<3;i++){
    Manager[i].getdata();
    Manager[i].print();
}
for(i=0;i<5;i++){
    Worker[i].getdata();
    Worker[i].print();
}
return 0;
}

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