HW 09

pdf

School

University of Minnesota-Twin Cities *

*We aren’t endorsed by this school

Course

1113

Subject

Computer Science

Date

Nov 24, 2024

Type

pdf

Pages

3

Uploaded by Hughng

Report
CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 8 Fall 2016 Due Date: Wednesday, Dec. 7, 2016 before 4:00pm. Instructions : This is an individual homework assignment. There are two problems worth 20 points each. Solve the problems below by yourself (unlike the labs, where you work collaboratively), and submit the solution as a C++ source code file. Because all homework assignments are submitted and tested electronically, the fol- lowing are important: • You follow any naming conventions mentioned in the homework instructions. • You submit the correct file(s) through Moodle by the due deadline. • You follow the example input and output formats given in each problem description. • Regardless of how or where you develop your solutions, your programs compile and execute on cselabs computers running the Linux operating system. Problem A: Production line (20 points) Ask the user to read a file. The file will be in the same format as “items.txt” on the website. There will always be a list of items with a name and price followed by some amount of recipes. If a recipe for an item is not present, the only way to make the item is to buy it directly. Make a program that reads all the items and recipes, then says how much profit can be made by making each item. If an item has no recipe, you would buy that item then resell it for the same price and make a profit of 0. If an item does have a recipe, you would buy the materials to make this item and subtract this cost from the price of the final product. There will only be zero or one recipe per item. The items will always be listed first. The names of items will always be a single word (using a _ to join names that are normally multiple words). You may assume there will be less than 50 items and each recipe will use less than 50 other items to create a final product. Example 1 (user input is underlined): What file to load?  items1.txt   Making Wood, profit=0  Making Metal, profit=0  Making Cat, profit=0  Making Spear, profit=40.2  Example 2 (user input is underlined): What file to load?  items2.txt   Making Lint, profit=0  Making Rubber_Chicken, profit=0  Making Wood, profit=0 
Making Glasses, profit=0  Making Substitute_Teacher, profit=65.8  Making Cat_Toy, profit=49.95  Making Scare_Crow, profit=100.58  Making Dog_Toy, profit=20  When you are done, name the source code file <username>_9A.cpp. Here you replace <username> with your U of M email address; for example, if your email address is smithx1234@umn.edu, your file should be named smithx1234_9A.cpp. Then submit your program using the HW 9 Problem A submission link in Moodle. Problem B: Cha-CHING Inc. (20 points) Reuse your code from part A. Find the item with the most profit and make that item. Repeat this process 20 times and show your total profit over the period. However, after making an item, the cost of the materials you buy increases by 10%. If multiple materials are used in a single recipe, each the cost is increased multiple times. For example, making a “Spear” in “items1.txt” takes 2 pieces of “Wood”. Each “Wood” initially costs 2.5. Buying the first piece of wood increases this from 2.5 to 2.75 and the second increases it from 2.75 to 3.025. This price increase is applied after you buy the wood. So your the first “Spear” made has a wood cost of 2 x 2.5 = 5, while the second “Spear” has a wood cost of 2 x 3.025 = 6.05. If no items make profit, simply make the first item on the list. Example 1 (user input is underlined): What file to load?  items1.txt   Time 1: Making Spear, total profit = 40.2  Time 2: Making Spear, total profit = 78.8  Time 3: Making Spear, total profit = 115.525  Time 4: Making Spear, total profit = 150.046  Time 5: Making Spear, total profit = 181.976  Time 6: Making Spear, total profit = 210.849  Time 7: Making Spear, total profit = 236.113  Time 8: Making Spear, total profit = 257.108  Time 9: Making Spear, total profit = 273.043  Time 10: Making Spear, total profit = 282.975  Time 11: Making Spear, total profit = 285.772  Time 12: Making Wood, total profit = 285.772  Time 13: Making Wood, total profit = 285.772  Time 14: Making Wood, total profit = 285.772  Time 15: Making Wood, total profit = 285.772  Time 16: Making Wood, total profit = 285.772  Time 17: Making Wood, total profit = 285.772  Time 18: Making Wood, total profit = 285.772  Time 19: Making Wood, total profit = 285.772  Time 20: Making Wood, total profit = 285.772
Example 2 (user input is underlined): What file to load?  items2.txt   Time 1: Making Scare_Crow, total profit = 100.58  Time 2: Making Scare_Crow, total profit = 199.216  Time 3: Making Scare_Crow, total profit = 295.713  Time 4: Making Scare_Crow, total profit = 389.856  Time 5: Making Scare_Crow, total profit = 481.409  Time 6: Making Scare_Crow, total profit = 570.114  Time 7: Making Scare_Crow, total profit = 655.682  Time 8: Making Scare_Crow, total profit = 737.801  Time 9: Making Scare_Crow, total profit = 816.124  Time 10: Making Scare_Crow, total profit = 890.268  Time 11: Making Scare_Crow, total profit = 959.815  Time 12: Making Scare_Crow, total profit = 1024.3  Time 13: Making Scare_Crow, total profit = 1083.22  Time 14: Making Substitute_Teacher, total profit = 1138.72  Time 15: Making Substitute_Teacher, total profit = 1190.77  Time 16: Making Scare_Crow, total profit = 1240.51  Time 17: Making Cat_Toy, total profit = 1289.79  Time 18: Making Cat_Toy, total profit = 1338.63  Time 19: Making Cat_Toy, total profit = 1386.76  Time 20: Making Cat_Toy, total profit = 1433.75  When you are done, name the source code file <username>_9B.cpp. Here you replace <username> with your U of M email address; for example, if your email address is smithx1234@umn.edu, your file should be named smithx1234_9B.cpp. Then submit your program using the HW 9 Problem B submission link in Moodle.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help