Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

D.Va's Mech System D.Va is a former professional gamer who now uses her skills to pilot a state-of-the-art mech in defense of her homeland. Her

D.Va's Mech System

D.Va is a former professional gamer who now uses her skills to pilot a state-of-the-art mech in defense of her homeland. Her real name is Hana and you can read more about her story here (Links to an external site.).

We are writing a program for D.Va's mech to load up before combat. D.Va's mech has two main systems, the micro missile system and the damage matrix system. The micro missile system is used to give damage to the enemies while the damage matrix system is used to absorb damage from enemies. You've seen how D.Va combats on the field during class and we are writing a short program to help D.Va prepare her mech systematically. The link of the video "Shooting Star" is here (Links to an external site.) in case you missed class.

D.Va will be fighting many enemy bots and one enemy boss for each combat. Each bot may have a different power value. D.Va would need a damage matrix system strong enough to absorb all damages from enemies and enough micro missiles to destroy all enemies. D.Va's mech has default power for both the damage matrix system and the micro missile system. If the default power isn't enough, our system would need to load more power to either or both of the systems for D.Va to win the combat.

System Detail

Our system will read combat information and default settings for D.Vas mech. It will then run three steps to analyze and prepare the mech for combat. First step is to calculate how much power D.Va needs given the number of enemies she's facing in combat. The second step is to load D.Va's mech with required power to fight the combat. Finally, the system will write a report into a file that D.Va can review before she goes into combat.

1. Read Combat Information

The monitoring system will give your system a file containing combat information. Therefore, your program will start by reading the file name from cin. Use the file name to open the file with fstream. Note that the file name will be something like "combat.txt" and this string will be the only thing your program will take from the input. No other input will be given.

The given file will contain 3 lines. The first line has one number indicating the number of bots attacking the city. The next line has many integers indicating each enemy bot's damage followed by one float number indicating the enemy boss' damage. The last line is the current setting of D.Va's mech, one integer indicating the number of micro missiles the mech has and one float indicating the amount of damage the defense matrix can absorb.

For example:

5 9 13 4 8 6 87.15 10 100.0

This file is indicating there're 5 enemy bots with damage 9, 13, 4, 8, and 6. And an enemy boss with damage 87.15. D.Va's mech currently has 10 micro missiles loaded and one defense matrix which can take 100.0 damage.

2. Calculate Power Needed

Then your system needs to calculate power needed for both the defense matrix system and the micro missile system. You will write two functions, one to calculate the damage the defense matrix system needs to absorb and another to calculate the power needed by the micro missile system.

  1. Defense Matrix Power: D.Va's defense matrix would need to take all damages from enemies. Your program will have a function named total_damage which takes in an array of ints storing bots' power, the number of bots, and a float indicating the boss' power. It would return a float telling us the total damage all enemies would give D.Va. That would then be how much power D.Va needs for her defense matrix system.
  2. Micro Missile Power: D.Va's micro missile system would need to be three times stronger than the enemies' power. We will make a function named missile_power which takes in an int or a float as the parameter indicating the power of the enemy and return 3 times the parameter value as the power needed for the missile system. Note that this function would only take one number at a time, and the reason that the value could be an int or a float is that the power for the enemy bot is an int and for the enemy boss is a float. The return value would match the type of the parameter. For example, missile_power(5) would return 15, while missile_power(2.5) would return 7.5. Therefore you would want to use templates for this function. The total missile power needed for D.Va will then be the sum of all the returned values from the missile_power function. Make sure you calculate missile power for both the bots and the boss and add them all together in main.

3. Load D.Va

Now that we know how much power is needed for both the micro missile system and the defense matrix system, let's load D.Va's mech to make sure the mech is ready. You would want to write two functions both called load_dva. Both load_dva functions should return void and take in two parameters. Their behaviors are slightly different. This is where we would use function overloading.

  1. Load Defense Matrix: To load the damage matrix, you want to first check how much damage the current defense matrix can absorb(the defense matrix power). If the total damage from enemies is less than the current defense matrix power then we don't change it, if it's larger, we update the defense matrix power with the total damage from enemies. The function will take two parameters, the current defense matrix power and the total damage from enemies we calculated from step 2. The function will update the value of the defense matrix power, therefore you will need to pass defense matrix power in by reference.
  2. Load Micro Missiles: To load the micro missile system, you want to update the number of micro missiles loaded in our mech. The number of micro missiles needed is equal to micro missile power (from step 2) divided by 100. Make sure you round this up to an integer, you can use ceil() from to round up. For example, ceil(23.6) would return integer 24. Make sure you include to use the function ceil. Again, if the number of missiles needed is less than the current missiles loaded in the mech then we don't need to change it, but if it's larger, we update the number of micro missiles in our mech. Similar to the other load_dva function, this load_dva function will also take two parameters, the number of micro missiles we currently have in the mech and the missile power needed that we calculated from step 2. This function will also modify the number of micro missiles so make sure you pass in by reference instead of pass in by value.

4. Report

Finally, let's write a summary report for D.Va to review before she heads into the combat. Write a file name "report.txt" into the current directory. The content of the report should look like this:

D.Va's Combat Report Combat with 5 enemy bots and one enemy boss with power 87.15. Loaded mech with 10 micro missiles and the defense matrix with power 127.15. Ready for combat!

Note that the number of enemy bots, the boss power, the number of missiles, and the defense matrix power in the file are all results calculated from your program and inserted into the file. Please don't hard code the output file. Take the results from your previous calculations to write into the report file.

Please make sure you have logic to check file open in your code and close the file after you finish the file operations.

Submission

You will only need to submit one single cpp file containing all your code. Please don't submit the report.txt as I will be generating that when grading your project. Make sure you include documentation for each function and each code block in your code as always. Please refer to the grading rubric for grading detail.

The unit tests will be triggering your functions, so please name your functions with the names specified in the assignment.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions