Using C++, this assignment uses two classes which utilize the concept of aggregation. One class will be called TimeOff. This class makes use of another class called NumDays. Then you will create a driver (main) that will handle the personnel records for a company and generate a report.
TimeOff class will keep track of an employee’s sick leave, vacation, and unpaid time off. It will have appropriate constructors and member functions for storing and retrieving data in any of the member objects.
Data members of TimeOff:
Validation:
Required Methods:
NumDays class is to store a value that represents a number of hours which is also converted to the number days the hours is equivalent to. Every 8 hours is converted to 1 day. So 12 hours is converted to 1.5 days for example.
Data members of TimeOff:
Required Methods:
Main will create an instance of the TimeOff class to represent one employee. The program does not need to ask the user for input. The program should increase and decrease the amount of vacation time, sick time and unpaid time. Showing that all the requirements are met. In other words, create a test plan.
Then create a second instance of TimeOff and assign the first instance of TimeOff to the second. Show both reports to show they are the same.
Screenshot
------------------------------------------------
Program
#include <iostream>
#include<string>
using namespace std;
//Create a class timeoff
class NumDays {
//Instance variables
private:
double hours;
double days;
//Member functions
public:
NumDays() {
hours = 0;
days = 0;
}
//Constructor
NumDays(double hrs) {
hours = hrs;
days = hrs / 8;
}
//Getter
double gethours() {
return hours;
}
double getDays() {
return days;
}
//Operator+ overload
friend NumDays operator+(const NumDays &n1, const
NumDays &n2) {
NumDays numdays(n1.hours +
n2.hours);
numdays.days = numdays.hours /
8;
return numdays;
}
//Operator - overload
friend NumDays operator-(const NumDays &n1, const
NumDays &n2) {
NumDays numdays(n1.hours -
n2.hours);
numdays.days = numdays.hours /
8;
return numdays;
}
//Operator++ overload
void operator ++() {
hours++;
days = hours / 8;
}
//Operator --overload
void operator --() {
hours--;
days = hours / 8;
}
};
//create a class TimeOff
class TimeOff {
//Instance variables
private:
string empName;
int empId;
NumDays maxSickDays;
NumDays sickTaken;
NumDays maxVacation;
NumDays vacTaken;
NumDays maxUnpaid;
NumDays unpaidTaken;
//Member functions
public:
//defualt constructor
TimeOff(){
empName = "";
empId = 0;
maxSickDays = 0;
sickTaken = 0;
maxVacation = 0;
vacTaken = 0;
maxUnpaid = 0;
unpaidTaken = 0;
}
//Parameterized constructor
TimeOff(string name, int id, NumDays maxSick, NumDays
sick, NumDays maxVocn, NumDays vocn, NumDays maxUpaid, NumDays
uPaid) {
if ((sick.gethours() +
vocn.gethours()) <= 240) {
empName =
name;
empId =
id;
maxSickDays =
maxSick;
if
(sick.gethours() <= maxSick.gethours()) {
sickTaken = sick;
}
maxVacation =
maxVocn;
if
(vocn.gethours() <= maxVacation.gethours()) {
vacTaken = vocn;
}
maxUnpaid =
maxUpaid;
if
(uPaid.gethours() <= maxUnpaid.gethours()) {
unpaidTaken=uPaid;
}
}
}
//Accessors
string getName() {
return empName;
}
int getId() {
return empId;
}
NumDays getMaxSick() {
return maxSickDays;
}
NumDays getSick() {
return sickTaken;
}
NumDays getMaxVocation() {
return maxVacation;
}
NumDays getVocation() {
return vacTaken;
}
NumDays getMaxUnPaid() {
return maxUnpaid;
}
NumDays getUnPaid() {
return unpaidTaken;
}
//Mutators
void setName(string name) {
empName=name;
}
void setId(int id) {
empId=id;
}
void setMaxSick(NumDays s) {
maxSickDays=s;
}
void setSick(NumDays s) {
if (maxSickDays .gethours()>=
s.gethours()) {
sickTaken =
s;
}
}
void setMaxVocation(NumDays v) {
maxVacation = v;
}
void setVocation(NumDays v) {
if (maxVacation.gethours() >=
v.gethours()) {
vacTaken =
v;
}
}
void setMaxUnPaid(NumDays un) {
maxUnpaid = un;
}
void setUnpaid(NumDays un) {
if (maxUnpaid.gethours() >=
un.gethours()) {
unpaidTaken =
un;
}
}
friend ostream& operator<<(ostream&
out,TimeOff &toff) {
out << "EmployeeName: "
<< toff.empName << ", Id: " << toff.empId
<< ", SickLeave: " << toff.sickTaken.getDays() <<
", Vocation: " << toff.vacTaken.getDays() << " ,
Unpaid:" << toff.unpaidTaken.getDays();
return out;
}
};
int main()
{
//create an object of time off class
TimeOff toff("Micheal Jackson", 1123, NumDays(120),
NumDays(60), NumDays(120), NumDays(60), NumDays(120),
NumDays(40));
//Print using overload
cout << toff << endl;
//Increamet days
NumDays num(60);
for (int i = 0; i < 10; i++) {
++num;;
}
//Add into time off sick days
toff.setSick(num);
//Display
cout << toff<< endl;
//Create second object and assign first
TimeOff toff2;
toff2 = toff;
//Display
cout << toff2 << endl;
}
----------------------------------------------------
Output
EmployeeName: Micheal Jackson, Id: 1123, SickLeave: 7.5,
Vocation: 7.5 , Unpaid:5
EmployeeName: Micheal Jackson, Id: 1123, SickLeave: 8.75, Vocation:
7.5 , Unpaid:5
EmployeeName: Micheal Jackson, Id: 1123, SickLeave: 8.75, Vocation:
7.5 , Unpaid:5
Using C++, this assignment uses two classes which utilize the concept of aggregation. One class will...
Design a class called NumDays. The class’ purpose is to store a value that represents a number of work hours and convert it to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days. The class should have a constructor that accepts a number of hours, as well as member functions for storing and retrieving the hours and days....
C++ Create NumDays Class to store a value that represents number of hours worked and number of days worked. Must ensure that the two representations are always consistent. Create a TimeOff Class to track an employee’s sick leave and vacation time. It should consist of the following members: maxSickDays, sickTaken, maxVacation, and vacTaken. These members should be of type NumDays. An employee, after one year of service, receives at the beginning of the year 160 hrs(20 days) of vacation time...
Using simple, college level c++ programming Design a class called NumDays. The class’s purpose is to store a value that represents a number of work hours and convert it to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days. The class should have a constructor that accepts a number of hours, as well as member functions for storing...
With Java Language: In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) .İd: String (5 pts) hours: int (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an...
write a C++ program using classes, friend functions and overloaded operators. Computer class: Design a computer class (Computer) that describes a computer object. A computer has the following properties: Amount of Ram in GB (examples: 8, 16), defaults to 8. Hard drive size in GB (examples: 500, 1000), defaults to 500. Speed in GHz (examples: 1.6, 2.4), defaults to 1.6. Type (laptop, desktop), defaults to "desktop" Provide the following functions for the class: A default constructor (constructor with no parameters)...
IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....
About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...
This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...
Overview This assignment will give you experience on the use of classes. Understand the Application Every internet user–perhaps better thought of as an Internet connection–has certain data associated with him/her/it. We will oversimplify this by symbolizing such data with only two fields: a name ("Aristotle") and a globally accessible IP address ("139.12.85.191"). We could enhance these by adding other—sometimes optional, sometimes needed—data (such as a MAC address, port, local IP address, gateway, etc), but we keep things simple and use...