473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Function within a Base Class

tsubasa
64
Greetings, and thanks in advance.

I am working on a program for school and I have managed to get everything to work, except the last portion of the program. It seems that the program is not calling the last function EmployeeSummary. The program will compile, and will accept data and compute overtime pay, etc. Just won't go on to the last function. Can someone help me out?

-Tsu

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. class CPayroll {
  9.  
  10. public:
  11.     void Compute(string m_name, int m_hours, double m_wage);
  12.     void EmployeeOutput(void);
  13.     void EmployeeSummary(CPayroll Timecard1, CPayroll Timecard2, CPayroll Timecard3);
  14.     string m_name;
  15.     int m_hours;
  16.     int m_OThours;
  17.     float m_wage;
  18.     float m_pay;
  19.     float m_OTpay;
  20.     float m_Totalpay;
  21.     float Total_Salary;
  22.     int Total_Hours;
  23.     float Total_OTHours;
  24. } ;
  25.  
  26. int main()
  27.  
  28. {
  29.     cout << "\nWelcome to the Employee Pay Center\n\n" ;
  30.  
  31.    CPayroll Timecard1;
  32.    CPayroll Timecard2;
  33.    CPayroll Timecard3;
  34.  
  35.     cout << "Enter the employee's name = ";
  36.     cin >> Timecard1.m_name;
  37.     cout << "\nEnter the hours worked = ";
  38.     cin >> Timecard1.m_hours;
  39.     cout << "\nEnter his or her hourly wage = ";
  40.     cin >> Timecard1.m_wage;
  41.     cout << endl;
  42.  
  43.    cout << "Enter the employee's name = ";
  44.     cin >> Timecard2.m_name;
  45.     cout << "\nEnter the hours worked = ";
  46.     cin >> Timecard2.m_hours;
  47.     cout << "\nEnter his or her hourly wage = ";
  48.     cin >> Timecard2.m_wage;
  49.     cout << endl;
  50.  
  51.     cout << "Enter the employee's name = ";
  52.     cin >> Timecard3.m_name;
  53.     cout << "\nEnter the hours worked = ";
  54.     cin >> Timecard3.m_hours;
  55.     cout << "\nEnter his or her hourly wage = ";
  56.     cin >> Timecard3.m_wage;
  57.     cout << endl;
  58.  
  59.     Timecard1.Compute(Timecard1.m_name, Timecard1.m_hours, Timecard1.m_wage);
  60.     Timecard2.Compute(Timecard2.m_name, Timecard2.m_hours, Timecard2.m_wage);
  61.     Timecard3.Compute(Timecard3.m_name, Timecard3.m_hours, Timecard3.m_wage);
  62. }
  63.  
  64. void CPayroll::Compute(string m_name, int m_hours, double m_wage)
  65. {
  66.     if (m_hours > 40)
  67.     m_OThours = m_hours - 40;
  68.     else
  69.     m_OThours = 0;
  70.     m_hours = m_hours - m_OThours;
  71.     m_pay= m_hours * m_wage;
  72.     m_OTpay = m_OThours * m_wage * 1.5;
  73.     m_Totalpay = m_OTpay+m_pay;
  74.     EmployeeOutput();
  75. }
  76.  
  77.  void CPayroll::EmployeeOutput()
  78.  {
  79.  
  80.      cout << "Employee Name ........................... = " << m_name <<endl;
  81.      cout.setf(ios::fixed);
  82.      cout << "Base Pay............. ................... = " << setprecision(2) << m_pay << endl;
  83.      cout << "Hours in Overtime........................ = " << m_OThours << endl;
  84.      cout << "Overtime Pay Amount...................... = " << setprecision(2) << m_OTpay << endl;
  85.      cout << "Total Pay ............................... = " << setprecision(2) << m_Totalpay << endl;
  86.      cout << endl;
  87.  
  88. }
  89.  
  90. void CPayroll::EmployeeSummary(CPayroll Timecard1, CPayroll Timecard2, CPayroll Timecard3)
  91. {
  92.     float Total_Salary = 0;
  93.     int Total_Hours = 0;
  94.     float Total_OTHours = 0;
  95.  
  96.     Total_Salary = Timecard1.m_Totalpay+Timecard2.m_Totalpay+Timecard3.m_Totalpay;
  97.     Total_Hours = Timecard1.m_hours+Timecard2.m_hours+Timecard3.m_hours;
  98.     Total_OTHours = Timecard1.m_OThours+Timecard2.m_OThours+Timecard3.m_OThours;
  99.  
  100. cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
  101. cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%" << endl;
  102. cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " << endl;
  103. cout << "%%%% Total Employee Salaries ..... =" <<  Total_Salary << endl;
  104. cout << "%%%% Total Employee Hours ........ =" <<  Total_Hours << endl;
  105. cout << "%%%% Total Overtime Hours......... = " <<  Total_OTHours << endl;
  106. cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
  107. cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
  108. cout << "%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%" << endl;
  109. }
  110.  
  111.  
Mar 1 '12 #1
3 1517
weaknessforcats
9,208 Expert Mod 8TB
How are you trying to call CPayroll::EmployeeSummary?

I don't see an obvious call in your code.
Mar 1 '12 #2
tsubasa
64
Thank you for responding!

What I tried to do is place the call EmployeeSummary(); on line 87, but when I try to do this I get a number of errors because it wants me to place the class inside. If I do that, then I get an error "Expect Primary expression before ',' token. Which I have no clue to what this is. I have tried some solutions on the Internet, but none of them work.
Mar 1 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
I don't see a call on line 87. Also, what's this about placing yuor class inside? Inside what?

The call inside CPayroll::EmployeeOutput()would look like:

void CPayroll::EmployeeOutput()
{
this->EmployeeSummary(arguments...);
}
Mar 1 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Phui Hock | last post by:
"When you make a virtual function call through a base-class pointer (that is, when you make a polymorphic call), the compiler quietly inserts code to fetch the VPTR and look up the function address...
8
by: Andreas Lagemann | last post by:
Hi, after browsing FAQ and archive for a while I decided that the following is a legal question. Consider this: Class Base { public: Base() {}
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
2
by: Bloke Smith | last post by:
I have written a class (and it works!). Now I want to tidy the code a bit by separating some subroutines and I get a "Fatal error: Call to undefined function:" e.g. class Fred{ function...
4
by: voidtwerp | last post by:
The following code cant call derived::fn() , it is calling base::fn() which is pure virtual. (the same problem is ocurring if I do it outside of constructors also) What am I doing wrong here? ...
6
by: noel.hunt | last post by:
I have a base class, PadRcv, with virtual functions. User code will derive from this class and possibly supply it's own functions to override the base class virtual functions. How can I test that...
4
by: Javier | last post by:
Hello, is this possible? I have a pure virtual function in the base class (to force the programmers of the derived classes to have this function implemented) but I want to call the derived class...
1
by: jman | last post by:
i've got an object and i'd like to recursively call a function within the class definition. (i've simplified the code ) function myclass() { this.loop = function(index) { // ..work
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.