Application Example: CD Publisher

In this exercise, we will develop an application for a small CD publishing company. The owner wants the prices to be calculated so a customer would get a discount if he orders more. To attract customers and encourage them to order more, she has decided to fix the prices so that the customer would pay:

• \$20/CD if he orders less than 20 units
• \$15/CD if he orders less than 50 units
• \$12/CD if he orders less than 100 units
• \$8/CD if he orders less than 500 units
• \$5/CD if he orders more than 500 units
 Practical Learning: Creating the Application
1. Start Visual Studio
2. Create a new Windows Forms Application and name it CDPublisher1
3. Design the form as follows:

 Control Name Text Other Properties Label Number of CDs: NumericUpDown updQuantity Maximum: 10000 TextAlign: Center Button btnClose Close Label Unit Price: TextBox txtUnitPrice 0 TextAlign: Right Label Total Price: TextBox txtTotalPrice 0 TextAlign: Right
4. Double-click the up down button to access its OnChange() event and implement it as follows:

 ```System::Void updQuantity_ValueChanged(System::Object^ sender, System::EventArgs^ e) { int Quantity; double UnitPrice, TotalPrice; Quantity = System::Decimal::ToInt32(updQuantity->Value); if( Quantity < 20 ) UnitPrice = 20; else if( Quantity < 50 ) UnitPrice = 15; else if( Quantity < 100 ) UnitPrice = 12; else if( Quantity < 500 ) UnitPrice = 8; else UnitPrice = 5; TotalPrice = Quantity * UnitPrice; txtUnitPrice->Text = UnitPrice.ToString("C"); txtTotalPrice->Text = TotalPrice.ToString(L"C"); }```
5. Double-click the Close button and implement it as follows:

 ```System::Void btnClose_Click(System::Object^ sender, System::EventArgs^ e) { Close(); }```
6. Test the application
7. Close it