四则运算计算器——计应191西——计应191西4组毛绍冲

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎使用计算器,请根据提示进行操作:");
            Console.WriteLine("加法运算,请按1");
            Console.WriteLine("减法运算,请按2");
            Console.WriteLine("乘法运算,请按3");
            Console.WriteLine("除法运算,请按4");
 
            int flag = Convert.ToInt32(Console.ReadLine());
 
            int a, b;
 
            Calclator c;
 
            switch(flag)
            {
                case 1 :
                    Console.WriteLine("请输入2数,并换行");
                    a = int.Parse(Console.ReadLine());
                    b = int.Parse(Console.ReadLine());
//Console.WriteLine("这是一条测试语句。");
//Console.WriteLine(a);
//Console.WriteLine(b);
 
                    c = new Calclator(a, b);
                    Console.WriteLine(c.a + " + " + c.b  + " = {0}", c.add());
 
                    break;
                case 2 :
                    Console.WriteLine("请输入2数,并换行");
                    a = int.Parse(Console.ReadLine());
                    b = int.Parse(Console.ReadLine());
 
                    c = new Calclator(a, b);
                    Console.WriteLine(c.a + " - " + c.b  + " = {0}", c.subt());
 
                    break;
                case 3 :
                    Console.WriteLine("请输入2数,并换行");
                    a = int.Parse(Console.ReadLine());
                    b = int.Parse(Console.ReadLine());
 
                    c = new Calclator(a, b);
                    Console.WriteLine(c.a + " x " + c.b  + " = {0}", c.mult());
 
                    break;
                case 4 :
                    Console.WriteLine("请输入2数,并换行");
                    a = int.Parse(Console.ReadLine());
                    b = int.Parse(Console.ReadLine());
 
                    c = new Calclator(a, b);
                    Console.WriteLine(c.a + " ÷ " + c.b  + " = {0}", c.divi());
 
                    break;
            }
        }
    }
 
    public class Calclator
    {
        public int a;
        public int b;
 
        public Calclator(int a, int b)
        {
            this.a = a;
            this.b = b;
        }
 
        public int result;
        public int add()
        {
            result = a + b;
            return result;
        }
        public int subt()  //subtraction
        {
            result = a - b;
            return result;
        }
        public int mult()  //multiplication
        {
            result = a * b;
            return result;
        }
        public int divi()  //division
        {
            result = a / b;
            return result;
        }
    }
}
四则运算计算器——计应191西——计应191西4组毛绍冲

 

上一篇:20201214-4 文件读与写详解2


下一篇:python 的open函数