Пример #1
0
void problem10(){
    //number to be entered
    int hours=0;
    float days=0;
    float days2=0;
    
    cout<<"Entering problem 4 chapter 14"<<endl;
    cout<<"Enter Hours Worked in Whole Numbers"<<endl;
    cin>>hours;
    NumDays worked;
    NumDays wrkd2;
    NumDays totWork;
    
    worked.setHour(hours);
    wrkd2.setHour(hours);
    
    worked.conv();
    wrkd2.conv();
    
    totWork=worked+wrkd2;
    cout<<"Both objects added "<<totWork.getDays()<<endl;
    totWork=worked-wrkd2;
    cout<<"Both object subtracted "<<totWork.getDays()<<endl;
    
    cout<<"Days worked ++      " <<endl;
    ++worked;
    cout<<"New Days Worked:     "<<worked.getDays()<<endl;
    cout<<"Days Worked -- twice "<<endl;
    --worked;
    --worked;
    cout<<"Days:                 "<<worked.getDays()<<endl;
    
    
}
Пример #2
0
void TimeOff::setMaxVacation(NumDays& maxVacation) {
	if (maxVacation.getHours() > 270) {
		throw invalid_argument("cannot have more than max vacation");
	}
	_maxVacation = maxVacation;
}
Пример #3
0
NumDays NumDays::operator -(NumDays x) {
	NumDays a(getHours() - x.getHours());
	return a;
}
 //execution begins here
 int main() 
 {
     //create timeoff instance
     TimeOff tmOf;
     //declare variables
    string emplName;  // employs name;
    int idnNum;  //employs identification number 
    // declared instances
    NumDays maxSckDys; // instance containing total sick days allowed
    NumDays sckTaken; // num of days of sick leave taken
    NumDays maxVction; //max num of paid vacation days allowed
    NumDays vacTkn;  // num of of paid vacation days taken
    NumDays maxUpd; // max number of unpaid vacation days allowed
    NumDays unpdTken; // num of unpaid vacation days taken
    
    
    cout << "This program demonstrates Aggregation, class containing another"
            "class instant.\n";
    cout << "------------------------------------\n";
    //user input
    cout <<"Enter the following information\n";
    cout << "Employ Name: ";
    getline(cin,emplName);
    tmOf.setEmplName(emplName);
    cout << "Id Number:   ";
    cin >> idnNum;
    tmOf.setIdnNum(idnNum);
    
    //obtain hours for each instance.
    cout << "Number of sick leave days allowed: ";
    maxSckDys.usrInp();    
    cout << "Number of sick leaves taken by employee: ";
    sckTaken.usrInp();
    do{
        cout << "Number of paid vacation days allowed: ";
        cout << "\nMust be below 240: ";
        maxVction.usrInp();
    }while(maxVction.getHours() > 240);
    cout << "Number of paid vacations taken: ";
    vacTkn.usrInp();
    cout << "Number of unpaid vacations allowed: ";
    maxUpd.usrInp();
    cout << "Number of unpaid vacations taken: ";
    unpdTken.usrInp();
    cout << endl;
    
    //display information 
    cout << "________________________________\n";
    cout << "Employee information: \n";
    cout << "Name: " << emplName << endl;
    cout << "Id #: " << idnNum << endl;
    cout << "Sick leave days allowed: \n";
    maxSckDys.prnt();
    cout << "Sick leave days taken: \n";
    sckTaken.prnt();
    cout << "Paid vacations allowed: \n";
    maxVction.prnt();
    cout << "Paid vacations taken: \n";
    vacTkn.prnt();
    cout << "Unpaid vacations allowed: \n";
    maxUpd.prnt();
    cout << "Unpaid vacations taken: \n";
    unpdTken.prnt();
    
    
    cout << endl; 
    
    return 0; 
 }