+2 votes
265 views

Write a c++ program that would print the information (name, year of joining, salary, address) of three employees by creating a class named Employee.

The output should be as follows: Name Year of joining Address

Robert 1994 64C-Walls treat

Sam 2000 68D-Wall Street

John 1999 26B- WallsStreat

by using both private and public member functions c++

by (555 points)  
reopened by | 265 views

1 Answer

+3 votes
Best answer

Here is the solution:

#include<iostream>
using namespace std;

class Employee{
    private:
        string eName, eJoinDate, eAddress;
    public:
        //Define no-arg constructor
        Employee(){

        }
        //Define argumented constructor
        Employee(string n, string jd, string a){
            eName = n;
            eJoinDate = jd;
            eAddress = a;
        }
        //define setters
        void setName(string n){
            eName = n;
        }
        void setJoinDate(string jd){
            eJoinDate = jd;
        }
        void setAddress(string a){
            eAddress = a;
        }
        //Define getter functions
        string getName(){
            return eName;
        }
        string getJoiDate(){
            return eJoinDate;
        }
        string getAddress(){
            return eAddress;
        }
        void display(){
            cout<<eName<<" \t"<<eJoinDate<<" \t"<<eAddress<<endl;
        }
};

main(){

    Employee emp[3];
    emp[0] = Employee("Robert","1994","64C-Walls street");
    emp[1] = Employee("Sam","2000","68D-Wall street");
    emp[2] = Employee("John","1999","26B-Wall Street");

    cout<<endl<<"Name \tJoining Date \tAddress"<<endl;
    cout<<"-----------------------------------"<<endl;

    for(int i=0; i<3; i++){
        emp[i].display();
    }

}

Please vote up the Answer, keep visiting our website and share the link with your friends. (Support us)

by (3.3k points)  
selected by
Thanks Dear!

Related questions

+1 vote
0 answers
asked Jun 5 by toheed (1.4k points) | 15 views
+1 vote
1 answer
asked Jun 27 by fatyma Nauman (555 points) | 44 views
+2 votes
3 answers
+3 votes
1 answer
+1 vote
2 answers
+2 votes
0 answers
asked Jun 12 by toheed (1.4k points) | 21 views
+2 votes
1 answer
asked Jun 5 by toheed (1.4k points) | 17 views
+2 votes
2 answers
asked Jun 4 by toheed (1.4k points) | 93 views




Welcome to Meansflow - Where Developers and Students Learn, Share, & Build Careers, where you can ask questions and receive answers from other members of the community.
118 questions
90 answers
43 comments
111 users