search an array
May 6, 2017 at 8:22pm UTC
im having trouble setting up main to take in a cin value and sent it to a function to search an array....this is the .h file im having trouble with the raisepay() function....its supposed to search for an employee in the array using the ssn number and give it a 10% raise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#include <iostream>
#include <string>
class employee
{
public :
employee();
std::string fname;
std::string lname;
int ssn;
int pay;
private :
};
class firm
{
public :
firm();
void newemp();
void displayemp();
int raisepay(std::string ssn);
private :
int size;
int empcount;
employee total[5];
int findIndexForKey(std::string key);
};
firm::firm()
{
size = 5;
empcount = 0;
}
employee::employee()
{
fname = "N/A" ;
lname = "N/A" ;
pay = 0;
ssn = 0;
}
void firm::newemp()
{
employee info;
std::string fname;
std::string lname;
double pay;
int ssn;
std::cout << "enter new employee first name: " ;
std::cin >> fname;
std::cout << "Enter new employee last name: " ;
std::cin >> lname;
std::cout << "enter new employee SSN: " ;
std::cin >> ssn;
std::cout << "Enter new employee payrate: " ;
std::cin >> pay;
info.fname = fname;
info.lname = lname;
info.ssn = ssn;
info.pay = pay;
total[empcount] = info;
empcount++;
}
void firm::displayemp()
{
for (int i = 0; i < empcount; i++)
{
std::cout << "employee first name: " ;
std::cout << total[i].fname << std::endl;
std::cout << "employee last name: " ;
std::cout << total[i].lname << std::endl;
std::cout << "employee SSN: " ;
std::cout << total[i].ssn << std::endl;
std::cout << "employee Payrate: " ;
std::cout << total[i].pay << std::endl;
}
}
int firm::raisepay()
{
}
Last edited on May 6, 2017 at 8:50pm UTC
May 6, 2017 at 8:59pm UTC
After you set the SSN for employee you search for it with a getter function
Something like:
1 2 3 4
if (array[index].getSSN() == ssn){
// Increase pay by 10%
}
Last edited on May 6, 2017 at 9:00pm UTC
May 6, 2017 at 11:57pm UTC
I was doing something like this but couldnt figure out how to use cin in main and pass it to the function
Topic archived. No new replies allowed.