Eiffel 引介 Part IV (1)

Eiffel Introduction

Eiffel 引介

 

Rensselaer, 2000

James C. McKim, Jr, Rensselaer at Hartford

 K ][ N G of @ R K 译

 

4. Hello World 以及其它惯用的示例

4.1 Hello(示例)

class HELLO

creation make

feature

    make is

      -- say hello to the significant people in the world.

    do

        io.putstring( “Hello, OOPers%N” )

    end

end

 

变量 io 是一个引用,指向一个型别为 STANDARD_FILES 的对象。后面我们将看到类别 HELLO 如何访问这个变量。

 

4.2 Eiffel 系统[译注3/OOSC2e,p196]

 

l         代码文件的名称通常应该与该代码所包含之类别的名称相同,并以 .e 作为扩展名。

l         因此,类别 HELLO 的代码应该写在名为 hello.e 的文件里。

l         每个不同的系统应该处在不同的目录中。

下面给出了 hello stack 两个系统的示例。

 

4.3 STACK class

class MY_STACK[ G ]

  creation make

  feature

    capacity, depth : INTEGER

    push( x : G ) is

      -- Make x the top item.

      require

        not_full: depth < capacity

      do

        depth := depth + 1

        s.put( x, depth )

      ensure

        depth = old depth + 1

        top = x

    end -- push

    pop is

      -- Remove the top item.

      require

        not_empty: depth > 0

      do

        depth := depth - 1

      ensure

        depth = old depth - 1

        -- top = the item remaining on the stack (if any)

        -- that has been there the least amount of time.

    end -- pop

    top : G is

      -- The item that has been on the stack for the least

      -- amount of time.

      require

        not_empty: depth > 0

      do

        Result := s.item( depth )

    end -- top

  feature{NONE}

    s : ARRAY[ G ]

    make( c : INTEGER ) is

    -- Initialize an empty stack with capacity c.

      require

        c > 0

      do

        capacity := c

        !!s.make( 1, capacity )

      ensure

        capacity = c

        depth = 0

    end -- make

end -- MY_STACK

 

 

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是经纬高转ENU的Matlab代码: ``` function [x,y,z] = llh2enu(lat,lon,h,lat0,lon0,h0) % LLH2ENU Converts geodetic coordinates to local East, North, Up (ENU) % coordinates. % [x,y,z] = LLH2ENU(lat,lon,h,lat0,lon0,h0) converts geodetic coordinates % (latitude, longitude, and height) to local ENU coordinates (East, North, % Up) given a local reference point (lat0, lon0, h0). All inputs are in % degrees and meters. % % Reference: "A Guide to Coordinate Systems in Great Britain" by % Peter Osborne, 2011. % % Example: % % Convert coordinates of the Eiffel Tower to ENU coordinates % lat = 48.858093; % N % lon = 2.294694; % E % h = 37; % meters % lat0 = 48.858093; % N % lon0 = 2.294694; % E % h0 = 0; % meters % [x,y,z] = llh2enu(lat,lon,h,lat0,lon0,h0); % fprintf('East: %.2f meters\n', x); % fprintf('North: %.2f meters\n', y); % fprintf('Up: %.2f meters\n', z); % % See also ECEF2LLH, ECEF2ENU, ENU2ECEF, ENU2LLH. % WGS84 ellipsoid constants a = 6378137; % semi-major axis (meters) b = 6356752.314245; % semi-minor axis (meters) e = sqrt(1 - (b/a)^2); % eccentricity % Convert to radians lat = deg2rad(lat); lon = deg2rad(lon); lat0 = deg2rad(lat0); lon0 = deg2rad(lon0); % Radius of curvature in the prime vertical N = a / sqrt(1 - e^2 * sin(lat0)^2); % Cartesian coordinates of local reference point x0 = (N + h0) * cos(lat0) * cos(lon0); y0 = (N + h0) * cos(lat0) * sin(lon0); z0 = ((1 - e^2) * N + h0) * sin(lat0); % Cartesian coordinates of point to convert x = (N + h) * cos(lat) * cos(lon); y = (N + h) * cos(lat) * sin(lon); z = ((1 - e^2) * N + h) * sin(lat); % Rotation matrix from ECEF to ENU R = [-sin(lon0) cos(lon0) 0 ; ... -sin(lat0)*cos(lon0) -sin(lat0)*sin(lon0) cos(lat0); ... cos(lat0)*cos(lon0) cos(lat0)*sin(lon0) sin(lat0)]; % Translation vector from ECEF to ENU T = [x0; y0; z0]; % Convert to ENU coordinates P = R * ([x; y; z] - T); x = P(1); y = P(2); z = P(3); end ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kingofark

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值