Top Post

6/recent/ticker-posts

CS304 Assignment 2 spring 2021 full source code unique.

 Source code would be updated soon

#include<iostream>
#include<string>
using namespace std;
class Person{
    private:
        string firstName;
        string lastName;
        int personalId;
        double salary;
    public:
        static int current_id;
        // set Datafields
        void setFirstName(string fName){
            firstName=fName;
        }
        void setLastName(string lName){
            lastName=lName;
        }
        void setSalary(double sl){
            salary=sl*12;
        }
        // get Datafields
        string getFirstName(){
            return firstName;
        }
        string getLastName(){
            return lastName;
        }
        double getSalary(){
            return salary;
        }
        int getPersonalId(){
            return personalId;
        }

        Person() : personalId(current_id++) {}
    
};
int Person::current_id=8248001;

class HRM{
    private:
        Person employee;
    public:
        void addPerson(string,string,double);
        void deletePerson();
        void updatePerson();
        ~HRM(){
            cout<<employee.getFirstName()<<"\t\t"<<employee.getLastName()<<"\t\t"<<employee.getPersonalId()<<"\t\t"<<employee.getSalary()<<endl;
            }
        int id(){
            return employee.getPersonalId();
        }
    
};

int main()
{
    HRM e[2];
    string fName,lName;
    double sl;
    char addopt='y';
    int i=0;
    int opt;
    
        cout<<"Press 1 for Add new Employee:"<<endl;
        cout<<"Press 2 for Delete Employee"<<endl;
        cout<<"Press 3 for Update Employee"<<endl;
        cout<<"Press 4 or any other key to Quit"<<endl;
        cin>>opt;
        if(opt==1)
        {
            while(addopt=='y' | addopt=='Y')
            {
                cout<<"Enter first name:"<<endl;
                cin>>fName;
                cout<<"Enter second name:"<<endl;
                cin>>lName;
                cout<<"Enter salary:"<<endl;
                cin>>sl;
                e[i].addPerson(fName,lName,sl);
                i++;
                cout<<"Are you want to add more record[y/Y]:"<<endl;
                cin>>addopt;
            }

        }
        else if(opt==2)
        {
            e[i].deletePerson();
        }
        else if(opt==3)
        {
            int updateid;
            cout<<"Enter id for update employee info:"<<endl;
            cin>>updateid;
            for(int l=0;l<10;l++)
            {
                if(e[l].id()==updateid)
                {
                    e[l].updatePerson();
                }
                else
                {
                    cout<<"Record not found agianst your entered id"<<endl;
                    break;
                }
            }
        }
        else
        {
            exit(1);
        }
        cout<<"########Following information would be updated#########"<<endl;
        cout<<"First Name\t Last Name\t Personal ID \t Salary per year(Rupees)"<<endl;
        cout<<"***********************************************************************"<<endl;
    return 0;
}


void HRM::addPerson(string fName,string lName,double sl)
{
    employee.setFirstName(fName);
    employee.setLastName(lName);
    employee.setSalary(sl);
}
void HRM::deletePerson(){
    int idelete;
    cout<<"Enter ID of employee to remove "<<endl;
    cin>>idelete;
    cout<<"Your Enter id is"<<idelete<<endl;
    cout<<"curent id is"<<employee.getPersonalId()<<endl;
}

void HRM::updatePerson()
{
    string rfname,rlname;
    double rsalary;
    cout<<"Enter First name"<<endl;
    cin>>rfname;
    employee.setFirstName(rfname);
    cout<<"Enter First name"<<endl;
    cin>>rlname;
    employee.setLastName(rlname);
    cout<<"Enter Salary"<<endl;
    cin>>rsalary;
    employee.setSalary(rsalary);
}












 

Post a Comment

0 Comments