Software Engineering Classroom Training ———— cheapest book plan

Source: Internet
Author: User

One • Experimental topics :

A bookstore for the "Harry Potter" series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of 8 yuan, the specific discount is as follows:

Discount on this number

2 5%

3 10%

4 20%

5 25%

Depending on the number of volumes purchased and this number, different discount rules will be applicable. The singular book only corresponds to one discount rule, for example, two volume 1, one volume 2, you can enjoy 5% discount, another volume does not enjoy the discount. The design algorithm calculates the lowest price for the reader to buy a batch of books.

Two · Experiment ideas:

The price of 6~10 was calculated and 8 exceptions were obtained. Because 8 is divided into 4 books and 4 is cheaper, the others are 5 and the remainder to buy. And more than 10 of this book can be corresponding to 6~10, for example, 11 and 6 are equivalent, 17 and 7 is equivalent ... The rule of calculation is to put this number n mod 5 =k, then the corresponding k+5 can be. Then 5*y+8 the number of exceptions.

three · code

//goyshu.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include"iostream"using namespacestd;intMain () {intb//define the number of books purchased    intM,n; inti; Doublesum=0; cout<<"Please enter the number of books you need to purchase:"<<Endl; CIN>>b; M=b/5; N=b%5; I=n+5; if(i!=8)    {        Switch(n) { Case 0: Sum=m* +*0.75;  Break;  Case 1: Sum=m* +*0.75+8;  Break;  Case 2: Sum=m* +*0.75+ -*0.95;  Break;  Case 3: Sum=m* +*0.75+ -*0.9;  Break;  Case 4: Sum=m* +*0.75+ +*0.8;  Break; }    }        Elsesum= (M-1)* -+4*8*0.8*2; if(i!=8) {cout<<"Reader Purchase"<<b<<"The lowest price for this book is:"<<Endl; cout<<sum<<Endl; cout<<"can be divided into buy"<<m<<"Set"<<"and the"<<n<<"the different types of books"<<Endl; }    Else{cout<<"Reader Purchase"<<b<<"The lowest price for this book is:"<<Endl; cout<<sum<<Endl; cout<<"can be divided into buy"<<m-1<<"Set"<<"and the"<<"2 sets of 4 different types of books"<<Endl; }    return 0;}

Four · experience

This topic at the beginning of the time I feel very simple, because I did not count 6-10 of the lowest price is how much, wrong to think is 5+n. But it was a trap to calculate that I knew 8 books. Once you know how to buy, the code is much easier. It seems to be a program ape should be particularly serious, not careless.

Software Engineering Classroom Training ———— cheapest book plan

Related Article

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.