By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

Function does not take 2 arguments. Why?

P: 1
Whenever I call insertData in the getEmployee function, it seems to think that there is not two arguments being made. One argument is a vector and the other should be a struct. I have both arguments right, to my knowledge, but it still gives me an error. Any Help?

Here is the code.........
#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;
void findByName(const vector <Employee> &V, string lName);
void getEmployee(vector <Employee> &V);
void employeesPerDept(const vector <Employee> &V, string dept);
void employeeList(const vector <Employee> &V);
void salaryByDept(const vector <Employee> &V, string dept);
bool readFile(vector <Employee> &V);
int binSearch(const vector<Employee> &V, int hi, int lo, string lName);
void ShellSort(vector<Employee> &V);
void putData(const vector<Employee> &V);
void insertData(vector <Employee>& V, Employee);
int displayMenu();
template<class CType>
void swapper(CType &a, CType &b)
{
CType temp;
temp = a;
a = b;
b = temp;
}
struct Employee {
string lastName;
string firstName;
string department;
double salary;
int employeeNum;
};
int main()
{
Employee x;
vector<Employee> data;
string lastName, dept;
int choice;
char answer;
const int findEmployee = 1,
findDepartment = 2,
addEmployee = 3,
getList = 4,
displaySalaries = 5,
endProgram = 6;
do
{
system("cls");
readFile(data);
displayMenu();
cin >> answer;
switch (choice)
{
case findEmployee: findByName(data, lastName);
break;
case findDepartment:cout << "Enter a department: "; cin >> dept;
employeesPerDept(data, dept);
break;
case addEmployee: getEmployee(data);
break;
case getList: employeeList(data);
break;
case displaySalaries: cout << "Enter a department"; cin >> dept; salaryByDept(data, dept);
break;
case endProgram:
break;
default:
cout << "You did not enter one of the choices above. Please"
" run the program again and choose one of the displayed numbers." << endl;
break;
}
cout << "Run again? (Y or N)" << endl;
cin >> answer;
answer = toupper(answer);
} while (answer == 'Y' && choice != endProgram);
cout << "Have a good day!" << endl;
putData(data);
}
void findByName(const vector <Employee> &V, string lName)
{
int high, low;
Employee data;
char answer;
do {
cout << "What is the last name of the person to which you want to find?" << endl;
cin >> lName;
int result = binSearch(V, high, low, lName);
data = V[result];
if (result != -1) {
cout << "Full Name:\t" << data.firstName << " " << data.lastName << endl;
cout << "Employee Number:\t" << data.employeeNum << endl;
cout << "Department:\t" << data.department << endl;
cout << "Salaray:\t" << data.salary << endl;
}
else {
cout << "I'm sorry, that name does not appear to be in the system" << endl;
cout << "Would you like to search again?(Y or N)" << endl;
cin >> answer;
}
answer = toupper(answer);
} while (answer == 'Y');
cout << "Have a good day!" << endl;
}
void getEmployee(vector <Employee> &V)
{
Employee data;
cout << "What is the employee's first name?" << endl;
cin >> data.firstName;
system("cls");
cout << "What is the employee's last name?" << endl;
cin >> data.lastName;
system("cls");
cout << "What is the employee's number?" << endl;
cin >> data.employeeNum;
system("cls");
cout << "What is the department of the employee?" << endl;
cin >> data.department;
system("cls");
cout << "What is the employee's salary?" << endl;
cin >> data.salary;
system("cls");
insertData(V, data); HERE IS THE ERROR
cout << "Employee has been added" << endl;
}
void employeesPerDept(const vector <Employee> &V, string dept)
{
Employee data;
for (unsigned int i = i; i < V.size(); i++){
if (V[i].department == dept) {
data = V[i];
cout << data.firstName << " " << data.lastName;
}
}
}
void employeeList(const vector <Employee> &V)
{
Employee data;
int pause = 25;
string temp;
for (unsigned int i = 0; i < V.size(); i++) {
data = V[i];
cout << data.firstName << " " << data.lastName;
if (i == pause) {
pause += 25;
system("pause");
cout << "To continue, press enter" << endl;
int enterKey = atoi(temp.c_str());
if (enterKey = '/n') {
system("cls");
}
}
}
}
void salaryByDept(const vector <Employee> &V, string dept)
{
Employee data;
double total = 0;
for (unsigned int i = i; i < V.size(); i++) {
if (V[i].department == dept) {
data = V[i];
total += data.salary;
}
}
cout << "The total of the salaries in the " << dept << " department is " << total << "$" << endl;
}
bool readFile(vector <Employee> &V)
{
Employee data;
ifstream fin;
fin.open("Payroll.txt");
while (fin >> data.firstName >> data.lastName >> data.employeeNum >> data.department >> data.salary)
{
V.push_back(data);
}
fin.close();
}
int binSearch(const vector<Employee> &V, int hi, int lo, string lName)
{
Employee data;
hi = V.size() - 1;
lo = 0;
while(lo <= hi)
{
int mid = (lo + hi) / 2;
if (V[mid].lastName == lName) {
return mid;
}
else if (V[mid].lastName > lName)
hi = mid - 1;
else
lo = mid + 1;
}
return -1;
}
void ShellSort(vector<Employee> &V)
{
bool flag = true;
int i, numLength = V.size();
int d = numLength;
while (flag || (d>1))
{
flag = false;
d = (d + 1) / 2;
for (i = 0; i < (numLength - d); i++)
{
if (V[i + d].lastName < V[i].lastName)
{
swapper(V[i], V[i + d]);
flag = true;
}
}
}
}
void putData(const vector<Employee> &V)
{
Employee data;
ofstream fout;
fout.open("Payroll_update.txt");
if (fout) {
for (unsigned int i = 0; i < V.size(); i++) {
data = V[i];
cout << data.firstName << " " << data.lastName << " " << data.employeeNum << " ";
cout << data.department << " " << data.salary << endl;
}
}
else
cout << "Error opening file" << endl;
fout.close();
}
void insertData(vector <Employee>& V, Employee toAdd)
{
ifstream fin;
fin.open("Payroll.txt");
while (fin >> toAdd.lastName >> toAdd.firstName >> toAdd.employeeNum >> toAdd.department >> toAdd.salary) {
V.push_back(toAdd);
ShellSort(V);
}
fin.close();
}
int displayMenu()
{
cout << "--------------------------------------------------" << endl;
cout << "\tChoose Desired Function :" << endl;
cout << "1. Find Employee by Name" << endl;
cout << "2. Enter Department and display its employees" << endl;
cout << "3. Add Employee" << endl;
cout << "4. Get list of Employees" << endl;
cout << "5. Display total of salaries for a department" << endl;
cout << "6. End Program" << endl;
cout << "--------------------------------------------------" << endl;
}
Dec 7 '16 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
My compiler (Visual Studio) won't compile your code because the function prototypes of your functions appear before the struct Employee definition.

Position the struct definition above any use of the struct type.

Recompoile and let me know what happened.
Dec 7 '16 #2

Post your reply

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