gggg

PHOTO EMBED

Tue Apr 27 2021 06:25:59 GMT+0000 (Coordinated Universal Time)

Saved by @ahmedqgqgq #java

#include <bits/stdc++.h>
using namespace std;

/* class definition for each record */
class Employee{
    
    int id;
    string name;
    
    public:

    Employee(int Id, string Name){
        id = Id;
        name = Name;
    }

    int getid(){
        return id;
    }

    void print(){
        cout<<"Id : "<<id<<"\n";
        cout<<"Name : "<<name<<"\n";
    }

};

/* class definition which stores multiple records of 'Employee' type */
class EmployeeFile
{
    
    vector<Employee> file;

	public:

    void add(int id, string name){
        file.push_back(Employee(id,name));
    }

    Employee search(int id){
        for(auto f : file){
            if(f.getid() == id)
                return f;
        }
        return {0,""};
    }

    void print(){
        for(auto f : file){
            f.print();
        }
    }

};

int main() {
	
    EmployeeFile emp;

    /* input number of records */
    int n;
    cin>>n;

    for(int i=0;i<n;i++){
        int id;
        string name;
        cin>>id>>name;
        /* add record */
        emp.add(id,name);
    }

    cout<<"List of employees\n";
    /* print records */
    emp.print();

    int key;
    cin>>key;

    /* search record with key */
    Employee e = emp.search(key);

    cout<<"Searched employee\n";
    e.print();
    
	return 0;
}
content_copyCOPY