Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Display the values

Posted on 2011-04-30
4
Medium Priority
?
248 Views
Last Modified: 2013-12-16
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;
}
0
Comment
Question by:mustish1
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:UltraDog
ID: 35497668
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
 

Author Comment

by:mustish1
ID: 35497697
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
 
LVL 1

Accepted Solution

by:
UltraDog earned 2000 total points
ID: 35497711
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
 

Author Closing Comment

by:mustish1
ID: 35497721
Thanks.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question