Created
November 16, 2012 09:19
-
-
Save ieve-rothe/4085788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include "boost/variant.hpp" | |
| using namespace std; | |
| // employee_data[0] holds employee IDs (int) | |
| // employee_data[1] holds hours worked (int) | |
| // employee_data[2] holds pay rate (double) | |
| // employee_data[3] holds wages (double) | |
| // employee_data[ii][0-6] holds individual employee data for each of the seven individuals. | |
| typedef boost::variant< int, double > employee_data_vartype; | |
| typedef vector< vector<employee_data_vartype>> employee_vector_type; | |
| employee_vector_type getHoursAndRate(employee_vector_type employee_data) { | |
| cout << "Please enter hours worked and pay rate for each employee: " << endl; | |
| // For each element in the employee_data vectors, which should all be the same length... | |
| for (int ii=0; ii < (employee_data[0].size()-1); ii++) { | |
| int hours; double rate; | |
| cout << "--------------------------------------" << endl;; | |
| cout << "Employee: " << employee_data[0][ii] << endl; | |
| cout << "Please enter hours worked (integer): "; | |
| cin >> hours; | |
| employee_data[1][ii] = hours; | |
| cout << "Please enter the pay rate (float/double): "; | |
| cin >> rate; | |
| cout << "--------------------------------------" << endl; | |
| cout << endl; | |
| employee_data[2][ii] = rate; | |
| cout << endl; | |
| } | |
| return employee_data; | |
| } | |
| // Seeds employee identification numbers into the employee_data 2d vector: | |
| // Acccepts and returns employee_data 2d vector. | |
| employee_vector_type seedEmployeeData(employee_vector_type employee_data) { | |
| employee_data[0][0] = 1234; | |
| employee_data[0][1] = 4563; | |
| employee_data[0][2] = 8765; | |
| employee_data[0][3] = 4568; | |
| employee_data[0][4] = 9867; | |
| employee_data[0][5] = 9235; | |
| employee_data[0][6] = 7684; | |
| return employee_data; | |
| } | |
| // Calculate employee wages from hours worked [1][ii] and hourly wage [2][ii] | |
| // Takes and returns employee_data 2d vector. | |
| employee_vector_type calculateWages(employee_vector_type employee_data) { | |
| for (int ii=0; ii < (employee_data[0].size() - 1); ii++) { | |
| int hours; double wages, rate; | |
| hours = (int)employee_data[1][ii]; | |
| rate = (double)employee_data[2][ii]; | |
| wages = hours * rate; | |
| employee_data[3][ii] = wages; | |
| } | |
| return employee_data; | |
| } | |
| void printEmployeeData(employee_vector_type employee_data) { | |
| return; | |
| } | |
| int main() { | |
| employee_vector_type employee_data(4, vector<employee_data_vartype> (7, 0)); | |
| cout << "Payroll Tracking System" << endl; | |
| cout << "Cameron Carroll. CSIS 138 Project 3A" << endl; | |
| cout << "--------------------------------------" << endl << endl << endl; | |
| // Load employee IDs: | |
| employee_data = seedEmployeeData(employee_data); | |
| // Get hours worked and pay rate from user, for each employee: | |
| // employee_hours = getHours(); | |
| // employee_payrates = getPayRates(); | |
| employee_data = getHoursAndRate(employee_data); | |
| // Calculate gross wages for each employee: | |
| employee_data = calculateWages(employee_data); | |
| // Print out data for all employees: | |
| printEmployeeData(employee_data); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [cameron@ghast-l 3]$ g++ Project_3A_CCarroll.cpp -std=c++11 --debug | |
| Project_3A_CCarroll.cpp: In function ‘employee_vector_type calculateWages(employee_vector_type)’: | |
| Project_3A_CCarroll.cpp:80:37: error: invalid cast from type ‘__gnu_cxx::__alloc_traits<std::allocator<boost::variant<int, double> > >::value_type {aka boost::variant<int, double>}’ to type ‘int’ | |
| Project_3A_CCarroll.cpp:81:31: error: cannot convert ‘__gnu_cxx::__alloc_traits<std::allocator<boost::variant<int, double> > >::value_type {aka boost::variant<int, double>}’ to ‘double’ in assignment | |
| [cameron@ghast-l 3]$ g++ Project_3A_CCarroll.cpp -std=c++11 --debug | |
| Project_3A_CCarroll.cpp: In function ‘employee_vector_type calculateWages(employee_vector_type)’: | |
| Project_3A_CCarroll.cpp:80:37: error: invalid cast from type ‘__gnu_cxx::__alloc_traits<std::allocator<boost::variant<int, double> > >::value_type {aka boost::variant<int, double>}’ to type ‘int’ | |
| Project_3A_CCarroll.cpp:81:39: error: invalid cast from type ‘__gnu_cxx::__alloc_traits<std::allocator<boost::variant<int, double> > >::value_type {aka boost::variant<int, double>}’ to type ‘double’ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment