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

C++ Write a member function ChargeTheCard of struct CreditCard which is used to

ID: 3865984 • Letter: C

Question

C++

Write a member function ChargeTheCard of struct CreditCard which is used to simulate customer using the credit card to shop or make purchases. As you know that available credit on your credit card is defined by the following expression:


availableCredit = CreditLimit – balance


The credit card charging software makes sure that your purchase does not exceed available credit. If it does then the purchase must be denied. If the amount of purchase is less than or equal to available credit, then purchase is allowed and balance is increased by the amount of purchase. Write the ChargeTheCard function such that above standard is enforced.

void ChargeTheCard(double purchaseAmount)
{

)

Explanation / Answer

Hi,

Please find below the code-

void ChargeTheCard(double purchaseAmount)
{
if(availableCredit < purchaseAmount)
{
cout<<"Your Purchase Amount exceeds your total available credit. Please provide lower Amount";
}
else if(availableCredit >= purchaseAmount)
{
availableCredit=availableCredit-purchaseAmount
}

}

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