Hello there. Thank you for taking the time to help me! I am working on a program that keeps information about staff members of three types (volunteer, full time, or hourly), and has header files for each of these types. There is also a staffMemberParser file which reads an string that the user inputs and tokenizes the string into fields like firstName, lastName, and memberId. Right now, I have all of the subsidiary files written, and am working on the main function, called Assignment7.cpp. For this function, we are supposed to add code to what is given, and that is what I am having a problem with. I get these errors:
54 Assignment7.cpp 'class std::vector<StaffMember*, std::allocator<StaffMember*> >' has no member named 'computePay'
79 Assignment7.cpp 'class std::vector<StaffMember*, std::allocator<StaffMember*> >' has no member named 'printInfo'
Now, I would assume that they are telling me the functions computePay and printInfo are not defined, but they ARE! I have written computePay and printInfo in all of the subsidiary files, which includes StaffMember.h, Volunteer.h, FullTimeEmployee.h, and HourlyEmployee.h, so there is certainly a definition for both of these functions. What is going on here? How can I fix this?
Thank you for any help you can provide! Here is my main function for your reference, and below that, just for kicks, is one of my other functions, just so you can see that the functions are defined:
Code:
// Assignment #: 7
// Name:
// EmailAddress:
// Description: It displays a menu of choices
// (add volunteers, full time employees, or hourly employees,
// compute their pay, search a member, list members,
// quit, display menu) to a user.
// Then it performs the chosen task. It will keep asking a user
// to enter the next choice until the choice of 'Q' (Quit) is
// entered.
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include "StaffMember.h"
#include "StaffMemberParser.h"
using namespace std;
void printMenu();
int main()
{
char input1;
string inputInfo;
bool operation;
vector<StaffMember *> memberList;
printMenu(); // print out menu
do
{
cout << "What action would you like to perform?" << endl;
cin >> input1;
switch (input1)
{
case 'A': //Add Member
cout << "Please enter a member information to add:\n";
cin >> inputInfo;
/***********************************************************************************
ADD your code here to create a pointer to an object of one of child classes of
StaffMember class and add it to the memberList
***********************************************************************************/
break;
case 'C': //Compute Pay
/***********************************************************************************
*** ADD your code here to compute the pay for all members the memberList.
***********************************************************************************/
memberList.computePay();
cout << "pay computed\n";
break;
case 'D': //Search for Member
cout << "Please enter a memberID to search:\n";
cin >> inputInfo;
operation = false;
/***********************************************************************************
*** ADD your code here to search a given memberID. If found, set "found" true,
*** and set "found" false otherwise.
***********************************************************************************/
if (operation == true)
cout << "member found\n";
else
cout << "member not found\n";
break;
case 'L': //List Members
if (sizeof(memberList) == 0)
{
cout << "no member\n" << endl;
}
else
{
for (int j=0; j < memberList.size(); j++)
{
memberList.printInfo;
}
}
break;
case 'Q': //Quit
for (int j=0; j < memberList.size(); j++)
{
delete memberList.at(j);
}
break;
case '?': //Display Menu
printMenu();
break;
default:
cout << "Unknown action\n";
break;
}
} while (input1 != 'Q' && input1 != 'q'); // stop the loop when Q is read
}
/** The method printMenu displays the menu to a user **/
void printMenu()
{
cout << "Choice\t\tAction\n";
cout << "------\t\t------\n";
cout << "A\t\tAdd Member\n";
cout << "C\t\tCompute Pay\n";
cout << "D\t\tSearch for Member\n";
cout << "L\t\tList Members\n";
cout << "Q\t\tQuit\n";
cout << "?\t\tDisplay Help\n\n";
}
Code:
// HourlyEmployee.h
// protections
#ifndef HourlyEmployee_H
#define HourlyEmployee_H
using namespace std;
class HourlyEmployee: public StaffMember
{
// private variables
private:
double rate;
int hoursWorked;
// public functions
public:
HourlyEmployee(string1, string2, string3, double1, int1)
{
StaffMember(string1, string2, string3)
rate = double1;
hoursWorked = int1;
}
virtual void computePay()
{
pay = rate*hoursWorked;
}
virtual void printInfo()
{ cout << "\nHourly Employee:" << StaffMember::printInfo() << endl; }
};
#endif