关闭

【Basic computer】------ Calculator

840人阅读 评论(12) 收藏 举报
分类:


【Basic computer】------ Calculator



Reuse VS copy

  
【Copy】: copy is pretty to all of us, just Ctrl+c and Ctrl+v;


【Reuse】: the same thing you can use it for many time .


【comparison】:for example, you want to use a car, I already  have a car, but you do not, you want use the same car as mine, copy is that you go to build a car as my 100% but reuse is different ,you just borrow the car from me and use it .

   So which is better, while we are program which is for sure that reuse is much better, because reuse is less code but copy which means you gonna to use more workspace and program more.


    



Tight coupling  VS  loose coupling


      【Tight coupling】:which is mean each function have strongly connection to themselves and all the codes at the same winform.


      【loose coupling】:there have many winforms. Each windform has their own method and just finish the things themselves. For example: three level.


     【comparison】:for example, you have a restaurant, at the first period maybe there just you alone to running it , you to service people, you go to buy the demand goods and you cook the food for customers by yourself. All these three thing you do it by you alone this what we call it Tight coupling;

  

        But what is Loose coupling? One day you restaurant is became more popular and you hire two people, person A going to service the Customers; person B is going to input some demand goods like oil, vegetables , salt and so on. So right now you are upgrade, that is mean different people have their own business which means everyone in your restaurant have clear duty and you restaurant will make more and more efficient for sure. As the same while we are designer the software and coding the code where we learn it from the real life around us.

  

【Calculator】

       First time we code all the codes on the same class which we call it tight coupling, but we want to make it more efficient ,so we changed to loose coupling. We separate  class “Program” to two classes as “Operation” and ”Program”.

                    
    




The detail codes:

 【Operation】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Caculator
{
    class Operation
    {
        public static double GetResult(double numberA, double numberB, string operate)
        {
            double result = 0d;
            switch (operate)
            {
                case "+":
                    result = numberA + numberB;
                    break;


                case "-":
                    result = numberA - numberB;
                    break;


                case "*":
                    result = numberA * numberB;
                    break;


                case "/":
                    result = numberA / numberB;
                    break;
            }
            return result;
        }
    }
}



【program】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Caculator
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("Pleaser input NumberA: ");
                string strNumberA = Console.ReadLine();
                Console.Write("plsase input a operational sign(+、—、*、/):  ");
                string strOperate = Console.ReadLine();
                Console.Write("Pleaser input NumberB: ");
                string strNuberB = Console.ReadLine();
                string strResult = "";
                strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNuberB), strOperate));
                Console.WriteLine("The result is:" + strResult);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("You are wrong:" + ex.Message);
            }
        }
    }
}




The result show: 



 
 


 







0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

Android Calculator2源码分析与修改

将Android 4.4.4的计算器Calculator移植出来,可以独立的在Android Studio中使用。完整的代码已经推到我的GitHub,链接在文末。 下面看一下效果图: 这是在三星手...
  • zhoumushui
  • zhoumushui
  • 2015-04-14 16:13
  • 1938

【Computer Vision】计算机视觉相关课程和书籍

Table of Contents BooksCoursesPapersSoftwareDatasetsTutorials and TalksResources for studentsBlog...
  • j_d_c
  • j_d_c
  • 2017-03-16 09:22
  • 1438

【Matlab Computer Vision System ToolBox】学习笔记-1-点云配准流程 | 特征匹配

本系列博客将介绍Matlab中机器视觉工具箱的应用,更多内容见Matlab官方文档。 1. PointCloud Registration Workflow -点云配准流程 2. Bluran ...
  • kaspar1992
  • kaspar1992
  • 2017-02-02 16:48
  • 2992

LeetCode Basic Calculator(用栈计算表达式的值)

题意:给出一个计算表达式,只包含 +,-,(,),求计算结果 思路:用栈来实现  代码如下: public class Solution { private int cal(int nu...
  • wuli2496
  • wuli2496
  • 2016-07-21 20:34
  • 213

224-m-Basic Calculator

有括号的运算,只有加减运算。很明显本题只考察括号匹配没有再加入乘除,否则就真是半个计算器的工程了。由于我是先写了计算器二式,所以本题也想用一次扫描就出结果。但由于有括号要考虑出栈,要考虑单个括号括的数...
  • kakulukia
  • kakulukia
  • 2015-07-07 21:50
  • 199

第一周 leetcode 224. Basic Calculator(hard)

第一周 leetcode 224. Basic Calculator(hard)题目描述: Implement a basic calculator to evaluate a simple ex...
  • renzhff
  • renzhff
  • 2017-03-13 20:25
  • 111

Leetcode Basic Calculator 系列

Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
  • u010129448
  • u010129448
  • 2015-08-02 13:25
  • 260

leetcode_Basic Calculator

题目: Implement a basic calculator to evaluate a simple expression string. The expression stri...
  • sunp823
  • sunp823
  • 2015-06-30 23:43
  • 198

【leetcode】String——Basic Calculator II (227)

题目: Implement a basic calculator to evaluate a simple expression string. The expression string...
  • u013127687
  • u013127687
  • 2016-04-28 15:25
  • 183

LeetCode No.224 Basic Calculator

LeetCode No.224 Basic Calculator
  • woshihuangjianwei
  • woshihuangjianwei
  • 2016-11-06 22:41
  • 101
    个人资料
    • 访问:329546次
    • 积分:15427
    • 等级:
    • 排名:第833名
    • 原创:390篇
    • 转载:3篇
    • 译文:0篇
    • 评论:5761条
    个人信息
    最新评论