Answer:
Step-by-step explanation:
The code is implemented in C++ and comments to aid understanding are provided below.
Will be attaching code for these 3 files:
CustomerDemo.cpp
Customer.cpp
Customer.h
Source code for CustomerDemo.cpp:
#include <iostream>
#include "Customer.h"
using namespace std;
int main()
{
string response = "y";
double val;
Customer a("John Doe", "101 Main St.", "Rockford", "IL", "61801", 100.00);
Customer b("J", "101 Main St.", "Rockford", "IL", "61801", 100.00);
Customer c("Doe", "101 Main St.", "Rockford", "IL", "61801", 100.00);
Customer z("D", "101 Main St.", "Rockford", "IL", "61801", 100.00);
while ( response == "y" )
{
cout << "Purchase value (in $): ";
cin >> val;
if(!c.add_purchase(val)) break;;
cout << "Do you want to purchase another item (y/n)? ";
cin >> response;
}
cout << "Please pay the balance of $" << c.get_unpaid_balance() << endl;
/* cout << "would you like to pay off part of the unpaid balance?" <<endl;
if (response== "y")
{
cout< "Enter the payment amoun (in $)";
(c.get_
cout << "Do you want to purchase another item (y/n)? ";
cin >> response;
}*/
system("pause");
return 0;
}
→ Source code for Customer.cpp:
#include "Customer.h"
Customer::Customer()
{
name = "";
address = "";
city = "";
state = "";
zipcode = "";
credit_limit = 0;
year_to_date_purchases = 0;
unpaid_balance = 0;
}
Customer::Customer(string n, string a, string c, string s, string z, double cl)
{
name = n;
address = a;
city = c;
state = s;
zipcode = z;
credit_limit = cl;
year_to_date_purchases = 0;
unpaid_balance = 0;
}
void Customer::increase_limit(double amount)
{
credit_limit += amount;
}
string Customer::get_name() const
{
return name;
}
string Customer::get_address() const
{
return address;
}
string Customer::get_city() const
{
return city;
}
string Customer::get_state() const
{
return state;
}
string Customer::get_zipcode() const
{
return zipcode;
}
double Customer::get_credit_limit() const
{
return credit_limit;
}
double Customer::get_unpaid_balance() const
{
return unpaid_balance;
}
bool Customer::add_purchase(double val)
{
if ( (val + unpaid_balance) > credit_limit )
{
cout << "Not enough credit limit. Purchase cannot be completed.\\";
return false;
}
year_to_date_purchases += val;
unpaid_balance += val;
cout << "Purchase successful.\\"; //trace message
return true;
}
void Customer::pay_balance(double payment)
{
unpaid_balance -= payment;
}
→ Source code for Customer.h:
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class Customer
{
public:
//constructors
Customer();
Customer(string name, string address, string city,
string state, string zipcode, double);
//accessors
string get_name() const;
string get_address() const;
string get_city() const;
string get_state() const;
string get_zipcode() const;
double get_credit_limit() const;
double get_unpaid_balance() const;
//mutators
void increase_limit(double amount);
bool add_purchase(double val);
void pay_balance(double payment);
private:
string name;
string address;
string city;
string state;
string zipcode;
double credit_limit;
double year_to_date_purchases;
double unpaid_balance;
};
#endif
cheers i hope this helped !!