Pages

Write a program to create a class name employee and create three attributes and create a setter and a getter function for each attribute and call a default constructor in C++

Monday, 13 May 2013

#include <iostream>
#include <string>
using namespace::std;
class employee
{
      string first_name;
      string last_name;
      int salary;
      public:
             employee()
             {
                       first_name='NULL';
                       last_name='NULL';
                       salary=0;
             }
             void setFirstName()
             {
                  cout<<"Enter Your First Name: ";
                  cin>>first_name;
             }
             void setlastName()
             {
                  cout<<"Enter Your Last Name: ";
                  cin>>last_name;
             }
             void setSalary()
             {
                  cout<<"Enter Your Salary: ";
                  cin>>salary;
                  if(salary<0)
                  {
                              salary=0;
                  }
             }
             void dsplayFirstName()
             {
                  cout<<"Your First Name is: "<<first_name<<endl;
             }
             void displayLastName()
             {
                  cout<<"Your Last Name is: "<<last_name<<endl;
             }
             void displaySalary()
             {
                  cout<<"Your Salary is: "<<salary<<endl;
             }
};
int main()
{
    employee a1;
    a1.setFirstName();
    a1.setlastName();
    a1.setSalary();
    a1.dsplayFirstName();
    a1.displayLastName();
    a1.displaySalary();
    system("pause");
}
 

Search Box

Most Reading

Contact Form

Name

Email *

Message *