Question

In: Computer Science

Write a method that takes four strings as parameter. The first string should be a pokemon...

Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type, the third a pokemon name, and the fourth a pokemon type. The method should print out which pokemon has the advantage over the other based on their type. In this case you can use fire, water, and leaf. Example outputs should be like:

Example:

Pokemon X (Water) has the advantage over Pokemon Y (fire)

Pokemon X (Fire) has the advantage over Pokemon Y (leaf)

Pokemon X (Leaf) has the advantage over Pokemon Y (water)

Solutions

Expert Solution

#include<bits/stdc++.h>
using namespace std;

void pokemon(string p1, string t1, string p2, string t2) {
  if (t1 == "water" && t2 == "fire") {
    cout << "Pokemon " << p1 << " (" << t1 << ")" << " has the advantage over Pokemon " << p2 << " (" << t2 << ")\n";
  } else if (t2 == "water" && t2 == "fire") {
    cout << "Pokemon " << p2 << " (" << t2 << ")" << " has the advantage over Pokemon " << p1 << " (" << t1 << ")\n";
  }else if (t1 == "fire" && t2 == "leaf") {
    cout << "Pokemon " << p1 << " (" << t1 << ")" << " has the advantage over Pokemon " << p2 << " (" << t2 << ")\n";
  } else if (t2 == "fire" && t2 == "leaf") {
    cout << "Pokemon " << p2 << " (" << t2 << ")" << " has the advantage over Pokemon " << p1 << " (" << t1 << ")\n";
  }else if (t1 == "leaf" && t2 == "water") {
    cout << "Pokemon " << p1 << " (" << t1 << ")" << " has the advantage over Pokemon " << p2 << " (" << t2 << ")\n";
  } else if (t2 == "leaf" && t2 == "water") {
    cout << "Pokemon " << p2 << " (" << t2 << ")" << " has the advantage over Pokemon " << p1 << " (" << t1 << ")\n";
  }
}

int main()
{
  pokemon("X","fire","Y","leaf");
}

OUTPUT:


Related Solutions

Please use JAVA to do this: Write a method that takes four strings as parameter. The...
Please use JAVA to do this: Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type(either fire, water, or leaf, where water beats fire, fire beats leaf and leaf beats water), the third a pokemon name, and the fourth a pokemon type. The method should print out which pokemon has the advantage over the other based on their type. Example: Pokemon X(which is the fire type) has the...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. 2. Given the following Vehicle interface and client program in the Car class: public interface Vehicle{ public void move(); } public class Car implements Vehicle{ public static void main(String args[]) Vehicle v = new Vehicle(); // vehicle declaration } The above declaration is valid? True or False? 3. Java permits a class to...
Write a static method called "evaluate" that takes a string as a parameter
In Java language  Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
Create a method called firstLetter that takes a String parameter and integer parameter. It should return...
Create a method called firstLetter that takes a String parameter and integer parameter. It should return -1 if the number of words in the given String is greater than or equal to the integer parameter (it should return -1 and not process the String any further) (4 points). If the String does not have more words than the given integer, the method should return 1 if all the words in the string start with the same letter(8 points) and 0...
Java Write a valid Java method called printReverse that takes a String as a parameter and...
Java Write a valid Java method called printReverse that takes a String as a parameter and prints out the reverse of the String. Your method should not return anything. Make sure you use the appropriate return type.
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be...
Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be passed in on the stack. The answer should be returned in eax. The subroutine should not disturb any registers except eax, ecx, and edx. (Save any registers on the stack and restore them before exiting the subroutine.) Upon entry to the subroutine, push ebp, etc., to access the parameter.
Write a RECURSIVE method that receives a string as a parameter. The method will return true...
Write a RECURSIVE method that receives a string as a parameter. The method will return true if the string received as a parameter is a palindrome and false if it is not. The method must not have any loops! In JAVA
in c++ Write a function that takes a C string as an input parameter and reverses...
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT