Answer to Question #240813 in C++ for Ali khan

Question #240813
There is a structure called employee that holds information like employee code,
name, date of joining. Write a program to create an array of the structure and enter
some data into it. Then ask the user to enter current date. Display the names of those
employees whose tenure is 3 or more than 3 years according to the given current
date.
1
Expert's answer
2021-09-22T23:48:35-0400
#include <iostream>


using namespace std;


struct employee
{
    int emp_code;
    string name;
    int date_of_joining;
};
int current_date;
int arr[5];
int main()
{
    struct employee emp[5];
    for(int i=0;i<5;i++){
        cout<<"\nEnter details for employee "<<i+1<<endl;
        cout<<"\nEnter employee code:";
        cin>>emp[i].emp_code;
        cout<<"\nEnter employee name:";
        cin>>emp[i].name;
        cout<<"\nEnter employee date of joining:";
        cin>>emp[i].date_of_joining;
        
        cout<<"\nEnter current date: ";
        cin>>current_date;
        int tenure=current_date-emp[i].date_of_joining;
        arr[i]=tenure;
    }
    cout<<"\nNames of employees whose tenure is 3 or more than 3 years according to the given current date:\n";
    for (int i=0;i<5;i++){
        if (arr[i]>=3){
            cout<<emp[i].name<<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