ok, I'm really stuck with this for weeks, was trying to find an example, but no luck with what I want to do, basic tutorials also for some reason don't explain much about constructors and destructors
what I want to do is have an admin class which will hold all the employee objects, can add them, list and calculate salaries
I'm trying to make array of objects, not sure if it's right
here is the code
Code:
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee(string name, short type, int salary)
{
_name = name; _type = type; _salary = salary;
}
~Employee() {}
private:
string _name;
short _type;
int _salary;
};
class Admin {
private:
int e;
public:
Admin(){
e=0;
}
void addEmployee(string name, int payPerMonth){ // not sure if this is the right way
Employee employee = new Employee[e](name, 1, payPerMonth); // this part I don't know
e++;
}
void addEmployee(string name, short payPerHour){
//...
}
void calculateTotalPay(){
//...
}
void printEmployees(){
//...
}
};
int main(){
Admin admin();
int input, salaryM;
short salaryH;
string name;
while(true){
cout << "1 - add employee(monthly), 2 - add employee(hourly), 3 - calculate employees salaries, 4 - list all employees" << endl;
cin >> input;
if (input==1){
cout << "name: " << endl;
cin >> name;
cout << "salary: " << endl;
cin >> salaryM;
admin.addEmployee(name, salaryM);
}
}
}