Skip to main content

Command Palette

Search for a command to run...

Array Of Objects

Published
•1 min read•View as Markdown
Array Of Objects
L

I've got accomplished web development with expertise in various programming languages including PHP, Laravel, C#, and C++. My curiosity to learn more and my passion for coding drives me to constantly enhance my skills and create exceptional digital experiences.

An array of objects is and could be constructed exactly like how we create an array of int or other datatypes.

#include <iostream>
#include <string.h>
#include <conio.h>
using namespace std;

class Employee
{
    string name;
    int salary;

public:
    void setinfo(void)
    {
        cout << "Enter Your Name " << endl;
        cin >> name;
        salary = 12000;
    }

    void getinfo(void)
    {
        cout << "You Name is " << name << " Salary is " << salary << endl;
    }
};
int main()
{
    // Employee laiba ;
    // laiba.setinfo();
    // laiba.getinfo();

    Employee emp[4];
    for (int i = 0; i <= 4; i++)
    {
        emp[i].setinfo();
        emp[i].getinfo();
    };
    return 0;
}