Answer to Question #324101 in C++ for king

Question #324101

The manager of the company has informed his assistant to enter the age of all the workers working in production department. Among all he has to find the employee with maximum age employee. Help the manager witn c++ program based on the concept of object oriented programming by creating a class employee having members empid, empname, edept,eage and display the name ,dept. and salary employee whose salary is minimum. Store the date of at least 7 employees. Make the data members of class only public. (6) Constraints Employee salary should be greater than or equal to 10000 if constraints are not matched then display "Wrong Salary Input’ 


1
Expert's answer
2022-04-05T13:18:00-0400
#include <iostream>
#include <string>
using namespace std;


class Employee {
public:
    Employee(unsigned id, string name, int slary=0, 
             string dept="production", int age=0);
    unsigned empid;
    string empname;
    int salary;
    string edept;
    int eage;
};


Employee::Employee(unsigned id, string name, int slr, string dept, int age)
{
    empid = id;
    empname = name;
    if (slr < 10000) {
        cout << "Wrong salary input" << endl;
        salary = 10000;
    }
    else { 
        salary = slr;
    }
    edept = dept;
    eage = age;
}


int main() {
    Employee workers[] = {Employee(1234, "John Smith", 50000),
                          Employee(1235, "Alice Brown", 45000),
                          Employee(1236, "Bob Johnson", 65000),
                          Employee(1237, "Charly Ginber", 55000),
                          Employee(1238, "Claris Mao", 47000),
                          Employee(1239, "Jhon Gordon", 55000),
                          Employee(1240, "Patric Corner", 35000)};
    int n = sizeof(workers) / sizeof(workers[0]);


    for (int i=0; i<n; i++) {
        cout << "Enter an age of " << workers[i].empname << ": ";
        cin >> workers[i].eage;
    }


    int idx;
    int max_age = 0;
    for (int i=0; i<n; i++) {
        if (workers[i].eage > max_age) {
            max_age = workers[i].eage;
            idx = i;
        }
    }
    cout << "The employee with maximum age is " << workers[idx].empname << endl;


    idx = 0;
    for (int i=1; i<n; i++) {
        if (workers[i].salary < workers[idx].salary) {
            idx = i;
        }
    }


    cout << endl << "The employee with minilum salary is"<< endl;
    cout << "Name: " << workers[idx].empname << endl;
    cout << "Dept: " << workers[idx].edept << endl;
    cout << "Salary: " << workers[idx].salary << endl;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS