如果某一常量与其它常量密切相关,应在定义中包含这种关系,而不应给出一些孤立的值

如果某一常量与其它常量密切相关,应在定义中包含这种关系,而不应给出一些孤立的值。

例如: const float RADIUS = 100; const float DIAMETER = RADIUS * 2;

 

 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 
 6 //测试字符串(string)对象
 7 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 8 
 9 int main(int argc, char** argv) {
10         //创建string对象,并显示
11     string s1;
12     string s2="ABCDEFGHIJK";
13     string s3=s2;
14     string s4(20,'A');
15     string s5(s2,3,3);
16     cout<<"s1="<<s1<<endl;
17     cout<<"s2="<<s2<<endl;
18     cout<<"s3="<<s3<<endl;
19     cout<<"s4="<<s4<<endl;
20     cout<<"s5="<<s5<<endl;
21 
22     //为string对象输入数据,并显示
23     cout<<"s1=";
24     cin>>s1;
25     cout<<"s2=";
26     cin>>s2;
27     cout<<"s3=";
28     cin>>s3;
29     cout<<"s4=";
30     cin>>s4;
31     cout<<"s5=";
32     cin>>s5;
33 
34     cout<<"s1="<<s1<<endl;
35     cout<<"s2="<<s2<<endl;
36     cout<<"s3="<<s3<<endl;
37     cout<<"s4="<<s4<<endl;
38     cout<<"s5="<<s5<<endl;
39     
40     return 0;
41 }

 

posted @ 2018-08-03 12:54  borter  阅读(126)  评论(0编辑  收藏  举报