Write a program for a retail store. The program will use three classes to identi
ID: 3856787 • Letter: W
Question
Write a program for a retail store. The program will use three classes to identify and store the characteristics of its different customers.
This three classes will include a base class and two derived classes.
Design a base class named PersonData_C which will have member variables for last name, first name, and zip code. These three variables must be declared private.
The PersonData_C class will contain the appropriate constructors, getters and setters, and a virtual member function named Display_Data which will display the last name. first name, and zip code.
The CustomerData_C class (derived from PersonData) will have two member variables: customerNumber will be used to hold a unique integer for each customer, and mailingList will be a bool which is set to true if the customer wishes to be on the mailing list and false if not.
The CustomerData_C class will override virtual function Display_Data, and this version will display the customer number and mailing list code plus the PersonData_C class data.
Also write the appropriate constructors, accessor and mutator member functions for this class.
The retail store has a "preferred customer plan" in which customers may earn discounts on all their purchases. The amount of a customer's discount for a current purchase is determined by the amount of the customer's prior cumulative purchases in the store:
-after customers spend $500 (not including current purchase), they get a 5% discount on the current and all subsequent purchases.
-after customers spend $1,000 (not including current purchase), they get a 6% discount on the current and all subsequent purchases.
-after customers spend $1,500 (not including current purchase), they get a 7% discount on the current and all subsequent purchases.
-after customers spend $2,000 (not including current purchase), they get a 10% discount on the current and all subsequent purchases.
Write a PreferredCustomer_C class (derived from CustomerData_C) which will have two member variables: purchasesAmount will hold the total of a customer's purchases to-date, and discountLevel should be set to the correct discount percentage based on the purchasesAmount and the store's "preferred customer plan" described above (note: whenever the purchasesAmount is updated, the discountLevel must be re-calculated).
This class will override virtual function Display_Data, and this version will display the purchase amount to-date and discount level plus the CustomerData_C class data and the PersonData_C class data.
The PreferredCustomer_C class will also need the appropriate constructors, setters, and getters, and a member function to purchase items, i. e., spend money, which will add to the purchase amount to-date (after discount, if any).
In main create a CustomerData_C object using constructor arguments customer number: 987654 and mailing list code: true, and first and last name: Norton Orton, and zip code: 56789.
Then in function Display_Customer_Info with a base class reference variable as a parameter, use the virtual function Display_Data to display this object’s data items (screen print this display).
In main, create a PreferredCustomer_C object using the default constructor, then have the user enter the following data and store it in the object:
-last name: McDaniels
-first name: McDougal
-zip code: 10001
-customer number: 222222
-mailing list: 1 (true)
-purchase amount to-date: $2000.00
Have this preferred customer make a $1,000 purchase (entered by the user), and in the function with the base class reference variable as a parameter, use the virtual function Display_Data to display the information stored in the PreferredCustomer_C object's 7 data items (screen print the data entry and this display).
Attachments
Explanation / Answer
void main()
{
struct date
{
int day;
int month;
int year;
};
struct details
{
char name[20];
int price;
int code;
int qty;
struct date mfg;
};
struct details item[50];
int n, i;
printf("Enter number of items:");
scanf("%d", &n);
fflush(stdin);
for (i = 0; i < n; i++)
{
fflush(stdin);
printf("Item name: ");
scanf("%s", item[i].name);
fflush(stdin);
printf("Item code: ");
scanf("%d", &item[i].code);
fflush(stdin);
printf("Quantity: ");
scanf("%d", &item[i].qty);
fflush(stdin);
printf("price: ");
scanf("%d", &item[i].price);
fflush(stdin);
printf("Manufacturing date(dd-mm-yyyy): ");
scanf("%d-%d-%d", &item[i].mfg.day,
&item[i].mfg.month, &item[i].mfg.year);
}
printf(" ***** INVENTORY ***** ");
printf("---------------------------------------------------------
--------- ");
printf("S.N.| NAME | CODE | QUANTITY | PRICE
| MFG.DATE ");
printf("---------------------------------------------------------
--------- ");
for (i = 0; i < n; i++)
printf("%d %-15s %-d %-5d %-5d
%d/%d/%d ", i + 1, item[i].name, item[i].code, item[i].qty,
item[i].price, item[i].mfg.day, item[i].mfg.month,
item[i].mfg.year);
printf("---------------------------------------------------------
--------- ");
}
OR
<?php
use ScavixWDFBaseTemplate;
use ScavixWDFJQueryUIuiButton;
use ScavixWDFJQueryUIuiMessage;
class Basket extends ShopBase
{
function BuyNow()
{
// displays the chechout form, which has all inputs for address on it
$this->content( Template::Make('checkout_form') );
}
function StartCheckout($fname,$lname,$street,$zip,$city,$email,$provider)
{
if( !$fname || !$lname || !$street || !$zip || !$city || !$email )
redirect('Basket','Index',array('error'=>'Missing some data'));
$cust = new SampleCustomer();
$cust->fname = $fname;
$cust->lname = $lname;
$cust->street = $street;
$cust->zip = $zip;
$cust->city = $city;
$cust->email = $email;
$cust->price_total = 0;
$cust->Save();
$order = new SampleShopOrder();
$order->customer_id = $cust->id;
$order->created = 'now()';
$order->Save();
$ds = model_datasource('system');
foreach( $_SESSION['basket'] as $id=>$amount )
{
$prod = $ds->Query('products')->eq('id',$id)->current();
$item = new SampleShopOrderItem();
$item->order_id = $order->id;
$item->price = $prod->price;
$item->amount = $amount;
$item->title = $prod->title;
$item->tagline = $prod->tagline;
$item->body = $prod->body;
$item->Save();
$order->price_total += $amount * $prod->price;
}
$order->Save();
$_SESSION['basket'] = array();
log_debug("Handing control over to payment provider '$provider'");
$p = new $provider();
$p->StartCheckout($order,buildQuery('Basket','PostPayment'));
}
function PostPayment()
{
// we just display the $_REQUEST data for now.
// in fact this is the point where some processing
// should take place: send email to the team,
// that prepares the items for shipping, send email(s) to customer,...
log_debug("PostPayment",$_REQUEST);
$this->content("<h1>Payment processed</h1>");
$this->content("Provider returned this data:<br/>" +
"<pre>".render_var($_REQUEST)."</pre>");
}
function Notification($provider)
{
log_debug("Notification",$_REQUEST);
$provider = new $provider();
if( $provider->HandleIPN($_REQUEST) )
die("OK");
die("ERR");
}
}
<?php
use ScavixWDFModelModel;
use ScavixWDFPaymentIShopOrder;
use ScavixWDFPaymentShopOrderAddress;
class SampleShopOrder extends Model implements IShopOrder
{
const UNKNOWN = 0;
const PENDING = 10;
const PAID = 20;
const FAILED = 30;
const REFUNDED = 40;
public function GetTableName() { return 'orders'; }
public function GetAddress()
{
$res = new ShopOrderAddress();
$res->Firstname = $this->fname;
$res->Lastname = $this->lname;
$res->Address1 = $this->street;
$res->Zip = $this->zip;
$res->City = $this->city;
$res->Email = $this->email;
return $res;
}
public function GetCurrency() { return 'EUR'; }
public function GetInvoiceId() { return "I".$this->id; }
public function GetLocale() { return 'en-US'; }
public function GetTotalPrice($price = false)
{
if( $price !== false )
return $price * ( (1+$this->GetVatPercent()) / 100 );
return $this->price_total * ( (1+$this->GetVatPercent()) / 100 );
}
public function GetTotalVat() { return $this->price_total * ($this->GetVatPercent()/100); }
public function GetVatPercent() { return 19; }
public function ListItems() { return SampleShopOrderItem::Make()->eq('order_id',$this->id)->orderBy('id'); }
public function SetCurrency($currency_code) { /* we stay with EUR */ }
public static function FromOrderId($order_id)
{
return SampleShopOrder::Make()->eq('id',$order_id)->current();
}
public function SetFailed($payment_provider_type, $transaction_id, $statusmsg = false)
{
$this->status = self::FAILED;
$this->updated = $this->deleted = 'now()';
$this->Save();
}
public function SetPaid($payment_provider_type, $transaction_id, $statusmsg = false)
{
$this->status = self::PAID;
$this->updated = $this->completed = 'now()';
$this->Save();
}
public function SetPending($payment_provider_type, $transaction_id, $statusmsg = false)
{
$this->status = self::PENDING;
$this->updated = 'now()';
$this->Save();
}
public function SetRefunded($payment_provider_type, $transaction_id, $statusmsg = false)
{
$this->status = self::REFUNDED;
$this->updated = $this->deleted = 'now()';
$this->Save();
}
public function DoAddVat() { return true; /* Let's assume normal VAT customers for now */ }
}
<?php
use ScavixWDFModelModel;
use ScavixWDFPaymentIShopOrderItem;
class SampleShopOrderItem extends Model implements IShopOrderItem
{
public function GetTableName() { return 'items'; }
public function GetAmount($currency) { return $this->price; }
public function GetDiscount() { return 0; }
public function GetHandling() { return 0; }
public function GetName() { return $this->title; }
public function GetQuantity() { return $this->amount; }
public function GetShipping() { return 0; }
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.