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

C++ plz! :) Construct a customer class that keeps track of a Customer purchases,

ID: 3816662 • Letter: C

Question

C++ plz! :)

Construct a customer class that keeps track of a Customer purchases, credit line, and total balance. An object in the customer class will have a name, an address, a credit limit (set to $1500) as well as other data fields. Declare and define data fields, include a constructor to populate the data fields, and implement member functions such that you can perform the following: Extract data members if needed. Keep track of number of sales, and total balance. Specify if a new purchase would exceed the credit limit. If the cost of an item to be purchased, added to the unpaid balance, surpasses the Customer's credit limit, do not allow the sale and output "Not enough credit limit. Purchase cannot be completed Otherwise show "Purchase successful." Write a program that tests the features of the customer class. Figure 1 shows a sample output. You can use the following pseudocode as a template #include header files using namespace std; class customer public: Customer (parameters) string get-name C) const double get-credit-limit const bool add-purchase (double val double get-total-balance const int get-num-purchases C) const private: data field Definition of constructor and member functions

Explanation / Answer

// Please change the name and address input to your name and address. Remove the comment above the class construction before submitting the assignment.

Program:

#include <iostream>
using namespace std;

class Customer
{
   public:
   Customer(string name, string address)
   {
       this->name = name;
       this->address = address;
       creditlimit = 1500;
       unpaidbalance = 0;
       purchases = 0;
   }
   string get_name() const
   {
       return name;
   }
   double get_credit_limit() const
   {
       return creditlimit;
   }
   bool add_purchase(double val)
   {
       if(creditlimit > (val+unpaidbalance))
       {
           unpaidbalance += val;
           cout<< "purchase was successful" << endl;
           purchases++;
           return true;
       }
       else
       {
           cout<<"Not enough credit limit. purchase can not be completed" << endl;
           return false;
       }
   }
   double get_total_balance() const
   {
       return unpaidbalance;
   }
   int get_num_purchases() const
   {
       return purchases;
   }
  
   private:
   string name;
   string address;
   double creditlimit;
   double unpaidbalance;
   int purchases;
};

int main()
{
   //fill your name and address here
   Customer cust("testing", "address");
  
   cout<< "Customer: " << cust.get_name() << endl;
   cout << "Credit Limit: " << cust.get_credit_limit() << endl;
  
   while(true)
   {
       int val;
       cout << "Enter purchase value (in $): ";
       cin >> val;
       cust.add_purchase(val);
       cout << "Do you want to purchase another item (y/n)? ";
       char c;
       cin >> c;
       if(c == 'n' || c == 'N')
           break;
   }
  
   cout << "The total of " << cust.get_num_purchases() << " purchase(s) is $" << cust.get_total_balance() << endl;
   return 0;
}

//Sample testing I did

Customer: testing                                                                                                                                                   

Credit Limit: 1500                                                                                                                                                  

Enter purchase value (in $): 1600                                                                                                                                   

Not enough credit limit. purchase can not be completedDo you want to purchase another item (y/n)? y                                                                 

Enter purchase value (in $): 200                                                                                                                                    

purchase was successfulDo you want to purchase another item (y/n)? y                                                                                                

Enter purchase value (in $): 400                                                                                                                                    

purchase was successfulDo you want to purchase another item (y/n)? y                                                                                                

Enter purchase value (in $): 100                                                                                                                                    

purchase was successfulDo you want to purchase another item (y/n)? n                                                                                                

The total of 3 purchase(s) is $700

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