首页 > 代码库 > 代码缩进

代码缩进

1.不同函数和类定义完后回车空开一行,以便观察函数

 1 class account 2 { 3      public: 4           int id; 5           double balance; 6           double annualInterestRate; 7 }; 8  9 double getMonthlyInterestRate(double x)10 {11     double y;12     y=x/12;13     return(y);14 }15 16 int withDraw(int a)17 {18     a=-a;19     return a;20 }21 22 int deposit(int b)23 {24     return b;25 }

 

2.不同操作:定义、申明、赋值、运算、函数调用。。。都应空开一行以便观察语句

 1 int main() 2 { 3     account acc; 4      5     acc.id=1122; 6     acc.balance=20000; 7     acc.annualInterestRate=0.045; 8      9     int with;10     int depo;11     double getMonthly;12     13     getMonthly=getMonthlyInterestRate(0.045);14     with=withDraw(2500);15     depo=deposit(3000);16     17     acc.balance=acc.balance+with+depo;18     cout<<"余额:"<<acc.balance<<\n;19     cout<<"月利率:"<<getMonthly<<\n;20     21     return 0;22 }

 

3.若语句太长超出屏幕,应该回车对齐以便观察

a=monday+tuesday+a+b*567-    trouble*7-90^4+your;

 

4.大括号左对齐,括号后空行并缩进4位

1 double getMonthlyInterestRate(double x)2 {3     double y;4     y=x/12;5     return(y);6 }

 

 

5.头文件名称空一位

代码缩进