Display the values

Hi guys: Can any one please tell me how to i display the values of name and salary in two separate functions ? Thanks.


#include<iostream>
using namespace test;
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
            void displayname();  // Display name
            void displaysalary();  // Display salary
           
};

Employee::Employee()
{
    name = "Andy Griffith Show";
    salary = 20000;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;

}

int main()
{
      system("pause");
      return 0;
}
mustish1Asked:
Who is Participating?
 
UltraDogCommented:
That's because you need to actually  call these functions like so:

int main()
{
      Employee emp ("emp1", 50000); // You need to create an instance of this class in order to get access to these functions.
    emp.displayname(); // Now this will print the name
    emp.displaysalary(); // and this will print the salary.
      system("pause");
      return 0;
}
0
 
UltraDogCommented:
use the "cout" or "printf" commands
for example:

void Employee::displayname()
{
    cout<"Employee's name:"<<name<<"\r\n"
}

void Employee::displaysalary()
{
    printf("Employee's salary: %f", salary);

}
0
 
mustish1Author Commented:
Program runs but dont display any thing


#include<iostream>
using namespace test;
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
            void displayname();  // Display name
            void displaysalary();  // Display salary
           
};

Employee::Employee()
{
    name = "Andy Griffith Show";
    salary = 20000;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;

}

int main()
{
      system("pause");
      return 0;
}

void Employee::displayname()
{
    cout << "Employee's name:" << name << endl;
}

void Employee::displaysalary()
{
    cout << "Employee's salary:" << salary << endl;

}
0
 
mustish1Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.