Cho em xin hướng làm bài assignment C
Problem A: Wedding Invitations (invite.c)
Though Arup wants to just send a free E-vitation to all of his guests for his wedding, his fiancee will have none of it. She has put her foot down and has insisted that they mail out regular invitations. After doing some research, Arup found out that depending on the size of the packages of invitations ordered, there are different prices. He wants you to figure out how many of each package to order, in order to get enough invitations to mail out at the cheapest price. For the purposes of this problem, there are only two packages:
- One with 50 invitations
- One with 200 invitations
Each vendor has a different price for the two packages. You’ll ask the user to input these two prices, as well as the total number of invitations that need to be sent out. Your job will be to calculate how many of each package to buy for the best deal, and how much will be spent on invitations.
Input Specification
- The cost of both packages (in dollars) will be positive real numbers less than 500.
- The number of invitations needed will be a positive integer less than 10000.
Output Specification
The first line of output will specify the number of small packages to buy to minimize the cost of the order of invitations using the following format:
You should order X small package(s).
where X is the number of small packages to order.
The second line of output will specify the number of large packages to buy to minimize the cost of the order of invitations using the following format:
You should order Y large package(s).
where Y is the number of small packages to order.
The last line of output should include the total cost of the packages using the following format:
Your cost for invitations will be $Z.
where Z is the minimum cost in question outputted to two decimal places.
Output Sample
Below is one sample output of running the program. Note that this sample is NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for clarity’s sake.)
Sample Run #1
What is the cost of a small package (in dollars)?
50.99
What is the cost of a large package (in dollars)?
150.99
How many invitations are you sending out?
240
You should order 1 small package(s).
You should order 1 large package(s).
Your cost for invitations will be $201.98.
Note: There are actually many somewhat tricky test cases for this problem. Keep in mind that the cost of the two packages might be anything. In some cases you might go with all of one package. In other cases, you might need to go with only the other package. Finally, in cases like this sample, a mixture of the packages is necessary.
Em có nghĩ đc 2 trường hợp là
if(cost_small < (cost_large / 4)) // nếu mua small lợi hơn - all in small { order_small = num_invites / small_invites; order_large = 0; if((num_invites % small_invites) != 0) // nếu sau khi mua vẫn còn thừa thì mua thêm 1 small order_small = order_small + 1; }
else if(cost_large < cost_small) // nếu mua large lợi hơn - all in large { order_small = 0; order_large = num_invites / large_invites;
if((num_invites % large_invites) != 0) // nếu còn thừa thì mua thêm 1 large order_large = order_large + 1; }
Chia thành 2 trường hợp lớn.
1.Dưới 200
2.Trên 200
Nếu là trường hợp dươi 200 thì mặc định sẽ có 1 large package hoặc vài smallpackage rồi ta so sánh cái nào rẻ hơn thì chọn.
Nếu lớn hơn 200 thì lại có 3 trường hợp mua hết small,mua hết large và mix large và small tùy cái nào rẻ hơn thì lấy.
Em cảm ơn ạ
Mà cho em hỏi cái trường hợp trên 200 ấy, thì hình như chỉ có 2 trường hợp thôi phải k.
Bạn tham khảo ví dụ code này: https://goo.gl/5LPKbp
em cảm ơn nhiều ạ
em đang nghiên cứu
Mình không có ý gì nhưng cái này nó giống homework hơn assignment. Vài bữa nữa bạn sẽ gặp assignment còn kinh khủng hơn thế này nhiều.