Maximum discounts for classroom exercises, minimum discounts, and discounts
I. Question requirements and design ideas
1. Question requirements
The bookstore offers promotions for the Harry Potter series of books. There are 5 volumes in total, which are represented by numbers 0, 1, 2, 3, and 4. The price of a single volume is 8 yuan. The specific discount is as follows:
Discounts
2 5%
3 10%
4 20%
5 25%
According to the number of purchased volumes and the quantity, different discount rules will be applied. A single book corresponds to only one discount rule. For example, if you purchase two volumes 1 and one volume 2, you can enjoy a 5% discount, while the other one does not. The design algorithm can calculate the lowest price for the readers to purchase a batch of books. 2. the five-core design concept is the basis, and all other situations with a ratio of five or more are based on the basis, we only need to solve the lowest price for users who have bought 6, 7, 8, and 9 books. Other users can directly overlay them. Through calculation, if you buy 6 books, you will be entitled to a 5-25% discount, or a 1-25% discount. If you buy 7 books, you will be entitled to a 5-5% discount and a 2-discount; when you buy 8 books, the minimum price is 4-20%. When you buy 9 books, the minimum price is 5-25%. Then, the user enters the purchase quantity I and uses the following statement to implement a = I/5;
B = 30 *;
C = I % 5.Ii. Source Code
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace youhuifangfa11 {12 public partial class Form1 : Form13 {14 double b, sum;15 int a, i, c;16 public Form1()17 {18 InitializeComponent();19 }20 21 private void button1_Click(object sender, EventArgs e)22 {23 i = int.Parse(textBox1.Text);24 if (i % 5 != 3)25 {26 a = i / 5;27 b = 30 * a;28 c = i % 5;29 if (c == 0)30 {31 sum = b;32 33 }34 if (c == 1)35 {36 sum = b + 8;37 }38 else if (c == 2)39 {40 sum = b + 16 * 0.95;41 }42 else if (c == 3)43 {44 sum = b + 24 * 0.9;45 }46 else if (c == 4)47 {48 sum = b + 32 * 0.8;49 }50 51 }52 else if(i%5==3&&i!=3)53 {54 a = i / 5;55 b = 30 * (a - 1);56 c = i % 5;57 sum = b + 32 * 0.8 * 2;58 }59 else if (i == 3)60 {61 sum = 0.9 * 24;62 }63 textBox3.Text = sum.ToString();64 }65 66 private void textBox1_TextChanged(object sender, EventArgs e)67 {68 69 }70 }71 }
Iii. Running results
Iv. Experiences
This topic is difficult to calculate at first, but there is a foundation for complicated and big tall buildings. For this topic, the discounts offered by the store are the basis, we only need to follow this foundation for consideration. Therefore, software development, especially implementation like this, will certainly have a way to find things and what variables are, what is the constant amount and what is the basis is easy to do.