0% found this document useful (0 votes)
7 views

Experiment No 3 Oop

Uploaded by

pranilmali1131
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Experiment No 3 Oop

Uploaded by

pranilmali1131
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

3
Code :-
#include <iostream>

#include <string>

using namespace std;

class Employee {

private:

int empID;

string empName;

float empSalary;

public:

void setEmployeeDetails(int id, string name, float salary) {

empID = id;

empName = name;

empSalary = salary;

void displayEmployeeDetails() {

cout << "Employee ID: " << empID << endl;

cout << "Employee Name: " << empName << endl;

cout << "Employee Salary: $" << empSalary << endl;

cout << "------------------------------" << endl;

};

int main() {

Employee employees[3];
int id;

string name;

float salary;

for (int i = 0; i < 3; i++) {

cout << "Enter details for Employee " << i + 1 << ":" << endl;

cout << "ID: ";

cin >> id;

cin.ignore(); // to ignore newline character

cout << "Name: ";

getline(cin, name);

cout << "Salary: ";

cin >> salary;

employees[i].setEmployeeDetails(id, name, salary);

cout << endl;

cout << "Employee Information:" << endl;

cout << "------------------------------" << endl;

for (int i = 0; i < 3; i++) {

employees[i].displayEmployeeDetails();

return 0;

}
Output :-

You might also like