Hi I was wondering if someone could tell me what I am doing wrong. I am trying to call the age function from the person class within the PEmployee class. but the name does not display and the age states 0. thank you for any insight you may give me. Have a nice day, C.D.
#ifndef Lab10
#define Lab10
#include <string>
using namespace std ;
class person
{
public:
/**
Constructs a person with no name and no age.
*/
person() ;
/**
Constructs a person with a given name and age.
@param pname is the name.
@param page is the age.
*/
person( string pname, int page ) ;
/**
Gets the name of the person and returns the name.
*/
string get_name() const ;
/**
Gets the age of the person and returns the age.
*/
int get_age() const ;
/**
Gets a name for person from the user.
*/
void read_name() ;
/**
Gets an age for person from the user.
*/
void read_age() ;
/**
Displays the name of person.
*/
void display_name() ;
/**
Displays the age of person with the name.
*/
void display_age() ;
private:
string name ;
int age ;
} ;
#endif
#ifndef PEMPLOYEE_H
#define PEMPLOYEE_H
#include <string>
#include "Lab10.h"
using namespace std ;
class PEmployee
{
public:
/**
Constructs an PEmployee with empty name and no salary.
*/
PEmployee() ;
/**
Constructs a PEmployee with a set name and salary
@param employee_name the PEmployee name.
@param initial_salary the PEmployee salary.
*/
PEmployee(string employee_name, double initial_salary) ;
/**
Sets the salary of the PEmployee.
*/
void set_salary () const ;
/**
Sets the salary of this employee.
@param new_salary the new salary value
*/
void set_salary(double new_salary) const ;
/**
Gets the name of this employee.
@return the employee name
*/
string get_name() const ;
/**
Gets the PEmployees name from the user
*/
void read_salary() ;
/**
Gets the age of person from person Class
*/
void get_data() ;
/**
Gets the PEmloyee salary.
@return the employee salary
*/
double get_salary() const ;
/**
Displays the age of PEmployee from person class.
*/
void display_age() ;
private:
person person_data ;
double salary ;
string employee_name ;
} ;
#endif
#include <iostream>
#include "Lab10.h"
#include <string>
using namespace std ;
person :: person()
{
age = 0 ;
}
person :: person(string pname, int page)
{
name = pname ;
age = page ;
}
int person :: get_age() const
{
return age ;
}
void person :: read_age()
{
cout << "Please enter the age of the person " ;
cin >> age ;
}
void person :: read_name()
{
cout << "Please enter the name of the person " ;
cin >> name ;
}
void person :: display_name()
{
cout << "The name of the person is " << name ;
}
void person :: display_age()
{
cout << "The age of " << name << "person is " << age ;
}
string person :: get_name() const
{
return name ;
}
#include <iostream>
#include <string>
#include "Lab10.h"
#include "PEmployee.h"
using namespace std ;
PEmployee :: PEmployee()
{
salary = 0 ;
}
PEmployee ::PEmployee(string employee_name, double initial_salary)
{
salary = initial_salary ;
string name = employee_name ;
}
void PEmployee :: set_salary(double new_salary) const
{
double salary = new_salary ;
}
string PEmployee :: get_name() const
{
return employee_name ;
}
void PEmployee :: read_salary()
{
cout << "Please enter the salary for the person " ;
cin >> salary ;
}
double PEmployee :: get_salary() const
{
return salary ;
}
void PEmployee :: display_age()
{
cout << "The age of " << employee_name << " is " << person_data << " and thier salary is $ " << salary << "\n" ;
}
#include <iostream>
#include <string>
#include "Lab10.h"
#include "PEmployee.h"
using namespace std ;
int main()
{
cin.clear() ; // clears the buffer.
person next ;
next.read_name() ; // Calls read_name to get name of person from user.
next.read_age() ; // Calls read_age to get age of person from user.
next.get_name() ; // Calls get_name to return the name of person.
PEmployee enter ;
enter.read_salary() ; // calls read_salary to get salary of PEmployee.
enter.get_salary() ; // returns salary of PEmployee.
enter.display_age() ; // Displays the name and age of person and salary of PEmployee
system("PAUSE") ;
return 0 ;