Amazon Interview Question
SDE-2sCountry: India
Interview Type: Phone Interview
hmm.. looks good. Can you please also enlist the functions/methods and collaborations among these classes.
by
Customer::paymentlist;
did you mean the transaction history?
Few suggestions:
1)
DVDLibrary
should also have customer list.
2)
class Customer
can have privileges. By it I mean privileges like: restricted access, power_user etc. where
privilege
can be either property or class in its own right depending upon the complexity of
privilege
3)There's also need for:
class Transactions
{
Customer& cust;
list<Dvd*> borrowed;
Date& transaction date;
public:
//methods
};
4)
class Payment
can have field: discount offered.
More enhancements can be followed.. your take?
#include <iostream>
#include <map>
#include<string>
using namespace std;
class DVD
{
string sName_;
int iD_;
string sDescrption_;
int iRent_;
bool bRented_;
public:
DVD(string name, int id, int rent, string desc = "") : sName_(name), iD_(id),
sDescrption_(desc), iRent_(rent), bRented_(false){}
const char* GetName() const
{
return sName_.c_str();
}
const char* GetDescription() const
{
return sDescrption_.c_str();
}
int GetID() const
{
return iD_;
}
int GetRent() const
{
return iRent_;
}
bool IsRented() const
{
return bRented_;
}
bool SetRentStatis(bool bRented)
{
bRented_ = bRented;
}
};
class Customer
{
string sAddress_;
string sCustName_;
bool bIsMember_;
int iCustId_;
public:
Customer(int id, string name, string address,bool member=false) : sCustName_(name),
sAddress_(address), bIsMember_(member), iCustId_(id)
{}
const char* GetName() const
{
return sCustName_.c_str();
}
const char* GetAddress() const
{
return sAddress_.c_str();
}
bool IsMember() const
{
return bIsMember_;
}
bool SetMember()
{
bIsMember_ = true;
}
};
class DVDLibrary
{
private:
//! Table of id vs DVD
map<int, DVD*> mIDTableDVD_;
//! name of DVD vs DVD pointers.
multimap<string, DVD*> mmTableOfNameDVD_;
//! Multimap of customer id vs DVD's with that customer.
multimap<int, DVD*> mmTableOfCustNameDVD_;
//! ID vs customer table.
multimap<int, Customer*> mIDCustomerTable_;
public:
DVDLibrary(){}
//! Add DVD to the store.
//! Create a DVD pointer and
//! Update mIDTableDVD_, mmTableOfNameDVD_
bool AddDvd(); //! Add dvd details as params
//! Remove DVD from the store.
//! Clear entry from mIDTableDVD_,mmTableOfNameDVD_
bool RemoveDvd();
//! Ask the Customer Id.
//! Check if the max number of the DVD's reached, If not give DVD
//! and do not prepare report.
//! set DVD status to rented.
bool RentDvdToMember();
//! Customer has agreed to buy the DVD.
//! Get Customer details. Create new customer. Add it to mIDCustomerTable_
//! Get Payment for each DVD
//! set DVD status to rented.
bool RentDvdToCustomer();
//! Let customer return DVD.
//! Update mmTableOfCustNameDVD_ and set the DVD status to not Rented.
bool RetrunDvdByCustomerOrMember(int dvdId, int custID);
//! Prepare the payment receipt for Customer.
//! To be called by RentDvdToCustomer.
string PrepareReceipt(int dvdId, Customer* cust);
};
This is exactly how I approached it. I think having two more classes, one called Transactions, and one called CreditCard may help the design. A transaction contains a Customer and a CreditCard and has its own unique_id. In your data library class you can maintain a set of these Transaction objects.
- Anonymous July 19, 2013