Use object-oriented programming to write an application for a company that uses a subscription-based business model to loan out clothes such as office and party wear to female clients.
A subscription costs $69 per 4 weeks. A client can make unlimited loan requests during her subscription, as long as she has no previous loan that has not been returned. There can be only one piece of clothes in each loan request.
The chosen piece of clothes takes a day to be delivered. For example, if a piece of clothes is selected on Wednesday (say, 4th September 2019), then it will arrive at the address of the client the following day, that is, Thursday, 5th 2019
The subscription is automatically renewed. To cancel the subscription, a client must o not have any loan that is unreturned, o pay up any outstanding balance, and o call to cancel before week 4 of each 4-week cycle.
Write the following classes:
(a) Client
The object attributes are client id, name and address. The constructor has three
parameters to initialise the three object attributes.
There are accessor methods for all object attributes, and a mutator
method for the address.
A addPayment method has a parameter amount which is added to the client’s balance if the amount is positive, and the method returns True. Otherwise, the method returns False.
A makePayment method that has a parameter amount which is subtracted from balance if the amount is positive, and the method returns True. Otherwise, the method returns False. Note that the balance may become negative, and it means that the client has paid in excess.
A str method that returns the object attributes as a string in the format shown here:
Test the class by creating the client in the example, and then invoke the methods you have written on the client object.
(b) Clothes
The object attributes are clothes id, brand, size, price and loan status. The loan
status records True if the piece of clothes is currently loaned
out, and False otherwise.
The constructor has four parameters to initialise the first four
attributes. Set loan status to False.
There are accessor methods for each object attribute, and a mutator method for
loan status.
The str method returns all the values of the attributes as a string, with yes or
no based on the loan status. Two examples are shown below:
Test the class by creating the two Clothes objects in the example,
and then invoke
the methods you have written on the Clothes objects
(c) Subscription
• The object attributes are the subscription id, start date of subscription, client
who made the subscription, the piece of clothes loaned under the subscription, if any, the date on which the piece of clothes is delivered to the client if there
is a loan, and the date on which the piece of clothes is
returned, if the loan has been returned.
The constructor has two parameters to initialise the client and the
start date of subscription. The subscription id is generated using
a running number, implemented with a class attribute, _nextId. The
subscription id of the first subscription is 1. The subscription id
of the second subscription is 2, and so on. The piece of clothes,
delivered date and return date are initialised to None. There are
accessor methods for each object attribute, and mutator methods for
the piece of clothes, delivery date and return date.
Another class attribute records the subscription rate which is
$69.
A class method getSubscriptionRate returns the subscription
rate.
A returnClothes method has one parameter, return date, and method returns False if o there is no outstanding piece of clothes for the subscription or o the return date is before the date that the piece of clothes is delivered. Otherwise, the method handles the return of the piece of loaned clothes by setting the loan status of the piece of clothes to False, the object attribute clothes to None, and updates the return date in the subscription. The method then returns True.
A requestClothes method has two parameters, the request date and the piece of clothes. The method returns False if o a loan by the client has not been returned, or o the requested piece of clothes is currently already loaned out, or o the request date is before the start date of the subscription, or o the request date is before the returned date of the last loan.
Otherwise, the method handles the request to loan a piece of clothes by setting the delivered date for the piece of clothes to be one day after the request date, the loan status of the requested piece of clothes to True, the object attribute clothes to the requested piece of clothes, and returns True.
The str method returns the object attributes as a string. Three examples are shown below:
Example 1: With no previous loan and no existing loan
Example 2: With a previous piece of clothes that is loaned, returned and no existing loan
Example 3: With a loan of a piece of clothes
Test the class by creating the Subscription object in the example, and then invoke the methods you have written on the Subscription object
(d) Company
The object attributes are a collection of clothes (list), a collection of clients
(dict) and a collection of subscriptions (list).The constructor initialises the
three attributes as empty collections.
There are three search methods, one for each of the object attributes.
o A searchClient method returns a client in the collection that has the same client id as the parameter
o A searchClothes method returns a piece of clothes in the collection that has the same clothes id as the parameter.
o A searchSubscription method returns a subscription in the collection that is made by the client with the same client id as the parameter. Note that each client can make only one subscription.
The method returns None if the search is unsuccessful.
• There are three add methods, one for each of the object
attributes o An
addClient method that creates and adds a client to the collection only if the collection does not contain a client with the same client id.
o An addClothes method that adds a piece of clothes to the collection only if the collection does not contain a piece of clothes with the same clothes id.
o The addSubscription method checks that the client making the subscription is an existing client, and that the client does not have a subscription yet. If so, the method creates a subscription and adds it to the collection only if the collection does not contain a subscription with the same subscription id. The subscription amount is added to the payment of the client making the subscription. o The method returns True if the add operation is successful, and False otherwise.
A cancelSubscription method that has two parameters, a client id and the cancel date. The method returns False if o there is no client with the given client id or o if the client has an outstanding balance, or o the client does not have a subscription, or o the cancel date is earlier than the start date of the subscription o the cancel date is not before week 4 of the 4-week subscription cycle, Otherwise, the method removes the subscription and returns True.
A returnClothes method that has two parameters, a client id and the return date. The method returns False if there is no client with the matching client id or if the client does not have a subscription. Otherwise, the method calls thereturnClothes method on the subscription, and returns the result of the call.
A requestClothes method that has three parameters, a client id, the request date and the requested piece of clothes. The method returns False if o the requested piece of clothes is already on loan or o there is no client with the matching client id or o the client does not have a subscription.
Otherwise, the method calls the requestClothes method on the subscription, and returns the result of the call.
• There are four str methods for object attributes.
o A clientStr method returns a string with each client detail
on
separate lines. o A clothesStr method returns a string with each
clothes detail on separate lines.
o A availableClothesStr method returns a string with each
clothes
detail on separate lines, for clothes currently not on
loan.
o A subscriptionStr method returns a string with each
subscription
detail on separate lines.
• The str method returns the object attributes as a string in the
format shown
below:
Test the class by creating the Company object in the example, and then invoke the methods you have written on the Company object.
#include <bits/stdc++.h>
using namespace std;
class Client
{
private :
int id;
string name;
string address;
int balance;
public :
Client(int a = 0, string b = "John", string c = "USA")
{
id = a;
name = b;
address = c;
balance = 0;
}
int getID()
{
return id;
}
string getName()
{
return name;
}
string getAddress()
{
return address;
}
void setAddress(string s)
{
address = s;
}
bool addPayment(int amount)
{
if(amount < 0)
return false;
balance += amount;
return true;
}
bool makePayment(int amount)
{
if(amount < 0)
return false;
balance -= amount;
return true;
}
string strClient()
{
string x = ("Client Id : " + to_string(getID()) + " with Name " +
getName() + " living at " + getAddress() + " has balance " +
to_string(balance));
return x;
}
};
class Clothes
{
private :
int id;
string brand;
char size;
int price;
bool loan_status;
public :
Clothes(int a = 0, string b = "Levi", char c = "M", int d =
100)
{
id = a;
brand = b;
size = c;
price = d;
loan_status = false;
}
int getID()
{
return id;
}
string getBrand()
{
return brand;
}
int getsize()
{
return size;
}
int getPrice()
{
return price;
}
bool getStatus(bool s)
{
return loan_status;
}
void setStatus(bool s)
{
loan_status = s;
}
string strCloth()
{
string s = ((loan_status == true)?"YES":"NO");
string x = ("Cloth Id : " + to_string(getID()) + " of Brand " +
getBrand() + " of size " + to_string(getSize()) + " of Price " +
to_string(getPrice())) + " has loan status " + s;
return x;
}
};
class Subscription
{
private :
int id;
string start_date;
Client c;
vector<Clothes> poc;
string deliver;
string returned;
static int _nextId;
static int sub_rate;
public :
Subscription(Client cc, string b)
{
c = cc;
start_date = b;
poc.clear();
deliver = "";
returned = "";
id = _nextId;
_nextId++;
}
int getID()
{
return id;
}
string getStartDate()
{
return start_date;
}
Client getClient()
{
return c;
}
vector<Clothes> getPOC()
{
return poc;
}
string getDeliver()
{
return deliver;
}
string getReturned()
{
return returned;
}
void setPOC(Clothes c)
{
poc.push_back(c);
}
void setDeliver(string d)
{
deliver = d;
}
void setReturned(string d)
{
returned = r;
}
static int getSubrate()
{
return sub_rate;
}
bool returnClothes(string d)
{
if(poc.size() == 0 || compareDates(d, deliver) < 0)
{
return false;
}
loan_status = false;
poc.clear();
returned = d;
return true;
}
bool requestClothes(string d, vector<Clothes> c)
{
if(loan_status == true ||compareDates(d, start_date) < 0 ||
compareDates(d, returned) < 0)
return false;
deliver = updateDate(d);
loan_status = true;
poc = c;
return true;
}
string strSub()
{
string x = ("Sub Id : " + to_string(getID()) + " of Client " +
getClient().name + " of items : ";
for(int i = 0; i < poc.size(); i++)
{
x += poc[i].id;
x += ',';
}
x += ("delivered on " + getDeliver() + " and returned on " +
getReturned());
return x;
}
};
int Subscription::_nextId = 0;
int Subscription::sub_rate = 69;
class Company
{
private:
vector<Clothes> cl;
vector<Client> c;
vector<Subscription> s;
public:
Company()
{
cl.clear();
c.clear();
s.clear();
}
Client searchClient(int x)
{
for(int i = 0; i < c.size(); i++)
{
if(c[i].getID() == x)
return c[i];
}
return NULL;
}
Clothes searchClothes(int x)
{
for(int i = 0; i < cl.size(); i++)
{
if(cl[i].getID() == x)
return cl[i];
}
return NULL;
}
Subscription searchSubscription(int x)
{
for(int i = 0; i < s.size(); i++)
{
if(s[i].getClient().getID == x)
return s[i];
}
return NULL;
}
void addClient(Client x)
{
for(int i = 0; i < c.size(); i++)
{
if(c[i].getID() == x.getID())
return;
}
c.push_back(x);
}
void addCloth(Cloth x)
{
for(int i = 0; i < cl.size(); i++)
{
if(cl[i].getID() == x.getID())
return;
}
cl.push_back(x);
}
bool addSubscription(Subscription x)
{
for(int i = 0; i < c.size(); i++)
{
if(c[i].getID() == x.getClient().getID())
{
for(int j = 0; j < s.size(); j++)
{
if(s[j].getID == x.getID() || s[j].getClient().getID() ==
x.getClient().getID())
return false;
}
}
}
s.push_back(x);
for(int i = 0; i < c.size(); i++)
{
if(x.getClient().getID() == c[i].getID())
{
c[i].addPayment(Subscription::getSubrate());
}
}
return true;
}
bool cancelSubscription(int x, string y)
{
for(int i = 0; i < c.size(); i++)
{
if(c[i].getID() == x)
{
if(c[i].getbalance() < 0)
return false;
for(int j = 0; j < s.size(); j++)
{
if(s[j].getClient().getID() == x)
{
if(compareDates(y, s[j].getStartDate()) < 0)
return false;
s.erase(s.begin()+j);
return true;
}
}
return false;
}
}
}
bool returnClothes(int x, string y)
{
for(int i = 0; i < c.size(); i++)
{
if(c[i].getID() == x)
{
for(int j = 0; j < s.size(); j++)
{
if(s[j].getClient().getID() == x)
{
return s[i].returnClothes(y);
}
}
return false;
}
}
return false;
}
bool requestClothes(int x, string y, vector<Clothes> z)
{
for(int i = 0; i < z.size(); i++)
{
if(z[i].getStatus() == true)
return false;
}
for(int i = 0; i < c.size(); i++)
{
if(c[i].getID() == x)
{
for(int j = 0; j < s.size(); j++)
{
if(s[j].getClient().getID() == x)
{
return s[i].requestClothes(y, z);
}
}
return false;
}
}
return false;
}
}
//compare date function will return < 0 if first parameter is smaller
Get Answers For Free
Most questions answered within 1 hours.