从VB到C++转型第一步

VB语法上远宽松过C++,可读性强,学习容易.然而学习C++虽然一方面难度大,出错容易,可读性较差,但是代码效率高,具备汇编语言程序的优点,功能强悍,也可以使程序员思维更严密,处事更谨慎.下面的代码是语法上最常见的"不适应":

#include <iostream.h>
int min(int x,int y) //function min(x as integer,y as integer) as integer
{
int z;
if (x < y) //if x < y then
{z = x; //z = x
} //usually '{' and '}' are not exist in the same line.
else //else
{
z = y; //z = y
} //end if
return(z); //min = z
} //end function

int max(int x, int y) //this is a function, not a sentence
{
int z; //this is a sentence,must end with ';'
if (x>y) z=x;//also if (x > y) z = x ; space is not influenced
else z=y; //equals to else'/n'{z=y;} C++ is not so strict as C
return(z);
}

void main()
{
int a,b,m,n;
cout <<"please enter two integers:/n"; //"string" & 'chr' string is a collected of chr
cin >>a >>b;
m = max(a,b);
n = min(a,b);
cout <<"the maximum number is " <<m <<'/n';
cout <<"the minimum number is " <<n <<'/n';
}

对比下VB代码:

function min(x as integer,y as integer) as integer

dim z as integer

if x< y then 'if x < y then z = x else z = y

z = x

else

z = y

end if

end function

private sub command1_click

dim a as integer,b as integer

a = val(text1.text)

b = val(text2.text)

me.print "最小值为:" + str(min(a,b)) + "." 'VB无论字符还是字符串都是""

end sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值