Skip to main content

Array of Objects

An array can be of any data type including struct. Similarly, we can also have arrays of variables of the type class. Such variables are called arrays of objects.

Class Definition:

class employee
        char name[30];
        float age;
    public:
        void getdata(void);
        void putdata(void);
};

The identifier employee is a user-defined data type and can be used to create objects related to different employee categories.

employee manage[3];        //aray of managers
employee foreman[15];     //array of foreman
employee worker[75];      // array of worker

the array manager contains three objects(managers), namely, manager[0], manager[1], and manager[2], of type employee class similarly, the foreman array contains 15 objects. and the worker array contains 75 objectives.(workers).

#include <iostream>
using namespace std;

class employee
{
            char name[30];  //string as class members
            float age;
    public:
        void getdat(void);
        void putdata(void);
};

void employee::getdata(void)
{
            cout <<"Enter name: ";
            cin >> name;
            cout << " Enter age: ";
            cin >> age;
}
void employee :: putdata(void)
{
            cout<< "Name: "<<name<<"\n";
            cout<<"Age:"<<age<<"\n";
}

const int size=3;
int main()
{
        employee manager[size];
        for(int i=0; i<size; i++)
        {
                cout<< "\nDetails of manger" <<i+1 << "\n";
                manager[i].getdata();\
        }
        cout <<"\n";
        for(i=0;i<size;i++)
        {    
                cout <<"\nManager" << i+1<<"\n";
                manager[i].putdata();
        }
        return 0;
}

Comments

Popular posts from this blog

Machine Learning Lab Internal Questions

 Internal Lab Programs 1. Read a CSV File, apply preprocessing, apply a few data visualizations, and train SVM model for a dataset and calculate its accuracy. Download DATASET 2. Read the CSV File, apply preprocessing, and train the data decision tree-based ID3 algorithm. Calculate each attribute value and display  3. Create a data and save it CSV, apply preprocessing by using that file demonstrate the FIND-S algorithm for finding the most specific hypothesis based on a given set of training data samples. 4. Read the super Market CSV file apply relevant visualizations (Box plot, Scatter plot, Bargraphs), linear regression and display performance metrics 5. Apply EM algorithm to cluster a set of data stored in a .CSV file. Use the same data set for clustering using k-Means algorithm. Compare the results of these two algorithms and comment on the quality of clustering. 6. Write a program for implementing Density based clustering algorithm.  7. Write a pr...

Big Data Analytics Programs

  List of Programs for Big Data Analytics   CLICK ON ME 1.  Implement the following Data structures in Java       a)  Linked Lists            b)   Stacks       c)  Queues     d)   Set            e)   Map 2.  Perform setting up and Installing Hadoop in its three operating modes:      Standalone,     Pseudo distributed,     Fully distributed. 3.  Implement the following file management tasks in Hadoop:    a) Adding files and directories    b) Retrieving files    c) Deleting files 4. Run a basic Word Count Map Reduce program to understand Map Reduce Paradigm. 5. Write a Map Reduce program that mines weather data.     Weather sensors collecting data every hour at many locations across the globe gather a large volume of log data, which is a ...

How to Install Parrot Operating System in Virtual Box using OVA

Step by Step Process of Parrot OS Installation What is Parrot OS Parrot is a free and open-source Linux system based on Debian that is popular among security researchers, security experts, developers, and privacy-conscious users. It comes with cyber security and digital forensics arsenal that is totally portable. It also includes everything you'll need to make your own apps and protect your online privacy. Parrot is offered in Home and Security Editions, as well as a virtual machine and a Docker image, featuring the KDE and Mate desktop environments. Features of Parrot OS The following are some of the features of Parrot OS that set it apart from other Debian distributions: Tor, Tor chat, I2P, Anonsurf, and Zulu Crypt, which are popular among developers, security researchers, and privacy-conscious individuals, are included as pre-installed development, forensics, and anonymity applications. It has a separate "Forensics Mode" that does not mount any of the system's hard...