Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Header #ifndef PAYROLL_H_INCLUDED #define PAYROLL_H_INCLUDED #include <iostream>

ID: 3537844 • Letter: H

Question

Header

#ifndef PAYROLL_H_INCLUDED
#define PAYROLL_H_INCLUDED
#include <iostream>
using namespace std;

class payroll
{
    private:
        int hour;
        int rate;
        int totalpay;
    public:
        payroll();
        void getRate(int r);
        void getHour(int h);
        void calcTotal();
        int getTotal();
};

#endif // PAYROLL_H_INCLUDED

Body

#include "payroll.h"
#include <iostream>
using namespace std;

payroll::payroll()
{
    hour=0;
    rate=0;
}

void payroll::getHour(int h)
{
    hour=h;
}

void payroll::getRate(int r)
{
    rate=r;
}

void payroll::calcTotal()
{
    if(hour<60)
    {
        totalpay=hour*rate;
    }
    else
    {
        return;
    }
}

int payroll::getTotal()
{
    return totalpay;
}

Main

#include "payroll.cpp"
#include <iostream>
using namespace std;

int main()
{
    payroll p[5];
    int hours, rates;
    cout<<endl;
    for(int i=0;i<3;i++)
    {
        cout<<"Enter the number of hours for employee "<<i+1<<endl;
        cin>>hours;
        cout<<"Enter rate for employee:";
        cin>>rates;
        p[i].getHour(hours);
        p[i].getRate(rates);
        p[i].calcTotal();
    }
    cout<<endl;
    for(int j=0;j<3;j++)
    {
        cout<<"The gross pay for employee "<<j+1<<" is:"<<p[j].getTotal()<<endl;
    }

    return 0;
}

This program should not accept the time over 60 hours, so I made if and else statement. However, I dont know how to quit else statement. Please Help me

Explanation / Answer

please rate - thanks

your assignment says

This program should not accept the time over 60 hours,

but you are accepting hours > 60

I've make changes to main and calcTotal


any questions ask


#ifndef PAYROLL_H_INCLUDED
#define PAYROLL_H_INCLUDED
#include <iostream>
using namespace std;

class payroll
{
    private:
        int hour;
        int rate;
        int totalpay;
    public:
        payroll();
        void getRate(int r);
        void getHour(int h);
        void calcTotal();
        int getTotal();
};

#endif // PAYROLL_H_INCLUDED

Body

#include "payroll.h"
#include <iostream>
using namespace std;

payroll::payroll()
{
    hour=0;
    rate=0;
}

void payroll::getHour(int h)
{
    hour=h;
}

void payroll::getRate(int r)
{
    rate=r;
}

void payroll::calcTotal()
{
        totalpay=hour*rate;
  
}

int payroll::getTotal()
{
    return totalpay;
}



Main

#include "payroll.cpp"
#include <iostream>
using namespace std;

int main()
{
    payroll p[5];
    int hours, rates;
    cout<<endl;
    for(int i=0;i<3;i++)
    {
       
        cout<<"Enter the number of hours for employee "<<i+1<<endl;
        cin>>hours;
        while(hours>60)
             {cout<<"must be <=60 ";
              cout<<"Enter the number of hours for employee "<<i+1<<endl;
              cin>>hours;
              }
        cout<<"Enter rate for employee:";
        cin>>rates;
        p[i].getHour(hours);
        p[i].getRate(rates);
        p[i].calcTotal();
    }
    cout<<endl;
    for(int j=0;j<3;j++)
    {
        cout<<"The gross pay for employee "<<j+1<<" is:"<<p[j].getTotal()<<endl;
    }

    return 0;
}



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote