MCC - CIS162AD
CS9 Inheritance - 15 points
   cs.gif

This project is based on CS8 Classes. In this assignment students should create a 3rd class, clsOrderPreferred, that inherits clsOrder. The new class will be used to process orders for preferred customers, and will include a 5% discount in the calculation of extended price.

How to Complete Assignment:

Partial Code for clsOrderPreferred:

//Your Name
namespace CS8
{
    class clsOrderPreferred : clsOrder 
    {
        private const decimal cdecDISCOUNT_RATE = 0.05M;

        //declare default constructor - call base default constructor
    
        //declare overloaded constructor - call base overloaded constructor

        //override definition of virtual definition in base
        public override void calcExtendedPrice()
        {
            cdecExtendedPrice = cintQuantity *
                (cdecPrice - cdecPrice * cdecDISCOUNT_RATE);
        }
    }//end of class
}

UML - Class Diagrams:

Symbol definitions:
- private
+ public
# protected
* shared/static
% read-only

clsOrder < Inherited By clsOrderPreferred
# string cstrDescription
# int cintQuantity
# decimal cdecPrice
# decimal cdecExtendedPrice

(Shared Variables)
# * decimal cdecTotalPrice
# * int cintTotalCount

(Const Variables)
# decimal cdecDISCOUNT_RATE = 0.05M

+ clsOrder( )
    default constructor

+ clsCustomer(string strName,
    string strStreet, string strCity,
    string strState, string strZip)

+ set & get string Description
+ set & get int Quantity
+ set & get decimal Price

(read-only property)
+ % get decimal ExtendedPrice

(Shared read-only property)
+ * % decimal get TotalPrice
+ * % int get TotalCount

(Supporting Methods)
+ virtual void calcExtendedPrice( )
+ void accumulateTotals( )
+ * void resetTotals( )
+ clsOrderPreferred( )
   : base( )
       call default constructor in base

+ clsOrderPreferred(string strDescription, int intQuantity, decimal decPrice)
   : base(strDescription, intQuantity, decPrice)

    Instead of assigning values here pass the arguments
    to the overloaded constructor in the base which
    already has the code to assign the values.

(Supporting Methods)
override definition of virtual definition in base
+ override void calcExtendedPrice( )


Partial Code for CS8Form:

After the statement (found at the top of the program):
    private clsOrder cobjOrder;
Add:
    private clsOrderPreferred cobjOrderPreferred;
to look like this:

        //declare class-level references to classes
        private clsCustomer cobjCustomer;
        private clsOrder cobjOrder;
        private clsOrderPreferred cobjOrderPreferred;
//Replace the existing btnCalculate method with the following:
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            string strMailingLabel;

            try
            {
                if (chkPreferredDiscount.Checked == true)
                {
                    //Create an instance of clsOrderPreferred
                    cobjOrderPreferred = new clsOrderPreferred 
                        (txtDescription.Text,
                         int.Parse(txtQuantity.Text),
                         decimal.Parse(txtPrice.Text));

                    //Calculate Extended Price 
                    cobjOrderPreferred.calcExtendedPrice();
                    //Accumulate Totals
                    cobjOrderPreferred.accumulateTotals();
                    //Display Extended Price
                    lblExtension.Text = cobjOrderPreferred.ExtendedPrice.ToString("C");
                }
                else
                {
                    //Create an instance of clsOrder 
                    cobjOrder = new clsOrder 
                        (txtDescription.Text,
                         int.Parse(txtQuantity.Text),
                         decimal.Parse(txtPrice.Text));

                    //Calculate Extended Price 
                    cobjOrder.calcExtendedPrice();
                    //Accumulate Totals
                    cobjOrder.accumulateTotals();
                    //Display Extended Price
                    lblExtension.Text = cobjOrder.ExtendedPrice.ToString("C");
                }//end if

                //Create an instance of clsCustomer using the overloaded constructor
                cobjCustomer = new clsCustomer(txtName.Text, txtStreet.Text,
                                    txtCity.Text, txtState.Text, txtZip.Text);

                //Build mailing label using the Get methods for Customer.
                strMailingLabel = cobjCustomer.Name + "\n" +
                                  cobjCustomer.Street + "\n" +
                                  cobjCustomer.City + ", " +
                                  cobjCustomer.State + "  " + cobjCustomer.Zip;

                //Display mailing address
                lblMailingLabel.Text = strMailingLabel;

                //Shared properties are accessed using class name
                //Test the Get Property methods of ReadOnly Shared properties 
                lblTotalCount.Text = clsOrder.TotalCount.ToString("N0");
                lblTotalPrice.Text = clsOrder.TotalPrice.ToString("C");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error :" + ex.Message
                                + "\n" + ex.StackTrace,
                                "Try/Catch - Unexpected Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }//end try
        }//end of btnCalculate        
        

Test Data:

Debug Option:
Consider walking through all of the class methods using the debugger. Set a break on the if statement inside of btnCalculate, and then step through (F11) the program to see the constructors and methods of the base and inherited classes.

Submit the modified CS8Form.cs, CS8Form.Designer.cs, clsOrder.cs and the new clsOrderPreferred.cs


Adopted from Programming in C#.Net, by Bradley and Millspaugh, 2004
Revised: 10/20/2009 - www.mc.maricopa.edu/~marquez/cis162ad/cs9_inheritance.html