Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++: Consider the following C++ program, and one of the C# or Java programs: 1 #include 2 3 template void m(T t) { std::cout
C++: Consider the following C++ program, and one of the C# or Java programs: 1 #include 2 3 template void m(T t) { std::cout < < "m(T=" < < 4 typeid(T).name() < < ")" < < std::endl; } 5 void m(int i) { std::cout < < "m(int) "; } 6 template void f (T t) { m(t); } 7 8 int main() { 9 10 11 12} C#: f("Hello"); f (123) ; f (4000000000); 1 using System; 2 3 class Program { static void m (T t) { Console.WriteLine($"m (T={typeof (T)})"); } static void m(int i) { Console.WriteLine ("m (int)"); } 4 5 6 static void f (T t) { m(t); } 7 8 9 10 11 static void Main(string[] args) { f("Hello"); f (123); f (4000000000); 12 13} } Java: 1 public class Main { 2 3 4 5 6 7 8 9 10 11} static void m(T t) { System.out.println("m(T)"); } static void m(int i) { System.out.println("m(int)"); } static void f(T t) { m(t); } public static void main(String[] args) { f("Hello"); f (123); f (4000000000L); For the chosen pair of the C++ and C# programs, or the C++ and Java programs, answer the following: 1. What output will be printed by the C++ program, and what output by the second language in the pair? 2. Explain why the C++ program behavior is different (in terms of methods called) from that of the C# or Java one. Why do different methods get called? 3. In C++, C#, or Java, write a generic function that takes 3 arguments of any suitable type T and returns their maximum value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started