Question

In: Computer Science

(C++) D.Va's Mech System D.Va is a former professional gamer who now uses her skills to...

(C++) 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 enemy bots may have different power values. D.Va would need a damage matrix system strong enough to take 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 first have some variables with initial values indicating enemy information and some default value for D.Va’s 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 the combat report into a file that D.Va can review before she goes into combat.

1. Initialization

Your system should start with variables initialization as following:

//Enemy Information
const int enemy_bots = 5;
int enemy_bot_power[enemy_bots] = {2, 5, 3, 7, 1};
float enemy_boss_power = 27.24;

//D.Va Default Spec
int micro_missiles = 10;
float defense_matrix_power = 100.0;

This would give you some enemy information including the number of enemy bots, their corresponding power(int), and enemy boss's power(float). This will also give you the default power of D.Va's mech including the number of micro missiles are loaded and how much power can the defense matrix absorb by default.

2. Calculate Power Needed

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

  1. Matrix Power: D.Va's matrix power would need to take all damage from bots and the boss. The damage of a bot is twice as strong as its power and the damage of a boss is four times stronger than its power. For example, if you have two bots with power 3 and 8 and a boss with power 13.2, the total damage would be  3*2 + 8*2 + 13.2*4 = 74.8. We will make a function named total_damage which takes in an array of ints indicating bots' power, an int indicating number of enemy bots we have, and a float indicating the boss's 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. Missile Power: D.Va's micro missile system would need to be five 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 5 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 25, while missile_power(2.5) would return 12.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 D.Va's systems, let's load the power to D.Va's mech. You would want to write two functions here with the same name load_dva. Both load_dva() functions should have type 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 change the value of the defense_matrix_power. If the power needed is less than the default defense_matrix_power value then we don't change it, if it's larger, we update the defense_matrix_power value with the power needed. Therefore this function would take in two parameters, the defense_matrix_power and the matrix power needed we calculated from step 2. Given that the function would update the value of one of its parameters, defense_matrix_power, please make sure you use pass by reference to update the value that's passed in.
  2. Load Micro Missiles: To load the micro missile system, you want to update the number of micro_missiles value, which indicates how many micro missiles we need in the mech. If the number of missiles needed is less than the default missiles then we don't need to change it, but if it's larger, we update the micro_missiles value. The number of micro missiles we need is equal to missile power needed(from step 2) divided by 100. Make sure you round this up to an integer, you can use ceil() from <cmath> to round up the float. For example, ceil(23.6) would return integer 24. Make sure you include <cmath> to use the function ceil. Similar to the other load_dva function, this load_dva function will also take two parameters, micro_missiles and the missile power needed that we calculated from step 2. Again, this function would modify the value of micro_missiles so make sure you pass in by reference instead of pass in by value.

Now in your main function you would have these two lines to load D.Va's mech:

//Load D.Va
load_dva(defense_matrix_power, matrix_power_needed);
load_dva(micro_missiles, missile_power_needed);

These two lines would update the value of defense_matrix_power and the micro_missiles.

4. Report

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

D.Va's Combat Report
Combat with 5 enemy bots and one enemy boss with power 27.24.
Loaded mech with 10 micro missiles and the defense matrix with power 144.96.
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. I may change the value from step1 to test your code to see whether the report makes sense. Take the results from your previous calculation 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.

Solutions

Expert Solution

#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

// Calculating Matrix Power Needed
float total_damage(int enemy_bot_power[], int number_of_bots, float enemy_boss_power)
{
float matrix_power_needed = 4 * enemy_boss_power;
for (int i = 0; i < number_of_bots; i++)
matrix_power_needed += 2 * enemy_bot_power[i];
return matrix_power_needed;
}

// Calculating Missile Power
template <typename T>
T missile_power(T enemy_power) { return 5 * enemy_power; }

// Function to Load Defense Matrix
void load_dva(float *defense_matrix_power, float matrix_power_needed)
{
if (*defense_matrix_power < matrix_power_needed)
*defense_matrix_power = matrix_power_needed;
}

// Fuction to Load Micro Missiles
void load_dva(int *micro_missiles, float missile_power_needed)
{
*micro_missiles = ceil(missile_power_needed / 100);
}

int main()
{
//Enemy Information
const int enemy_bots = 5;
int enemy_bot_power[enemy_bots] = {2, 5, 3, 7, 1};
float enemy_boss_power = 27.24;

//D.Va Default Spec
int micro_missiles = 10;
float defense_matrix_power = 100.0;

// Matrix and Missile Power Needed
int number_of_bots = sizeof(enemy_bot_power) / sizeof(enemy_bot_power[0]);
float matrix_power_needed = total_damage(enemy_bot_power, number_of_bots, enemy_boss_power);
float missile_power_needed = missile_power<float>(enemy_boss_power);
for (int i = 0; i < number_of_bots; i++)
missile_power_needed += missile_power<int>(enemy_bot_power[i]);

//Load D.Va
load_dva(&defense_matrix_power, matrix_power_needed);
load_dva(&micro_missiles, missile_power_needed);

// Writing Summary report in the file
ofstream myfile;
myfile.open("report.txt");
myfile << "D. Va's Combat Report\n";
myfile << "Combat with " << enemy_bots << " enemy bots and one enemy boss with power " << enemy_boss_power << ".\n";
myfile << "Loaded mech with " << micro_missiles << " micro missiles and the defense matrix with power " << defense_matrix_power << ".\n";
myfile << "Ready for combat!";
myfile.close();

return 0;
}

***************†PLEASE DON'T FORGET TO GIVE THUMBS UP..


Related Solutions

A University is offering a charitable gift program. A former student who is now 50 years...
A University is offering a charitable gift program. A former student who is now 50 years old is consider the following offer: The student can invest $9,600.00 today and then will be paid a 8.00% APR return starting on his 65th birthday (i.e For a $10,000 investment, a 9% rate would mean $900 per year). The program will pay the cash flow for this investment while you are still alive. You anticipate living 20.00 more years after your 65th birthday....
Bill, a process engineer, learns from a former classmate who is now a regional compliance officer...
Bill, a process engineer, learns from a former classmate who is now a regional compliance officer with the Occupational Safety and Health Administration (OSHA) that there will be an unannounced inspection of Bill’s plant. Bill believes that unsafe practices are often tolerated in the plant, especially in the handling of toxic chemicals. Although there have been small spills, no serious accidents have occurred in the plant during the past few years. What should Bill do?
3. Provide an example of using your teamwork skills and interpersonal skills in the professional skills...
3. Provide an example of using your teamwork skills and interpersonal skills in the professional skills and management. Provide specific examples for each skill set.
A successful manager uses human skills, technical skills, and conceptual skills. Do you think these skills...
A successful manager uses human skills, technical skills, and conceptual skills. Do you think these skills can be learned? Explain. Are these skills all needed at the same time by the different levels of management?
A company uses an A. B, C classification system.
 A company uses an A. B, C classification system. The annual revenue from the 43 A items is $812,000, the annual revenue from the 164 B items is $257,000 and the annual revenue from the 511 C items is $52,000. Which items should be cycle counted most often? The 511 C items The 43 A items The 164 B items Do not favor any of the items. All items should be cycle counted the same amount
Annie lists Mike, her former supervisor at Startup Inc. as a reference in her application for...
Annie lists Mike, her former supervisor at Startup Inc. as a reference in her application for an open position at Tech Corp. When the Tech Corp. hiring manager calls Mike to ask about Annie, Mike falsely states that Annie was fired for leaking trade secrets. Mike actually knew that Annie quit because she was unhappy with how the business was being run, but was concerned her comments would get back to investors. Tech Corp. decides not to hire Annie based...
As an administrative professional, create a paper on the skills and procedures and include:
As an administrative professional, create a paper on the skills and procedures and include:Identifying techniques for managing time, stress, and anger in the workplaceApplying conflict resolution skills in the workplaceDescribe strategies and tools for managing your workloadExplain steps for setting and meeting goals and establishing priorities in the workplaceDefine the steps necessary for ethical change in the workplaceIdentify traits of an ethical administrative professionalList and describe basic workplace standards as found in the Canada Labour CodeIdentify characteristics of ethical businesses...
Elaborate on the relationship-building skills and inter-professional communication skills that apply and working towards meeting the...
Elaborate on the relationship-building skills and inter-professional communication skills that apply and working towards meeting the Electronic Health Record Implementation plan to the hospital.
A whistle-blower in her allegations made in a qui tam suit, alleged that her former employer...
A whistle-blower in her allegations made in a qui tam suit, alleged that her former employer fired her because she told the company that it was "padding the bills" to the federal government for the cost-plus contract it had to build ejection seats for fighter aircraft. She alleges that the company overcharged for materials, ran up labor costs, threw "all kinds of stuff in overhead," and illegally plugged corporate administrative costs into the contract billings. As the forensic accountant hired...
Who designed the selection system that's now in use at Chipotle? Who decides which personality traits...
Who designed the selection system that's now in use at Chipotle? Who decides which personality traits are critical enough to be assessed during screening and which don't quite make the cut? That would be Monty Moran, co-CEO of the company and a high school classmate of Ells. Moran had been the lead attorney for Chipotle and a CEO of a prestigious Denver law firm. Moran recalls the conversation that changed all that, repeating Ells's words: “Monty, you may be a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT