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

During the tax season, every Friday, the J&J accounting firm provides assistance

ID: 3822969 • Letter: D

Question

During the tax season, every Friday, the J&J accounting firm provides assistance to people who prepare their own tax returns. Their charges are as follows:

If a person has low income (<= 25,000) and the consulting time is less than or equal to 30 minutes, there are no charges; otherwise, the service charges are 40% of the regular hourly rate for the time over 30 minutes.

For others, if the consulting time is less than or equal to 20 minutes, there are no service charges; otherwise, service charges are 70% of the regular hourly rate for the time over 20 minutes.

(For example, suppose that a person has low income and spent 1 hour and 15 minutes, and the hourly rate is $70.00. Then the billing amount is 70.00 * 0.40 * (45 / 60) = $21.00.)

Write a program in C++ that prompts the user to enter the hourly rate, the total consulting time, and whether the person has low income. The program should output the billing amount. Your program must contain a function that takes as input the hourly rate, the total consulting time, and a value indicating whether the person has low income. The function should return the billing amount. Your program may prompt the user to enter the consulting time in minutes. Below is the code i have at the moment. I keep getting a "timed out" message on the testcase i am trying to pass it through. The subject is over User Defined Functions..

#include <iostream>
#include <iomanip>
float gfHourRate = 0;
typedef struct {
int iNoChargeMin;
float fDiscount;
} SDiscount;

class CTaxReturn {
private:
bool bLowIncome;
int iConsultDurationMin;
float price;
SDiscount *psd;
public:
static const SDiscount sd[2];
CTaxReturn()
{
price = 0.0f;
bLowIncome = false;
iConsultDurationMin = 0;
psd = (SDiscount *)&sd[0];
}

CTaxReturn(bool isLowincome, int iDuration)
{
set_numbers(isLowincome, iDuration);
}
const float& set_numbers(bool isLowincome, int iDuration)
{
bLowIncome = isLowincome;
psd = (SDiscount *)&sd[bLowIncome ? 0 : 1];
iConsultDurationMin = iDuration;
price = ((iConsultDurationMin - psd->iNoChargeMin)/60.0) * gfHourRate * psd->fDiscount;
return price;
}
};
const SDiscount CTaxReturn::sd[2] = {{30,0.4}, {20, 0.7}};
using namespace std;

bool get_yesno(const string& strPrompt)
{
char yes = 0;
do {
cout << strPrompt + "(y/n) > ";
yes = 0;
cin >> yes;
while(cin.get()!=' ');
yes = tolower(yes);
} while(yes != 'y' && yes != 'n');
return yes == 'y' ? true : false;
}

template <class T>
const T& get_number(const string& strPrompt, T& tNumber)
{
tNumber = 0;
do {
cout << strPrompt + " > ";
cin >> tNumber;
while(cin.get() != ' ');
if (cin.good())
break;
} while (true);
return tNumber;
}

int main()
{
gfHourRate = get_number("What is the hourly rate?", gfHourRate);
CTaxReturn tr;
float fee = 0.0f;
do{
int iMin = 0;
iMin = get_number("Please enter consulting time (in minutes)", iMin);
bool bLow = get_yesno("Do you earn less or equal $25,000.00?");
fee = tr.set_numbers(bLow, iMin);
cout << "You have to pay $" << fixed << setprecision(2) << fee << endl;
}while(get_yesno("Do You want to continue?"));
return 0;
}

Explanation / Answer

Your code seems fine to me. Although you have quite complicated your problem or you have not shared full description of the assignment which prompt you to create class as wll as structure.

Anyhow, you test cases might be failing as they might not be passing any y/n answers to continue.

Share test case and I will debug and fix it without test cases nothing really cn't be done, apart from hit and trial on removing y/n prompt for continuing, or instead of asking for low salary in y/n terms ask for salary and figure it out.

#include <iostream>
#include <iomanip>

using namespace std;

float gfHourRate = 0;

typedef struct {
int iNoChargeMin;
float fDiscount;
} SDiscount;

class CTaxReturn {
private:
bool bLowIncome;
int iConsultDurationMin;
float price;
SDiscount *psd;
public:
static const SDiscount sd[2];
CTaxReturn()
{
price = 0.0f;
bLowIncome = false;
iConsultDurationMin = 0;
psd = (SDiscount *)&sd[0];
}

CTaxReturn(bool isLowincome, int iDuration)
{
set_numbers(isLowincome, iDuration);
}
const float& set_numbers(bool isLowincome, int iDuration)
{
bLowIncome = isLowincome;
psd = (SDiscount *)&sd[bLowIncome ? 0 : 1];
iConsultDurationMin = iDuration;
price = ((iConsultDurationMin - psd->iNoChargeMin)/60.0) * gfHourRate * psd->fDiscount;
return price;
}

};

const SDiscount CTaxReturn::sd[2] = {{30,0.4}, {20, 0.7}};

bool get_yesno(const string& strPrompt)
{
char yes = 0;
do {
cout << strPrompt + "(y/n) > ";
yes = 0;
cin >> yes;
while(cin.get()!=' ');
yes = tolower(yes);
} while(yes != 'y' && yes != 'n');
return yes == 'y' ? true : false;
}

template <class T>
const T& get_number(const string& strPrompt, T& tNumber)
{
tNumber = 0;
do {
cout << strPrompt + " > ";
cin >> tNumber;
while(cin.get() != ' ');
if (cin.good())
break;
} while (true);
return tNumber;
}

int main()
{
gfHourRate = get_number("What is the hourly rate?", gfHourRate);
CTaxReturn tr;
float fee = 0.0f;
do{
int iMin = 0;
iMin = get_number("Please enter consulting time (in minutes)", iMin);
bool bLow = get_yesno("Do you earn less or equal $25,000.00?");
fee = tr.set_numbers(bLow, iMin);
cout << "You have to pay $" << fixed << setprecision(2) << fee << endl;
}while(get_yesno("Do You want to continue?"));
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