I am working on a project in which i have to use Classes and do multiple things with different sorts of data. The basic question i have though is this: what am i doing wrong here in terms of this class declaration etc...i get ton of errors and cant seem to find anything to help. Please let me know how i could fix this to work it .
Your help is always appreicated!
include <iostream>
#include <fstream>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <cstring>
using namespace std;
class Employee
{
private:
char lastName[40];
char firstName[40];
char SSN[10];
double salary;
int years;
public:
Employee();
Employee(char[], char[], char[], double, int);
char* getlastName();
char* getfirstName();
char* getSSN;
double getSalary;
int getYears();
void setName(char[], char[]);
void setSSN(char[]);
void setSalary(double);
void setYearsEmployed(int);
int getLeaveTime();
void print();
};
Employee::Employee()
{
strcpy(lastName, "");
strcpy(firstName, "");
strcpy(SSN, "");
salary = 0;
years = 0;
}
Employee::Employee(char newLast[], char newFirst[], char newSSN[], double newSalary, int newYears)
{
strcpy(lastName, newLast);
strcpy(firstName, newFirst);
strcpy(SSN, newSSN);
salary = newSalary;
years = newYears;
}
char* Employee::getlastName()
{
return lastName;
}
char* Employee::getfirstName()
{
return firstName;
}
char* Employee::getSSN()
{
return SSN;
}
double Employee::getSalary()
{
return salary;
}
int Employee::getYears()
{
return years;
}
void Employee::print()
{
cout << fixed << left;
cout << "Name: "<< setw(15) << lastName; //prints lastname
cout << "First: " << setw(15) << firstName; //prints firstname
cout << "SSN: " << setw(15) << SSN << endl; // prints ssn
cout << "Salary: $" << setw(12) << setprecision(2) << salary; // prints salary
cout << "Years Employed: " << setw(15) << setprecision(2) << years << endl << endl;
}
void Employee::setName(char newFirst[], char newLast[])
{
strcpy(lastName, newLast);
strcpy(firstName, newFirst);
}
void Employee::setSSN(char newSSN[])
{
strcpy(SSN, newSSN);
}
void Employee::setSalary(double newSalary)
{
if (newSalary >= 0.0)
salary = newSalary;
else
salary = 0.0;
cout << "Error, Salary is 0\n";
}
void Employee::setYearsEmployed(int newYearsEmployed)
{
if (newYearsEmployed >= 0)
years = newYearsEmployed;
else
yearsEmployed = 0;
cout << "Error, Years Employed is 0\n";
}
int Employee::getLeaveTime()
{
leaveTime = 0;
if (years >= 0 && years <= 6)
leaveTime = years * 5;
else
leaveTime = 30;
return leaveTime;
}
#define ARSIZE 10
int buildArray(Employee[]);
void printArray(Employee[], int);
int main()
{
Employee employeeArray[ARSIZE];
int size;
size = buildArray(employeeArray);
cout << "Step 1, Prints Array.";
printArray(employeeArray, size);
cout << "Step 2, Changes first name.";
setName(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 3, Changes both names.";
setName(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 4, Changes ssn.";
setSSN(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 5, Changes salary to invalid salary.";
setSalary(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 6, Changes salary to valid salary.";
setSalary(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 7, Changes years employed to invalid value.";
setYearsEmployed(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 8, Changes years employed to valid value.";
setYearsEmployed(employeeArray,"");
printArray(employeeArray, size);
cout << "Step 9, Displays leave time for employee.";
getLeaveTime(employeeArray,"");
return 0;
}
int buildArray(Employee employee[])
{
char lastName[], firstName[], SSN[];
double salary;
int years;
int count = 0;
Employee e;
ifstream inFile;
ofstream outFile;
inFile.open("empinfo.txt"); //open employee info file
if (inFile.fail()) // if file doesn't open, an error message will pop up
{
cout << "Unable to open empinfo.txt file\n";
exit(1); //exits program
}
inFile >> lastName;
while (strcmp(lastName, "eof") != 0) //while the file opens, it adds up the count and places each exam count in the correct group
{
inFile >> firstName; //opens the employee's info from the file
inFile >> SSN;
inFile >> salary;
inFile >> years;
e = Employee(lastName, firstName, SSN, salary, years);
employee[count] = e;
count++;
inFile >> lastName;
}
inFile.close();
return count;
}
void printArray(Employee ar[], int size)
{
int i;
for(i = 0; i < size; i++)
ar[i].print();
}