(1) 选择3时的运行结果: (2) 选择5时的运行结果: The result is 16 Invalid Option
从键盘输入的8和two时(第二个数为非整数),程序运行结果: 程序不运行
4.在保持功能不变的情况下,改写上例代码如下: using System;
class CalcNumber { int number1,number2; char option; public void GetNumber()
{ Console.WriteLine(“Enter the First Number:”); number1=Convert.ToInt32(Console.ReadLine()); Console.WriteLine(“Enter the Second Number:”); number2=Convert.ToInt32(Console.ReadLine()); }
public void GetOption() { Console.WriteLine(“Main Menu”); Console.WriteLine(“1.Addition”);
Console.WriteLine(“2.Subtraction”); Console.WriteLine(“3.Multiplication”); Console.WriteLine(“4.Division”);
Console.WriteLine(“Enter the Operation you want to perform:”); option = Convert.ToChar(Console.ReadLine()); }
public int Compute() {
int result;