I never actually got an answer for this? Looking for some general advice on how
ID: 3571909 • Letter: I
Question
I never actually got an answer for this?
Looking for some general advice on how to use c++ arrays, if statements, strings, functions, and loops to go about creating these outputs while fulfilling the criteria for the slides. I'm wondering the most about the lists and employee input right now, so any specific advice there would be greatly appreciated.
Please make sure to read all the slides! The last time I submitted this question, the person answering did not, and I really do need to have the same outputs as set up in the slides.
https://www.dropbox.com/s/k4o7oshxv9goj1g/FA2016%20Final.pdf?dl=0
Explanation / Answer
Employee.cpp
/**
this is the Employee class witch reperest the employee oject
**/
#include <iostream>
#include <string>
using namespace std;
class Employee{
private:
string name;
int withholding;
public:
Employee(string n, int w){
name = n;
withholding = w;
}
void setName(string n){
name = = n;
}
void setWithholding(int w){
withholding = w;
}
string getName(){
return name;
}
int getWithholding(){
return withholding;
}
}
_____________________________________________________________________________
/**
As you asked only for general advice following functions will help you to dispay different menu, display and calculations.
So i m not giving complete code just function.
**/
#include <iostream>
#include <string>
using namespace std;
Employee[] employeeList;
int capacity; // max number of employee an employeelist can accomodate
int size; // number of employee in array/list
int payPeriod = 2; // 1.ANNUAL, 2.MONTHLY, 3.BIWEEKLY, 4.WEEKLY
void addEmployee(){
if(size==capacity){
cout << "Employee Array is full!"<<endl; // in case array is full no more employee can be added
}else{
strign name;
int withHolding;
cout << "EMPLOYEE NAME: "<<endl;
cin >> name;
cout << "EMPLOYEE WITHHOLDING: "<<endl;
cin >> withHolding;
Employee employee = new Employee(name, withHolding);
// look for fist empty slot insert employee there
for(int i=0;i<size;i++){
if(employeeList[i]==NULL){
employeeList[i] = employee;
size++;
return;
}
}
}
}
// delete employee and replace the entry by NULL
void deleteEmployee(string name){
for(int i=0;i<size;i++){
if(employeeList[i]!= NULL && employeeList[i]->getName().compare(name)==0){
employeeList[i] = NULL;
size--;
return;
}
}
cout << "Employee not found.";
}
void displayEmployeeList(){
for(int i=0;i<size;i++){
if(employeeList[i]!=NULL){
cout i<<". "<< employeeList[i]->getName()<<", "<<employeeList[i]->getWithholding()<<endl;
}
}
}
void editEmployee(string name){
for(int i=0;i<size;i++){
if(employeeList[i]!= NULL && employeeList[i]->getName().compare(name)==0){
cout << "CURRENT EMPLOYEE WITHHOLDING: " << employeeList[i]->getWithholding()<<endl;
cout << "NEW EMPLOYEE WITHHOLDING: ";
int withHolding;
cin >> withHolding;
editEmployee[i]->setWithholding(withHolding);
return;
}
}
cout << "Employee not found.";
}
void changePayPeriod(int newPayPeriod){
payPeriod = newPayPeriod;
}
void calculatePayCheck(string name){
for(int i=0;i<size;i++){
if(employeeList[i]!= NULL && employeeList[i]->getName().compare(name)==0){
cout << "WITHHOLDING: "<< employeeList[i]->getWithholding<<endl;
/**
display last paycheck here
**/
int newPay;
cout << "NEW PAYCHECK GROSS PAY:";
cin >> newPay;
/**
calculate and display new paycheck here according to your calculation
**/
return;
}
}
}
void mainMenu(){
cout << " Main Menu"<<endl;
cout << "1. EMPLOYEE MAINTENANCE"<<endl;
cout << "2. PAYROLL SETTINGS"<<endl;
cout << "3. CALCULATE EMPLOYEE PAYCHECK" <<end;
cout << "4. DISPLAY OVERALL PAYCHECK TOTALS"<<endl;
cout << " 0. Exit"<<endl;
cout <<" ENTER CHOICE: "<<endl;
}
void maintenanceMenu(){
cout << " EMPLOYEE MAINTENANCE"<<endl;
cout << "1. ADD EMPLOYEE"<<endl;
cout << "2. EDIT EMPLOYEE"<<endl;
cout << "3. DELETE EMPLOYEE" <<end;
cout << "4. DISPLAY EMPLOYEE LIST"<<endl;
cout << " 0. BACK TO MAIN MENU"<<endl;
cout <<" ENTER CHOICE: "<<endl;
}
void payrollMenu(){
cout << " PAYROLL SETTINGS"<<endl;
cout << "CURRENT PAY PERIOD: " << payPeriod <<endl;
cout << "1. ANNUAL"<<endl;
cout << "2. MONTHLY"<<endl;
cout << "3. BIWEEKLY" <<end;
cout << "4. WEEKLY"<<endl;
cout << " 0. BACK TO MAIN MENU"<<endl;
cout <<" NEW PAY PERIOD: "<<endl;
}