评"软件工程项目管理:功能点分析方法与实践"

 
using  System.Collections;
using  System.Collections.Generic;
namespace  OOPM
{
    
public class Interpret
    
{
    }

    
public class Context
    
{
        
private string _Statement;
        
private int _Data;
        
public Context(string statement)
        
{
            
this._Statement = statement;
        }

        
public string Statement
        
{
            
get
            
{
                
return this._Statement;
            }

            
set
            
{
                
this._Statement = value;
            }

        }

        
public int Data
        
{
            
get
            
{
                
return this._Data;
            }

            
set
            
{
                
this._Data = value;
            }

        }

    }

    
public abstract class Expression
    
{
        
protected Dictionary<stringint> table = new Dictionary<stringint>(9);
        
public Expression()
        
{
            table.Add(
""1);
            table.Add(
""2);
            table.Add(
""3);
            table.Add(
""4);
            table.Add(
""5);
            table.Add(
""6);
            table.Add(
""7);
            table.Add(
""8);
            table.Add(
""9);
        }

        
public virtual void Interpret(Context context)
        
{
            
if(context.Statement.Length == 0)
            
{
                
return;
            }

            
foreach (string key in table.Keys)
            
{
                
int value = table[key];
                
if (context.Statement.EndsWith(key + GetPostfix()))
                
{
                    context.Data 
+= value * this.Multiplier();
                    context.Statement 
= context.Statement.Substring(0, context.Statement.Length-this.GetLength());
                }

                
if (context.Statement.EndsWith(""))
                
{
                    context.Statement 
= context.Statement.Substring(0, context.Statement.Length - 1);
                }

            }

        }

        
public abstract string GetPostfix();
        
public abstract int Multiplier();
        
public virtual int GetLength()
        
{
            
return this.GetPostfix().Length + 1;
        }

    }

    
public class WanExpression : Expression
    
{
        
public override string GetPostfix()
        
{
            
return "";
        }

        
public override int Multiplier()
        
{
            
return 10000;
        }

        
public override void Interpret(Context context)
        
{
            
if (context.Statement.Length == 0)
            
{
                
return;
            }

            ArrayList tree 
= new ArrayList();
            tree.Add(
new GeExpression());
            tree.Add(
new ShiExpression());
            tree.Add(
new BaiExpression());
            tree.Add(
new QianExpression());
            
foreach (string key in table.Keys)
            
{
               
                
if (context.Statement.EndsWith(GetPostfix()))
                
{
                    
int temp = context.Data;
                    context.Data 
= 0;
                    
                    context.Statement 
= context.Statement.Substring(0, context.Statement.Length - 1);
                    
foreach (Expression exp in tree)
                    
{
                        exp.Interpret(context);
                    }

                    context.Data 
= temp + this.Multiplier() * context.Data;
                }

            }

           
        }

    }

    
public class QianExpression : Expression
    
{
        
public override string GetPostfix()
        
{
            
return "";
        }

        
public override int Multiplier()
        
{
            
return 1000;
        }

    }

    
public class BaiExpression : Expression
    
{
        
public override string GetPostfix()
        
{
            
return "";
        }

        
public override int Multiplier()
        
{
            
return 100;
        }

    }

    
public class ShiExpression : Expression
    
{
        
public override string GetPostfix()
        
{
            
return "";
        }

        
public override int Multiplier()
        
{
            
return 10;
        }

    }

    
public class GeExpression : Expression
    
{
        
public override string GetPostfix()
        
{
            
return "";
        }

        
public override int Multiplier()
        
{
            
return 1;//10^0
        }

        
public override int GetLength()
        
{
            
return 1;
        }

    }

    
/// <summary>
    
/// 客户代码
    
/// </summary>

    public class InterpretApp
    
{
        
public static int  Main(string ChineseCharacter)
        
{
            Context context 
= new Context(ChineseCharacter);
            ArrayList tree 
= new ArrayList();
            tree.Add(
new GeExpression());
            tree.Add(
new ShiExpression());
            tree.Add(
new BaiExpression());
            tree.Add(
new QianExpression());
            tree.Add(
new WanExpression());
            
foreach (Expression exp in tree)
            
{
                exp.Interpret(context);
            }

            
return context.Data;
        }

    }

}

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值