+2 votes
443 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 (575 points)  
reopened by | 443 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, 2020 by toheed (1.4k points) | 20 views
+1 vote
1 answer
asked Jun 27, 2020 by fatyma Nauman (575 points) | 90 views
+3 votes
3 answers
asked May 21, 2020 by athar (3.3k points) | 128 views
+1 vote
1 answer
+3 votes
1 answer
asked May 22, 2020 by athar (3.3k points) | 172 views
+2 votes
0 answers
+2 votes
2 answers
+2 votes
0 answers
asked Jun 12, 2020 by toheed (1.4k points) | 52 views
+2 votes
1 answer
asked Jun 5, 2020 by toheed (1.4k points) | 32 views
+2 votes
2 answers
asked Jun 4, 2020 by toheed (1.4k points) | 145 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.
131 questions
94 answers
44 comments
134 users