首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    面向对象的简单计算器C#语言版

    using circumstance; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 下午第四题面向对象的计算器 {     class Program     {         static void Main(string[] args)         {             while (true)             {                 Console.WriteLine("请输入第一个数字:");                 int number1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("请输入运算符:");                 string str = Convert.ToString(Console.ReadLine());                 Console.WriteLine("请输入第二个数字:");                 int number2 = Convert.ToInt32(Console.ReadLine());                 JiSuan jisuan = Show(str, number1, number2);                 if (jisuan != null)                 {                     int result = jisuan.Compute();                     Console.WriteLine("运算结果为:" + result);                 }                 else                     Console.WriteLine("请输入正确的运算符!");             }         }         ///

            /// 将运算符和数字传入的方法         ///         /// <param name="str">运算符</param>         /// <param name="number1">第一个数</param>         /// <param name="number2">第二个数</param>         /// <returns></returns>         private static JiSuan Show(string str, int number1, int number2)         {             JiSuan ji = null;             switch (str)             {                 case "+": ji = new Add(number1, number2); break;                 case "-": ji = new Sub(number1, number2); break;                 default:                     break;             }             return ji;         }     } }

    01

    两位数活多位乘法的计算编程

    Private Sub Command1_Click() Dim M As String Dim N As String M = Trim(Text1.Text) N = Trim(Text2.Text) Dim Number1() As Byte Dim Number2() As Byte ReDim Number1(Len(M)) ReDim Number2(Len(N)) Dim index As Byte For index = 1 To Len(M) Step 1 Number1(index) = Mid(M, index, 1) Next index For index = 1 To Len(N) Step 1 Number2(index) = Mid(N, index, 1) Next index Dim Result() As Byte ReDim Result(Len(M) + Len(N)) Dim MCarry As Byte Dim ACarry As Byte Dim Remainder As Integer Dim i As Integer, j As Integer Dim Mtemp As Integer, Atemp As Integer For i = Len(N) To 1 Step -1 For j = Len(M) To 1 Step -1 Mtemp = Number1(j) * Number2(i) + MCarry MCarry = Mtemp \ 10 Remainder = Mtemp Mod 10 Atemp = Remainder + Result(i + j) + ACarry ACarry = Atemp \ 10 Result(i + j) = Atemp Mod 10 Next j Result(i) = MCarry + ACarry MCarry = 0 ACarry = 0 Next i Dim Mstr As String For index = 1 To Len(N) + Len(M) Mstr = Mstr & Str(Result(index)) Next Label3.Caption = Mstr End Sub

    02
    领券