Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1083158
  • 博文数量: 106
  • 博客积分: 9093
  • 博客等级: 中将
  • 技术积分: 2770
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-01 17:22
文章分类

全部博文(106)

文章存档

2014年(1)

2012年(29)

2011年(32)

2010年(20)

2008年(24)

分类: 系统运维

2012-05-18 11:13:55

你已经学会了Dsply和算术运算。下一步你要学的是变量。在编程中,变量只不过是用来指代某个东西的名字。程序员通过使用变量名可以让他们的程序读起来更像英语。而且因为 程序员的记性都不怎么地,变量名可以让他们更容易记住程序的内容。如果他们没有在写程序时使用好的变量名,在下一次读到原来写的代码时他们会大为头疼的。

如果你被这章习题难住了的话,记得我们之前教过的:找到不同点、注意细节。

  1. 在每一行的上面写一行注解,给自己解释一下这一行的作用。
  2. 倒着读你的RPGLE文件。
  3. 朗读你的RPGLE文件,将每个字符也朗读出来。

EX4

0001.00 D Cars            S             10S 0 
0002.00 D Space_in_a_car  S             10S 1 
0003.00 D Drivers         S             10S 0 
0004.00 D passengers      S             10S 0 
0005.00 D Cars_not_driven...                  
0006.00 D                 S             10S 0 
0007.00 D Carpool_capacity...                 
0008.00 D                 S             10S 1 
0009.00 D Average_passengers_per_car...       
0010.00 D                 S             10S 0 
0011.00 D Cars_driven     S             10S 0 
0012.00 D String          S             51A   
0013.00 D Wait            S              1A   
0014.00 C                   Eval      Cars = 100                                  
0015.00 C                   Eval      Space_in_a_car = 4.0                        
0016.00 C                   Eval      Drivers = 30                                
0017.00 C                   Eval      Passengers = 90                             
0018.00 C                   Eval      Cars_not_driven = Cars - Drivers            
0019.00 C                   Eval      Cars_driven = Drivers                       
0020.00 C                   Eval      Carpool_capacity = Cars_driven *            
0021.00 C                                                Space_in_a_car           
0022.00 C                   Eval      Average_passengers_per_car = Passengers /   
0023.00 C                                                          Cars_driven    
0024.00 C*                                                                        
0025.00 C                   Eval      String = 'There are ' + %char(Cars) +       
0026.00 C                                      ' cars available.'                 
0027.00 C     String        Dsply                                                 
0028.00 C                   Eval      String = 'There are only ' +                
0029.00 C                                      %char(Drivers) +                   
0030.00 C                                      ' drivers available.'              
0031.00 C     String        Dsply                                                 
0032.00 C                   Eval      String = 'There will be ' +                 
0033.00 C                                      %char(Cars_not_driven) +           
0034.00 C                                      ' empty cars today.'               
0035.00 C     String        Dsply                                                 
0036.00 C                   Eval      String = 'We can transport ' +              
0037.00 C                                      %char(Carpool_capacity) +          
0038.00 C                                      ' people today.'                   
0039.00 C     String        Dsply                                                 
0040.00 C                   Eval      String = 'We have ' +                       
0041.00 C                                      %char(Passengers) +                
0042.00 C                                      ' to carpool today.'               
0043.00 C     String        Dsply                                                 
0044.00 C                   Eval      String = 'We need to put about ' +          
0045.00 C                                      %char(Average_passengers_per_car) +
0046.00 C                                      ' in each car.'                    
0047.00 C     String        Dsply                   Wait                          
0048.00 C*                                                                        
0049.00 C                   Eval      *inlr = *on                                 
0050.00 C                   Return                                                

EX4F

0001.00 D Cars            S             10S 0                                    

0002.00 D Space_in_a_car  S             10S 1                                    

0003.00 D Drivers         S             10S 0                                    

0004.00 D passengers      S             10S 0                                     

0005.00 D Cars_not_driven...                                                     

0006.00 D                 S             10S 0                                    

0007.00 D Carpool_capacity...                                                     

0008.00 D                 S             10S 1                                    

0009.00 D Average_passengers_per_car...                                          

0010.00 D                 S             10S 0                                     

0011.00 D Cars_driven     S             10S 0                                    

0012.00 D String          S             51A                                      

0013.00 D Wait            S              1A                                       

0014.00  /free                                                                   

0015.00     Cars = 100;                                                          

0016.00     Space_in_a_car = 4.0;                                                 

0017.00     Drivers = 30;                                                        

0018.00     Passengers = 90;                                                     

0019.00     Cars_not_driven = Cars - Drivers;                                    

0020.00     Cars_driven = Drivers;                                               

0021.00     Carpool_capacity = Cars_driven * Space_in_a_car;                     

0022.00     Average_passengers_per_car = Passengers / Cars_driven;               

0023.00                                                                          

0024.00     String = 'There are ' + %char(Cars) + ' cars available.';            

0025.00     Dsply String;                                                        

0026.00     String = 'There are only ' + %char(Drivers) + ' drivers available.'; 

0027.00     Dsply String;                                                        

0028.00     String = 'There will be ' + %char(Cars_not_driven) +                 

0029.00              ' empty cars today.';                                       

0030.00     Dsply String;                                                        

0031.00     String = 'We can transport ' + %char(Carpool_capacity) +             

0032.00              ' people today.';                                           

0033.00     Dsply String;                                                        

0034.00     String = 'We have ' + %char(Passengers) + ' to carpool today.';      

0035.00     Dsply String;                                                         

0036.00     String = 'We need to put about ' +                                   

0037.00              %char(Average_passengers_per_car) +                         

0038.00              ' in each car.';                                             

0039.00     Dsply String '' Wait;                                                

0040.00                                                                          

0041.00    *inlr = *on;                                                           

0042.00    return;                                                               

0043.00                                                                          

0044.00  /end-free



当我刚开始写这个程序时我犯了个错误,RPGLE 告诉我这样的错误信息:

20 D Carpool_capacity...                    

21 D                 S             10S 0    

……

33 C                   Eval      Car_pool_capacity = Cars_driven *

34 C                                                Space_in_a_car 

*RNF7030 30      1 The name or indicator is not defined.  

*RNF7030 30     33 003300  The name or indicator CAR_POO... is not defined. 

用你自己的话解释一下这个错误信息,解释时记得使用行号,而且要说明原因。

RPGLE中变量名是不区分大小写的。

更多的加分习题:

1.      如何查看编译错误。试一试命令WRKSPLF,然后按SHIFT+F6,看看能找到什么信息

2.      在每一个变量赋值的上一行加上一行注解

3.      记住 = 的名字是等于(equal),它的作用是为东西取名

4.      记住 _ 是下划线字符(underscore)

5.      函数%char()的作用是什么,为什么使用它

阅读(1430) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~