Objectives: • Practice passing parameters by reference Exercise 1: Steve has three tools: iron sward, diamond pickaxe, a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Objectives: • Practice passing parameters by reference Exercise 1: Steve has three tools: iron sward, diamond pickaxe, a

Post by answerhappygod »

Objectives Practice Passing Parameters By Reference Exercise 1 Steve Has Three Tools Iron Sward Diamond Pickaxe A 1
Objectives Practice Passing Parameters By Reference Exercise 1 Steve Has Three Tools Iron Sward Diamond Pickaxe A 1 (69.01 KiB) Viewed 75 times
Objectives Practice Passing Parameters By Reference Exercise 1 Steve Has Three Tools Iron Sward Diamond Pickaxe A 2
Objectives Practice Passing Parameters By Reference Exercise 1 Steve Has Three Tools Iron Sward Diamond Pickaxe A 2 (69.01 KiB) Viewed 75 times
Objectives Practice Passing Parameters By Reference Exercise 1 Steve Has Three Tools Iron Sward Diamond Pickaxe A 3
Objectives Practice Passing Parameters By Reference Exercise 1 Steve Has Three Tools Iron Sward Diamond Pickaxe A 3 (58.95 KiB) Viewed 75 times
Objectives: • Practice passing parameters by reference Exercise 1: Steve has three tools: iron sward, diamond pickaxe, and gold shovel. He can hold one tool in his hand, one tool in his inventory hot bar, and one tool in the inventory. If Steve clicks F, his tools are swapped as follows: The tool in his hand goes to the inventory The tool in the inventory goes to the hot bar • The tool in the hot bar goes to his hand Write a C++ program to model switching between the tools. 1. Write the function void swap(char hand, char hotBar, char inventory) which swaps the tools as indicated above. 2. Write the function void print(char hand, char botBar, char inventory) which prints the contents of each as shown in the sample output. 3. In the main: a. In a loop, ask the user to click a button b. If the user inputs F, swap the tools. If the user inputs N, do nothing. c. Print the contents of the player's hand, hot bar, and inventory. d. If the user inputs anything other than F or N, the program should exit. Sample output: Microsoft Visual Studio Debug Console The following tools are available to you: S: Sward p: pickaxe ti torch Hand Hot Bar Inventory s р t Enter a command: F Hand Hot Bar Inventory t Enter a comand: F Hand Hot Bar Inventory t Enter a command: N Hand Hot Bar Inventory t Enter command: M C:\Users\user\source repos\Project1\Debug\Project1.exe (process 3796) exited with code . Press any key to close this window

Exercise 2: Coal ores can be squished together to form coal blocks. Crafting Coal blocks can be broken down back to coal ores. A coal block is equivalent to 9 coal ores. Both processes are done in the crafting table. Write a C++ program to model crafting with coal. 1. Declare the function void craftCoalint& colores, int& coalBlocks) which: a. Takes the number of coal ores as well as coal blocks b. If the number of coal ores is less than 9, then function should break the coal blocks down to ores and add it to the number of coal ores. c. Else, the function should try to convert as many of the coal ores to blocks as possible. A block can only be crafted with exactly 9 ores. 2. In the main, ask the user how many coal blocks and ores they have in their inventory, then call craftCoal Print the updated number of coal ores and blocks. Sample output: K Microsoft Visual Studio Debug Console How many do you have of the following? coal blocks: 6 Crafting... You now have 7 coal Ores and 13 coal Blocks Coal ores: 70 Microsoft Visual Studio Debug Console How many do you have of the following? Coal ores: 8 Coal blocks: 16 Crafting... You now have 152 Coal Ores and a coal Blocks
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply