Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program named InputMethodDemo2 that eliminates the repetitive code in th

ID: 665778 • Letter: W

Question

Write a program named InputMethodDemo2 that eliminates the repetitive code in the InputMethod() in the InputMethodDemo program in Figure 8-5. Rewrite the program so the InputMethod()contains only two statements:

one = DataEntry(“first”);

two = DataEntry(“second”);

Farrell, Joyce. Microsoft® Visual C# 2012: An Introduction to Object-Oriented Programming, 5e, 5th Edition. Cengage Learning, 03/2013. VitalBook file.

The citation provided is a guideline. Please check each citation for accuracy before use.

using System; class InputMethodDemo Notice the keyword out. static void MainO int first, second; InputMethod (out first, out second); Console.WriteLine ("After InputMethod first is {0}", first); Console.WriteLine("and second is 10}", second) private static void InputMethod(out int one, out int two) string s1, s2; Console.Write("Enter first integer"); s1 = Console.ReadLine(); Console.Write("Enter second integer "); s2 = Console.ReadLine(); rt . ToInt32(s1); two = Convert.ToInt32(s2); Notice the keyword out.

Explanation / Answer

using System;

public class InputMethodDemoTwo

{

public static void Main()

{

int first, second;

InputMethod(out first, out second);

Console.WriteLine("After InputMethod first is {0}", first);

Console.WriteLine("and second is {0}", second);

Console.ReadLine(); }

public static void InputMethod(out int first, out int second)

{

first = DataEntry("first");

second = DataEntry("second");

}

public static int DataEntry(string method)

{

int result = 0;

if (method.Equals("first"))

{

Console.Write("Enter first integer ");

Int32.TryParse(Console.ReadLine(), out result);

}

else if (method.Equals("second"))

{

Console.Write("Enter second integer ");

Int32.TryParse(Console.ReadLine(), out result);

}

return result;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote