I need to use the following UML Class diagram to build a C++ program but i need
ID: 3667521 • Letter: I
Question
I need to use the following UML Class diagram to build a C++ program but i need an example as my professor uses nothing but power points presentations.
Employee
-firstName : string
-lastName : string
-empID : int
-gender : char
-dependents : int
-annualSalary : double
-static numEmployees : int = 0
+Employee()
+Employee(in first : string, in last : string, in ID : int, in gen : char, in dep : int, in sal : double)
+calcPay() : double
+displayEmployee() : void
+static getNumEmployees() : int
+getFirstName() : string
+setFirstName(in first : string) : void
+getLastName() : string
+setLastName(in last : string) : void
+getEmpID() : int
+setEmpID(in ID : int) : void
+setEmpID(in ID : string) : void
+getGender() : char
+setGender(in gen : char) : void
+setGender(in gen : string) : void
+getDependents() : int
+setDependents(in dep : int) : void
+setDependents(in dep : string) : void
+getAnnualSalary() : double
+setAnnualSalary(in sal : double) : void
+setAnnualSalary(in sal : string) : void
I need to use the following UML Class diagram to build a C++ program but i need an example as my professor uses nothing but power points presentations.
Employee
-firstName : string
-lastName : string
-empID : int
-gender : char
-dependents : int
-annualSalary : double
-static numEmployees : int = 0
+Employee()
+Employee(in first : string, in last : string, in ID : int, in gen : char, in dep : int, in sal : double)
+calcPay() : double
+displayEmployee() : void
+static getNumEmployees() : int
+getFirstName() : string
+setFirstName(in first : string) : void
+getLastName() : string
+setLastName(in last : string) : void
+getEmpID() : int
+setEmpID(in ID : int) : void
+setEmpID(in ID : string) : void
+getGender() : char
+setGender(in gen : char) : void
+setGender(in gen : string) : void
+getDependents() : int
+setDependents(in dep : int) : void
+setDependents(in dep : string) : void
+getAnnualSalary() : double
+setAnnualSalary(in sal : double) : void
+setAnnualSalary(in sal : string) : void
Explanation / Answer
Note:
stoi and stod are a C++11 function. If you aren't using a compiler that understands C++11, this simply won't compile.
#include<iostream>
#include<string>
using namespace std;
class Employee
{
private:
string firstName;
string lastName;
int empID ;
char gender ;
int dependents ;
double annualSalary ;
static int numEmployees;
public:
Employee(){
}
Employee(string first ,string last, int ID ,char gen ,int dep ,double sal){
firstName=first;
lastName=last;
empID =ID;
gender =gen;
dependents = dep;
annualSalary = sal;
}
double calcPay(){
return annualSalary/12.0;
}
void displayEmployee(){
cout<<"First Name: "<<firstName<<", Last Name: "<<lastName<<", EmpId: "<<empID;
cout<<", Gender: "<<gender<<", Number of dependents: "<<dependents<<", AnnualSalary: "<<annualSalary<<endl;
}
static int getNumEmployees(){
return numEmployees;
}
string getFirstName(){
return firstName;
}
void setFirstName(string first){
firstName = first;
}
string getLastName(){
return lastName;
}
void setLastName(string last){
lastName = last;
}
int getEmpID(){
return empID;
}
void setEmpID(int ID){
empID = ID;
}
void setEmpID(string ID){
empID = stoi(ID);
}
char getGender(){
return gender;
}
void setGender(char gen){
gender = gen;
}
void setGender(string gen){
gender = gen.at(0);
}
int getDependents(){
return dependents;
}
void setDependents(int dep){
dependents = dep;
}
void setDependents(string dep){
dependents = stoi(dep);
}
double getAnnualSalary(){
return annualSalary;
}
void setAnnualSalary(double sal){
annualSalary = sal;
}
void setAnnualSalary(string sal){
annualSalary = stod(sal);
}
};
int Employee::numEmployees = 0;
int main(){
return 0;
}