Classroom Experiment--the lowest price experiment of purchase book

Source: Internet
Author: User

Classroom Experiment--the lowest price experiment of purchase book

First, design ideas

The experiment is to calculate the purchase of a number of books the lowest price, when the choice of different types of books when the purchaser can enjoy the discount, and according to the number of books purchased by the purchaser can be divided into four files discount, the number of 2,3,4,5 when the discount is 5%,10%,20%,25%.

The core of the problem is to find the law of the lowest price, and this law in every 10 books cycle once, in these 10 books in addition to eight books to enjoy 20% discount, others follow the priority to enjoy 25% preferential rules, so when calculating the final price, Just divide the book of multiples of 10 and the remaining books to calculate the price.

Second, the Code implementation

//Hao Ying 2016/6/2//The lowest price experiment of book purchase#include <iostream>using namespacestd;intMain () {inti,number,a,b; DoublePrice ; cout<<"Please enter the number of books:"; CIN>>Number ; A=number/Ten; b=number%Ten; if(b==0) { price=2*a*8*0.25; }    Else if(b>0&&b<9&&b!=8)    {        if(b%5==0) { price=Ten*a*8*0.25+ (b/5)*5*8*0.25+ (b%5)*8*0.25; }        Else if(b%5==1) { price=Ten*a*8*0.25+ (b/5)*5*8*0.25+ (b%5)*8; }        Else if(b%5==2) { price=Ten*a*8*0.25+ (b/5)*5*8*0.25+2*8*0.05; }        Else if(b%5==3) { price=Ten*a*8*0.25+ (b/5)*5*8*0.25+3*8*0.1; }        Else if(b%5==4) { price=Ten*a*8*0.25+ (b/5)*5*8*0.25+4*8*0.2; }    }    Else if(b==8) { price=Ten*a*8*0.25+8*8*0.2; } cout<<"The lowest price the reader buys for this book is:"<<Price ; cout<<Endl; return 0;}

Third, the realization

The lowest price when the number of books is 1-10:

When the number of books is 338, the maximum price is:

Iv. Personal Summary

Through this experiment I think the main or exercise the design ideas, in fact, a beginning to think of simple, such as 8 book only think of the combination of 5 and 3, and did not think of 4 and 4 or other combinations, when further thinking about the time, considering the number of books in the case there are a lot of combinations of ways, So do not know how to find the least cost from these circumstances, in the teacher's tips, try to start from a book to find the law, sure enough, his lowest price is a regular, only in multiples of 8 of the case, and every 10 can enjoy 25% discount, Just consider the case of removing the extra books from 10. The harvest in this experiment is a mathematical method, it tells us to solve a problem before we find the best way to avoid doing a lot of useless, but also to improve our efficiency in solving problems, in the face of problems when more than the brain is the best way to solve the problem! This experiment has benefited me a lot, then I will definitely work harder to finish the experiment!

Classroom Experiment--the lowest price experiment of purchase book

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.