Knowee
Questions
Features
Study Tools

WAP in C++ to implement array of objects. creating a class employee and accepting and displaying multiple datasets accepted by the user using array of objects.

Question

WAP in C++ to implement array of objects. creating a class employee and accepting and displaying multiple datasets accepted by the user using array of objects.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple program in C++ that creates an array of Employee objects. The program will ask the user to enter the details for each employee and then display them.

#include<iostream>
using namespace std;

class Employee {
    private:
        string name;
        int id;
    public:
        void getData() {
            cout << "Enter Employee ID: ";
            cin >> id;
            cout << "Enter Employee Name: ";
            cin >> name;
        }
        void displayData() {
            cout << "Employee ID: " << id << ", Employee Name: " << name << endl;
        }
};

int main() {
    int n;
    cout << "Enter the number of employees: ";
    cin >> n;
    Employee emp[n]; // array of Employee objects

    // get data for each employee
    for(int i=0; i<n; i++) {
        cout << "Enter details for employee " << i+1 << ": " << endl;
        emp[i].getData();
    }

    // display data for each employee
    for(int i=0; i<n; i++) {
        cout << "Details of employee " << i+1 << ": " << endl;
        emp[i].displayData();
    }

    return 0;
}

This program first asks the user to enter the number of employees. It then creates an array of Employee objects of that size. It then asks the user to enter the details for each employee and stores them in the respective Employee object. Finally, it displays the details of each employee.

This problem has been solved

Similar Questions

draw a neat diagram of WAP architecture and explain in detail

WAP to create an array of 6 integer elements use try and catch block to show exceptionoccured when(i)User enter other than integer throw exception and assign rest value to 0.(ii)user enter other than integer throw exception and assign only that value as 0.

WAJP o define a class Person having name of the person , age of the person and gender of the person. Include accept() and toString() method to display the data. Create 3 objects and display name of the person who is youngestedited 09:01 AM

WAP describing utility of assignment operators

Consider a scenario where you need to manage records of employees in a company. Create aprogram in C that utilizes structures to handle employee information. The program shouldperform the following tasks:a. Define a structure named Employee with the following attributes:Employee ID (integer)Employee Name (string)Department (string)Salary (float)b. Create an array of structures to store information for a maximum of 5 employees.c. Display the information of the employees.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.